Cetak PDF melalui Java

PDF belgelerini yazdırın. PDF dosyalarını programlı olarak değiştirmek için Java için Aspose.PDF’yi kullanın

Cara Mencetak PDF Menggunakan Java Library

Untuk mencetak PDF, kita akan menggunakan Aspose.PDF for Java API yang merupakan API konversi yang kaya fitur, kuat dan mudah digunakan untuk platform Java. Anda dapat mengunduh versi terbarunya langsung dari [Maven](https://repository.aspose.com/webapp/ #/artifacts/browse/tree/general/repo/com/aspose/aspose-pdf) dan menginstalnya dalam proyek berbasis Maven Anda dengan menambahkan konfigurasi berikut ke pom.xml.

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java AP</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

Dependency

<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>

Mencetak dokumen PDF melalui Java


Anda memerlukan Aspose.PDF for Java untuk mencoba kode di lingkungan Anda.

  1. Muat PDF dengan instance Document.
  2. Dapatkan DocumentInfo menggunakan properti Document.Info.
  3. Akses & menampilkan properti Document.Info yang berbeda.

Cetak PDF - Java

Kode sampel ini menunjukkan cara mencetak File PDF


    // Create PdfViewer object
    PdfViewer viewer = new PdfViewer();

    // Open input PDF file
    viewer.BindPdf(System.IO.Path.Combine(_dataDir, "input.pdf"));

    // 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

    // 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();
    System.Drawing.Printing.PrintDocument prtdoc = new System.Drawing.Printing.PrintDocument();

    // Set printer name
    ps.PrinterName = prtdoc.PrinterSettings.PrinterName;

    // Set PageSize (if required)
    pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);

    // Set PageMargins (if required)
    pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

    // Print document using printer and page settings
    viewer.PrintDocumentWithSettings(pgs, ps);

    // Close the PDF file after priting
    viewer.Close();