Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Sun Apr 05, 2020 4:26 pm

PdfDocument pdfdoc;
PrintPreviewDialog ppd;

// after loading PDF file into pdfdoc, then...
ppd=new PrintPreviewDialog();
ppd.Document=pdfdoc.PrintDocument;
ppd.ShowDialog();

But, VS2015 said that the pdfdoc.PrintDocument is deprecated!!

So, for the above simple scenario (for use with PrintPreviewDialog), what is the suggested way to replace the deprecated PrintDocument?
Can you show me the equivalent code?

grchen168
 
Posts: 32
Joined: Sat Jan 24, 2015 4:48 pm

Mon Apr 06, 2020 4:42 am

Hi, amy.zhao,
it will be appreciated if you can provide me for replacement of the deprecated PrintDocument
(note, only for use of WinForm namespace's PrintPreviewDialog).
Thanks in advance.

grchen168
 
Posts: 32
Joined: Sat Jan 24, 2015 4:48 pm

Mon Apr 06, 2020 4:58 am

Hi,

Thanks for your post.
Our previous printing api used System.Drawing.Printing.PrintDocument class. Now we have created a better printing performance class, named Spire.Pdf.Print.PdfPrintSettings, the original printing way will be removed in the future, so pdfdoc.PrintDocument has been marked as it will be deprecated, we only maintain the new printing way now, sorry there is no equivalent code can be used for PrintPreviewDialog control. But PrintPreviewControl control is available in the new printing. Here is sample code for reference.
Code: Select all
 
           PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(input);
         
            this.printPreviewControl1.Rows = 1;
            this.printPreviewControl1.Columns = 1;
            doc.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.FitSize, true);

            doc.Preview(this.printPreviewControl1);


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Apr 06, 2020 7:01 am

Hi, Amy,
Thanks for the reply.
Based on what you suggested, I am now considering using Spire's pdfViewer control.

But, now, I have a new question using about pdfViewer control:
again, I already have a pdfdocument object (that is already instantiated using LoadFromFile());
how to be efficiently setting pdfViewer1's pdf content??
(that is, without firstly saving the original pdfdocument into physical file, and then, load from the aforementioned file, again, using pdfViewer.LoadFromFile())

Are there any efficient way to initialize pdfViewer's PDF content using already existed PDFDocument object?

grchen168
 
Posts: 32
Joined: Sat Jan 24, 2015 4:48 pm

Mon Apr 06, 2020 8:03 am

Hi,

Sorry that there is no method to initialize pdfViewer's PDF content using already existed PDFDocument object. But you could save pdf document to a stream, then use pdfViewer control's LoadFromStream method to read it.
Code: Select all
pdfDocument.SaveToStream(pdfStream);
this.pdfViewer1.LoadFromStream(pdfStream);


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Apr 06, 2020 8:50 am

Got it.
I currently using the following:
pdfViewer1.LoadFromStream(pdfdoc.SaveToStream(FileFormat.PDF)[0]);
Is that correct?

grchen168
 
Posts: 32
Joined: Sat Jan 24, 2015 4:48 pm

Mon Apr 06, 2020 8:52 am

For the following:
pdfViewer1.LoadFromStream(pdfdoc.SaveToStream(FileFormat.PDF)[0]);

What else steps should I take in order to avoid memory leak??

grchen168
 
Posts: 32
Joined: Sat Jan 24, 2015 4:48 pm

Mon Apr 06, 2020 8:58 am

That's not correct.
Please try the below code.
Code: Select all
 MemoryStream pdfStream = new MemoryStream();
pdfDocument.SaveToStream(pdfStream);
this.pdfViewer1.LoadFromStream(pdfStream);


Sincerely
Amy,
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Apr 06, 2020 9:16 am

Thanks.

BTW, when I drop a PDFViewer control onto my Winform,
then, build my project using VS2015, VS2015 complain the following:
1>PdfPrintPreviewForm.Designer.cs(38,7,38,42): warning CS0618: 'PdfViewer.MultiPagesThreshold' is obsolete: 'This method may be removed in the future.No effect,only avoid compile error.'
1>PdfPrintPreviewForm.Designer.cs(44,7,44,32): warning CS0618: 'PdfViewer.Threshold' is obsolete: 'This method may be removed in the future.No effect,only avoid compile error.'

But, those 2 properties (MultiPagesThreshold & Threshold) are automatically added by VS designer or the PDFViewer control!!
Should I manually remove those 2 lines from the generated Designer.cs file??

What negative impact will it cause if I manually remove them?
Or what suggested properties should I manually configure, instead of those 2 obsolete properties?

grchen168
 
Posts: 32
Joined: Sat Jan 24, 2015 4:48 pm

Mon Apr 06, 2020 10:15 am

Hi,

Just manually remove those 2 properties (MultiPagesThreshold & Threshold). There is no negative impact.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Apr 06, 2020 11:57 am

Got it.
Thanks.

grchen168
 
Posts: 32
Joined: Sat Jan 24, 2015 4:48 pm

Tue Apr 07, 2020 1:17 am

Hi,

My pleasure.
If you need further assistance, welcome to contact us again.
Wish you all the best!

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF