Last active
August 7, 2024 15:27
Print PDF to PDF with C#. For further details: https://kb.aspose.com/pdf/net/print-pdf-to-pdf-with-csharp/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Pdf; | |
using Aspose.Pdf.Facades; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
new License().SetLicense("License.lic"); | |
// Instantiate the PdfViewer object | |
PdfViewer pdfViewer = new PdfViewer(); | |
// Load the input PDF file | |
pdfViewer.BindPdf("sample.pdf"); | |
// Set printing attributes | |
pdfViewer.AutoResize = true; | |
pdfViewer.AutoRotate = true; | |
pdfViewer.PrintPageDialog = false; | |
pdfViewer.PrintAsImage = false; | |
// Create objects for PrinterSettings and Page settings | |
Aspose.Pdf.Printing.PrinterSettings ps = new Aspose.Pdf.Printing.PrinterSettings(); | |
Aspose.Pdf.Printing.PageSettings pgs = new Aspose.Pdf.Printing.PageSettings(); | |
// Set printer name, paper size and margins | |
ps.PrinterName = "Adobe PDF"; | |
pgs.PaperSize = new Aspose.Pdf.Printing.PaperSize("A4", 827, 1169); | |
pgs.Margins = new Aspose.Pdf.Devices.Margins(5, 5, 5, 5); | |
// Print the document | |
pdfViewer.PrintDocumentWithSettings(pgs, ps); | |
// Close the PDF file | |
pdfViewer.Close(); | |
// Save the document | |
System.Console.WriteLine("PDF printed successfully"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment