We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Printing Single PDF with Multiple Page Sizes

I have a single PDF file which contains pages of varying sizes (legal and letter).



Can the Aspose.PDF component handle printing this document correctly?



The behavior I’m seeing is that it does not give the opportunity to select the paper size on a per page basis. How can I work around this, or am I missing a feature in the toolset?

Hello? Can anyone from support address my question?

We are currently on a trial license. If this issue exists with the component and isn’t slated to be fixed soon, we may have to chose another component.

Hi John,


Thanks for contacting support.

In case you are trying to print the PDF file with variant page sizes, you may consider using Pdfviewer.AutoResize = true; property. Also please note that PaperSize property in System.Drawing.Printing.PageSettings class provides the feature to specify the paper size of page. In case you need to individually set the page size, you may consider splitting the large PDF file to single page PDF documents and then dynamically set the page size for each file.

<o:p></o:p>

For further details, please visit


In case you encounter any issue, please share the resource file so that we can test the scenario at our end.

Thanks for the reply.

The autoresize feature will cause legal pages to shrink to fit letter paper. This is not acceptable for our business users. These are documents used in legal matters. They must print according to strict margin and sizing standards.

Usually, the end user is printing a batch of documents for the purpose of a real estate sale. The documents come in both letter and legal sizes.

We merge the documents together into a single PDF for multiple purposes. One of those reasons is to keep all the printed pages together at the printer.

Splitting the document up will create a scenario where other print jobs could get printed in between the user’s print request. That would create confusion.

We have used Amyuni components in the past, but they have proven to be extremely unreliable.

Our testing to date shows that the Aspose.Pdf component is a great toolset. This is the only issue we are facing.

Looking at the forums, this appears to be a known issue. Do you have any plans to address this?

Additionally, if I were to follow your suggestion of breaking up the large pdf into smaller ones, then it would create an undesirable effect when the target printer is the XPS print driver.

The user would be prompted multiple times for the filename to save into. This would create multiple files, when the true intent was to print the single print job into a single XPS file.

Additionally, I can tell by looking at your code via Reflector that you are not handling the PrintDocument::QueryPageSettings event.

This .NET framework event is designed to allow exactly this scenario. If you could provide an overload of the PdfViewer::PrintDocumentWithSettings() method that allowed me to pass in the handler to use, then my code could control the page settings on a per-page basis, resolving my issue.

Here is a sample of the document I am trying to print.





Please note:





The first page is letter sized. The second page is legal sized.





When printed, it SHOULD print the document as a single print job, switching the paper size accordingly while printing. When I go to my printer, I want to see two sheets of paper, one letter and one legal.





This appears to not be supported in the Aspose.Pdf component. This is the only issue we have encountered during the trial of this toolset. However, this is a “show stopper” for us. It is enough of an issue that our business will not accept the behavior and will force us to look at other products.





To be honest, I’d rather not use another product. The Aspose.Pdf component is impressive in all other cases.





I want to know if it’s possible for your development team to look into my previously suggestion and see if it’s feasible.





Thanks!

john.morris-1:
Additionally, if I were to follow your suggestion of breaking up the large pdf into smaller ones, then it would create an undesirable effect when the target printer is the XPS print driver.

The user would be prompted multiple times for the filename to save into.

Hi John,

In order to suppress the dialog to enter resultant file name, please follow the steps specified over Printing PDF to an XPS File and hiding print dialog.

Hi John,


Thanks for sharing the details.

I have tried to figure out a solution where first I tried traversing each page of document, get page dimensions, and try printing each page with respective dimensions but I am afraid the output is not correct. Given below is the code which I have used to test this scenario.

However, as per your actual requirement of Printing PDF with Multiple Page Sizes, I have logged an investigation ticket as PDFNEWNET-36955 in our issue tracking system. We will further look into the details of this requirement and will keep you posted on the status of implementation. Please be patient and spare us little time. We are sorry for your inconvenience.

[C#]

Document doc = new Document(“c:/pdftest/Documents.pdf”);<o:p></o:p>

for(int counter = 1; counter <= doc.Pages.Count; counter++)

{

Console.WriteLine("Page Height = " +doc.Pages[counter].CropBox.Height);

Console.WriteLine("Page Width = " + doc.Pages[counter].CropBox.Width);

Document tempdoc = new Document();

tempdoc.Pages.Add(doc.Pages[counter]);

//Create PdfViewer object and bind PDF file

PdfViewer pdfViewer = new PdfViewer();

pdfViewer.BindPdf(tempdoc);

//Set PrinterSettings and PageSettings

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

printerSetttings.Copies = 1;

printerSetttings.PrinterName = "Microsoft XPS Document Writer";

//Set output file name and PrintToFile attribute

printerSetttings.PrintFileName = "C:\\pdftest\\Documents_printoutput"+counter+".xps";

printerSetttings.PrintToFile = true;

//Disable print page dialog

pdfViewer.PrintPageDialog = false;

//Create objects for printer and page settings and PrintDocument

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

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

//Set XPS/PDF printer name

ps.PrinterName = "Microsoft XPS Document Writer";

//or set the PDF printer

//ps.PrinterName = "Adobe PDF";

//switch (doc.Pages[counter].CropBox.Height)

if(doc.Pages[counter].CropBox.Height < 900)

{ // case 595:

//Set PageSize (if required)

pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", (int)doc.Pages[counter].CropBox.Width,(int)doc.Pages[counter].CropBox.Height);

}else if(doc.Pages[counter].CropBox.Height > 1000)

{

//Set PageSize (if required)

pgs.PaperSize = new System.Drawing.Printing.PaperSize("A2", (int)doc.Pages[counter].CropBox.Width, (int)doc.Pages[counter].CropBox.Height);

}

//Set PageMargins (if required)

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

//Pass printer settings object to the method

pdfViewer.PrintDocumentWithSettings(printerSetttings);

pdfViewer.Close();

}