Spire.PDFViewer is a powerful PDF Viewer component for .NET. It allows developers to load PDF document from stream, file and byte array.

Tue Aug 25, 2020 3:51 pm

Hello. I cannot figure out how to display a pdf document in the Preview, as it will be printed.
If I use
Code: Select all
_document.PrintSettings.Landscape = true;
_document.PrintSettings.SelectPageRange(1, 2);
_document.PrintSettings.SelectMultiPageLayout((int)1, (int)2);
Stream [] streamPdf = _document.SaveToStream (FileFormat.PDF);
pdfDocumentViewer1.LoadFromStream (streamPdf [0]);
pdfDocumentViewer1.PrintSettings.Copies = document.PrintSettings.Copies;
pdfDocumentViewer1.PrintSettings.Landscape = document.PrintSettings.Landscape;
pdfDocumentViewer1.PrintSettings.SelectPageRange(
                _document.PrintSettings.PrintFromPage,
                _document.PrintSettings.PrintToPage);

pdfDocumentViewer1 shows me a document without print settings.
I am interested in settings such as Landscape, SelectMultiPageLayout, PageFrom and PageTo.
And also why PdfViewer and PdfDocumentViewer do not accept PdfDocument objects. Only File or stream.
Thank.

stron333
 
Posts: 7
Joined: Tue Aug 25, 2020 8:51 am

Wed Aug 26, 2020 6:29 am

Hi,

Thanks for your inquiry.
As per my understanding, you want to show the PDF with the print settings in PdfDocumentViewer. Sorry that Our Spire.PDFViewer does not support that. If you would like to make changes, please change the PDF file firstly then pass the changed PDF in the PDF Viewer.
In addition, PdfViewer and PdfDocumentViewer belong to Spire.PDFViewer while PdfDocument belongs to Spire.PDF. They are different products, so the internal structure is different. If you want to pass the PdfDocument into the PdfDocumentViewer, you need to convert the PdfDocument object into a stream or file then load in PdfDocumentViewer like you do. If I misunderstand your meaning or there is other question, welcome to get it back to us.

Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Wed Aug 26, 2020 7:07 am

Yes, you understood me correctly.
please change the PDF file firstly then pass the changed PDF in the PDF Viewer

How do I save changes to a PDF file considering PrintSettings. PdfDocument does not have a PrintToFile method.
And the SaveToFile or SaveToSream methods ignore PrintSettings.
I showed this method above.

stron333
 
Posts: 7
Joined: Tue Aug 25, 2020 8:51 am

Wed Aug 26, 2020 8:41 am

Hi,

Thanks for your feedback.
The following code can print to file. Note the printer need to support printing to PDF if you want to print to a pdf file.
Code: Select all
pdf.PrintSettings.PrintToFile("output.Pdf");


Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Wed Aug 26, 2020 9:06 am

To show a preview to the user, I need to print the PdfDocument with a third party printer that can print to Pdf, and then display this file in the PDFViewer, and then the user clicks on the print button himself? I think it's a crutch.
It would be really great if PDFViewer can display PdfDocument along with PrintSettings.

At the moment I am using the standard printPreviewControl
Code: Select all
pDFdocument.Preview (printPreviewControl1);

But it takes a very long time to load and there is no scrolling in it. And I need to implement via printPreviewControl1.Rows and printPreviewControl1.Columns.

On the other hand, PDFViewer has its own PrintSettings. But they also do not affect the display.

stron333
 
Posts: 7
Joined: Tue Aug 25, 2020 8:51 am

Wed Aug 26, 2020 10:48 am

Hi,

Thanks for your feedback.
You can add a print dialog to your Windows Forms application for printing Settings. Below is the code for your reference. If there's any problem, please feel free to write it back.
Code: Select all
private void btnPrint_Click(object sender, EventArgs e)
        {
            if (this.pdfDocumentViewer1.PageCount > 0)
            {
                PrintDialog dialogPrint = new PrintDialog();
                dialogPrint.AllowPrintToFile = true;
                dialogPrint.AllowSomePages = true;
                dialogPrint.PrinterSettings.MinimumPage = 1;
                dialogPrint.PrinterSettings.MaximumPage = this.pdfDocumentViewer1.PageCount;
                dialogPrint.PrinterSettings.FromPage = 1;
                dialogPrint.PrinterSettings.ToPage = this.pdfDocumentViewer1.PageCount;
                if (dialogPrint.ShowDialog() == DialogResult.OK)
                {
                    this.pdfDocumentViewer1.PrintSettings.SelectPageRange(dialogPrint.PrinterSettings.FromPage, dialogPrint.PrinterSettings.ToPage);
                    this.pdfDocumentViewer1.PrintSettings.PrinterName = dialogPrint.PrinterSettings.PrinterName;
                    this.pdfDocumentViewer1.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.FitSize, false);
                    this.pdfDocumentViewer1.PrintSettings.Landscape = dialogPrint.PrinterSettings.DefaultPageSettings.Landscape;
                    this.pdfDocumentViewer1.PrintDoc();
                }
            }
        }


Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Wed Aug 26, 2020 11:30 am

I have no problems with printing and setting print options. I have a problem with Preview

stron333
 
Posts: 7
Joined: Tue Aug 25, 2020 8:51 am

Thu Aug 27, 2020 2:42 am

Hi,

Thanks for your feedback.
As I said before, our Spire.PDFViewer does not support showing the PDF with print settings. I am sorry that the workaround of using the code PrintToFile cannot help you. If there is any other question, welcome to get it back to us.

Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Thu Aug 27, 2020 7:06 am

I understand, thank you very much for the consultation

stron333
 
Posts: 7
Joined: Tue Aug 25, 2020 8:51 am

Thu Aug 27, 2020 7:27 am

Hi,

Thanks for your reply.
If you encounter any issues related to our products in the future, just feel free to contact us. Wish you all the best!

Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Return to Spire.PDFViewer