Hi, i’m develope into my software the print of pdf file but when use PdfViewer for printing, the print have a large margin.
I use this code:
Aspose.Pdf.Facades.PdfViewer viewer = new Aspose.Pdf.Facades.PdfViewer();
//Open input PDF file
viewer.BindPdf(documentFilePath);
//Set attributes for printing
viewer.AutoResize = true; //Print the file with adjusted size
viewer.AutoRotate = true; //Print the file with adjusted rotation
viewer.PrintPageDialog = false; //Do not produce the page number dialog when printing
//Print document using printer and page settings
viewer.PrintDocumentWithSettings(printerSettings.ToAsposePrinterSettings());
//Close the PDF file after priting
viewer.Close();
printerSettings contain a default configuration of System.Windows.Forms.PrintDialog setting selected from user.
I’m use version 24.9.0 of Aspose.PDF
@Datagest
It seems you are experiencing issues with large margins when printing PDF files using the Aspose.PDF library. To address this, you can adjust the page format settings before printing. Here’s a general approach you can take:
-
Set Up the Printer Job: You can create a PrinterJob
object and retrieve the default page format. This allows you to customize the page settings, including margins.
-
Adjust Page Format: Modify the PageFormat
to set the desired margins. You can use the setMargins
method to specify the top, bottom, left, and right margins.
-
Print the Document: After adjusting the page format, you can proceed to print the document.
Here’s an example of how you might implement this:
import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;
import com.aspose.pdf.facades.PdfViewer;
public class PrintPDFWithCustomMargins {
public static void main(String[] args) {
// Create PdfViewer object
PdfViewer viewer = new PdfViewer();
// Open input PDF file
viewer.bindPdf("documentFilePath.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 a PrinterJob object
PrinterJob printJob = PrinterJob.getPrinterJob();
PageFormat pageFormat = printJob.defaultPage();
// Set custom margins (example: 10 units for each margin)
pageFormat.setMargins(10, 10, 10, 10); // top, left, bottom, right
// Print document using the modified page format
viewer.printDocumentWithSettings(printJob);
// Close the PDF file after printing
viewer.close();
}
}
Make sure to replace "documentFilePath.pdf"
with the actual path to your PDF file. Adjust the margin values as needed to fit your requirements.
If you continue to experience issues with margins, consider checking the printer settings or the specific printer driver, as they can also affect the output.
Feel free to reach out if you have further questions or need additional assistance!
I have make it but not work.
The old version the i have used as far as here worked correctly.
The old versione was 11.7.0
@Datagest
Would you kindly share the sample PDF file for our reference along with the sample output using Microsoft Print to PDF (Virtual Printer) for our reference so that we can test the scenario in our environment and address it accordingly.