Free Support Forum - aspose.com

Last page of PDF will not print

Hi, I am evaluating ASPOSE to use for printing existing PDF files using asp.net. I can print the file just fine with the exception of the last page. The last page of each file will not print. Aspose.Pdf.Facades.PdfViewer.Pagecount reports the correct number of pages.

Please see the code below:
{
string fname = @"\is-apps02\RPM\Working\Admin\g_payroll.pdf";
Aspose.Pdf.Facades.PdfViewer pdfv = new Aspose.Pdf.Facades.PdfViewer();

    System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
    System.Drawing.Printing.PrinterSettings prin = new System.Drawing.Printing.PrinterSettings();
   
    pdfv.BindPdf(fname);
    int pgcnt = 0;
    pgcnt = pdfv.PageCount;
    txt2.Text = pgcnt.ToString();

    prin.PrintRange = System.Drawing.Printing.PrintRange.AllPages;
    prin.PrinterName = cmbxPrinterNames.SelectedValue.ToString();
    prin.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("letter", 827, 1169);
    
    pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
    pgs.PaperSize = prin.DefaultPageSettings.PaperSize;
  
    pdfv.PrintDocumentWithSettings(pgs, prin);
    pdfv.Close();

}

Any suggestions?

Hi Mark,


Can you please share the sample PDF files causing this issue, so that we can test the scenario at our end. We are sorry for this inconvenience.

Be glad to. I have tried a couple of files and got similar results. The file I am attaching is a 7 page document. It would only print the first 4 pages.



On the statement,



prin.DefaultPageSettings.PaperSize = New System.Drawing.Printing.PaperSize(“letter”, 850, 1150)

I assume the last 2 values are page width and height signifying 8.5: and 11.5 inches" ?

Hi,


Thanks for sharing the resource file.

As per my observations, the shared PDF file has 6 pages and when trying to print PDF file to MS XPS Document Writer, the resultant file contains 6 pages. For your reference, I have also attached the resultant file generated over my end.

[C#]

string fname = @“c:/pdftest/g_test.pdf”; <o:p></o:p>

Aspose.Pdf.Facades.PdfViewer pdfv = new Aspose.Pdf.Facades.PdfViewer();

System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();

System.Drawing.Printing.PrinterSettings prin = new System.Drawing.Printing.PrinterSettings();

pdfv.BindPdf(fname);

Console.WriteLine(pdfv.PageCount);

int pgcnt = 0;

pgcnt = pdfv.PageCount;

prin.PrintRange = System.Drawing.Printing.PrintRange.AllPages;

prin.PrinterName = "Microsoft XPS Document Writer";

prin.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("letter", 827, 1169);

pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

pgs.PaperSize = prin.DefaultPageSettings.PaperSize;

pdfv.PrintDocumentWithSettings(pgs, prin);

pdfv.Close();