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

Free Support Forum - aspose.com

Java PDF Printing Ledger

Hello,

I am trying to print a PDF via Aspose.PDF as the Ledger Paper Size.

My code for setting Paper Size so far is:

PdfPrinterSettings printerSettings = new PdfPrinterSettings();

for(PrintPaperSize printPaperSize : printerSettings.getPaperSizes()){
if(printPaperSize.getPaperName().equals(printAttributes.getPrintAttributesPaperSize())){
printerSettings.getDefaultPageSettings().setPaperSize(printPaperSize);
break;
}
}

PdfViewer viewer = new PdfViewer();
viewer.bindPdf(document);
viewer.setAutoResize(true);
viewer.setAutoRotate(true);

viewer.printDocumentWithSettings(printerSettings);

Looking in the paper sizes list, Ledger is not there. Is there some other way to set the paper size on pdf prints?

Also printing via Aspose.Words is proving troublesome with specifying paper sizes. How should this be done as well?

@matthewanselmo

Thank you for contacting support.

We have modified your code snippet a little and have removed the loop and if condition because printAttributes was not defined in shared code snippet. You can set width and height of Ledger size using com.aspose.pdf.PageSize.getPageLedger() property as in the code snippet below:

PdfPrinterSettings printerSettings = new PdfPrinterSettings();
com.aspose.pdf.printing.PrintPaperSize printPaperSize = new com.aspose.pdf.printing.PrintPaperSize();
printPaperSize.setHeight((int) com.aspose.pdf.PageSize.getPageLedger().getHeight());
printPaperSize.setWidth((int) com.aspose.pdf.PageSize.getPageLedger().getWidth());
printerSettings.getDefaultPageSettings().setPaperSize(printPaperSize);

PdfViewer viewer = new PdfViewer();
viewer.bindPdf(document);
viewer.setAutoResize(true);
viewer.setAutoRotate(true);
viewer.printDocumentWithSettings(printerSettings);

About the problem with Aspose.Words for Java API, please create a separate topic in Aspose.Words forum while mentioning all the details along with respective files and we will assist you accordingly.

Manually setting the height and width as you showed above doesn’t seem to work.
I am printing to file with

printerSettings.setPrintToFile(true);

Printing the document with:

viewer.printDocumentWithSettings(printerSettings);

Doesnt do anything.

@matthewanselmo

We have updated the code snippet, as under, but page size in generated PDF document is not set to ledger. Therefore, a ticket with ID PDFJAVA-38098 has been logged in our issue management system for further investigations. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

// Create PdfViewer object
PdfViewer viewer = new PdfViewer();
// Open input PDF file
viewer.bindPdf(dataDir + "test(1).pdf");
// Set attributes for printing
viewer.setAutoResize(true); // Print the file with adjusted size
viewer.setAutoRotate(true); // Print the file with adjusted rotation
viewer.setPrintPageDialog(false); // Do not produce the page number dialog when printing

// Create objects for printer and page settings and PrintDocument
PrintPageSettings pgs = new PrintPageSettings();
PdfPrinterSettings printerSettings = new PdfPrinterSettings();
// Set printer name
printerSettings.setPrinterName("Microsoft Print to PDF");
com.aspose.pdf.printing.PrintPaperSize printPaperSize = new com.aspose.pdf.printing.PrintPaperSize();
//printPaperSize.setHeight((int) com.aspose.pdf.PageSize.getPageLedger().getHeight());
//printPaperSize.setWidth((int) com.aspose.pdf.PageSize.getPageLedger().getWidth());

printPaperSize.setHeight(792); //Basic unit in Aspose.PDF is, Point
printPaperSize.setWidth(1224); //where 72 points = 1 inch

// Set PageSize (if required)
pgs.setPaperSize(printPaperSize);

// Print document using printer and page settings
viewer.printDocumentWithSettings(pgs, printerSettings);

We are sorry for the inconvenience.