Κάντε το PDF χρησιμοποιώντας τη βιβλιοθήκη Java

Η ισχυρή βιβλιοθήκη μας Java επιτρέπει στους προγραμματιστές να δημιουργήσουν μέσω προγραμματισμού το PDF σε λίγα μόλις βήματα

Οι προγραμματιστές του Java μπορούν εύκολα να δημιουργήσουν PDF χρησιμοποιώντας μόνο το ισχυρό API προϊόντων μας. Σημαίνει ότι η λύση μας θα παρέχει στους προγραμματιστές όλα όσα χρειάζονται για να δημιουργήσουν το PDF στο Java.

Προβολή αποσπάσματος κώδικα

Δημιουργήστε το PDF σε Java μέσω προγραμματισμού

Με τη βιβλιοθήκη Java, οι προγραμματιστές μπορούν εύκολα να δημιουργήσουν το PDF από την αρχή. Για να γίνει αυτό, οι προγραμματιστές Java πρέπει να εκτελέσουν μερικά μόνο βήματα:

  1. Προσθήκη ονόματος αρχείου
  2. Ξεκινήστε τη δημιουργία ενός PDF εγγράφου χρησιμοποιώντας Java
  3. Αποθηκεύστε το αρχείο εξόδου του PDF

Αξίζει να σημειωθεί ότι ένα κενό έγγραφο τεχνικά υποτίθεται ότι περιέχει μία παράγραφο, επομένως όταν δημιουργείτε μέσω προγραμματισμού ένα PDF έγγραφο, θα έχετε ακριβώς αυτή τη βασική δομή εγγράφου.

Σημειώστε ότι μπορείτε να προσθέσετε άμεσα περιεχόμενο σε ένα PDF αρχείο που δημιουργήθηκε πρόσφατα. Έτσι, δεν θα λάβετε απλώς ένα κενό έγγραφο, αλλά ένα έγγραφο που περιέχει το απαραίτητο περιεχόμενο. Για περισσότερες πληροφορίες σχετικά με τον τρόπο επεξεργασίας ενός εγγράφου, ανατρέξτε στη σελίδα Επεξεργασία.

Δημιουργία PDF σε Java

Αυτή η βιβλιοθήκη Java σάς επιτρέπει να δημιουργείτε μέσω προγραμματισμού PDF έγγραφα. Δοκιμάστε την ισχυρή μας λειτουργικότητα και δείτε πώς μπορείτε να δημιουργήσετε PDF σε ορισμένες μορφές χρησιμοποιώντας το ακόλουθο παράδειγμα:

Δημιουργήστε ένα νέο PDF χρησιμοποιώντας το Java
Επιλέξτε τη μορφή προορισμού από τη λίστα
Εκτέλεση κώδικα
import com.aspose.words.*;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Font font = builder.getFont();
font.setName("Courier New");
font.setColor(Color.BLUE);
font.setSize(36);
font.setHighlightColor(Color.YELLOW);

builder.write("Morbi enim nunc faucibus a.");

doc.save("Output.pdf");
import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Εάν NextSibling είναι μηδενικό, τότε πιθανότατα αυτό είναι το τελευταίο Run στην Παράγραφο. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.pdf"); import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Εάν NextSibling είναι μηδενικό, τότε πιθανότατα αυτό είναι το τελευταίο Run στην Παράγραφο. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1); doc.save("Output.pdf", saveOptions);
import com.aspose.words.*;

Document doc = new Document();

Run run = new Run(doc, "Proin eros metus, sagittis sed.");
Paragraph para = doc.getFirstSection().getBody().getFirstParagraph();
para.appendChild(run);

Comment comment = new Comment(doc);
comment.setAuthor("John Doe");
comment.setInitial("JD");
comment.setDateTime(new Date());
comment.setText("Quisque fringilla leo.");

CommentRangeStart commentRangeStart = new CommentRangeStart(doc, comment.getId());
CommentRangeEnd commentRangeEnd = new CommentRangeEnd(doc, comment.getId());

run.getParentNode().insertBefore(commentRangeStart, run);
run.getParentNode().insertAfter(commentRangeEnd, run);
commentRangeEnd.getParentNode().insertAfter(comment, commentRangeEnd);

comment.addReply("Jane Doe", "JD", new Date(), "Pellentesque vel sapien justo.");

doc.save("Output.pdf");
import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Εάν NextSibling είναι μηδενικό, τότε πιθανότατα αυτό είναι το τελευταίο Run στην Παράγραφο. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.pdf"); import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Εάν NextSibling είναι μηδενικό, τότε πιθανότατα αυτό είναι το τελευταίο Run στην Παράγραφο. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1); doc.save("Output.pdf", saveOptions);
import com.aspose.words.*;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
Run secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun);

builder.moveTo(secondRun);
builder.startBookmark("Aspose bookmark");
// Εάν NextSibling είναι μηδενικό, τότε πιθανότατα αυτό είναι το τελευταίο Run στην Παράγραφο.
if (secondRun.getNextSibling() != null)
    builder.moveTo(secondRun.getNextSibling());
else
    builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");

PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1);

doc.save("Output.pdf", saveOptions);
import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Εάν NextSibling είναι μηδενικό, τότε πιθανότατα αυτό είναι το τελευταίο Run στην Παράγραφο. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.pdf"); import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Εάν NextSibling είναι μηδενικό, τότε πιθανότατα αυτό είναι το τελευταίο Run στην Παράγραφο. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1); doc.save("Output.pdf", saveOptions);
import com.aspose.words.*;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.insertChart(ChartType.PIE, 432, 252);
Chart chart = shape.getChart();
chart.getTitle().setText("Demo Chart");

chart.getSeries().clear();
chart.getSeries().add("Series 1",
        new String[] { "Category1", "Category2", "Category3" },
        new double[] { 2.7, 3.2, 0.8 });

doc.save("Output.pdf");
import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Εάν NextSibling είναι μηδενικό, τότε πιθανότατα αυτό είναι το τελευταίο Run στην Παράγραφο. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.pdf"); import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Εάν NextSibling είναι μηδενικό, τότε πιθανότατα αυτό είναι το τελευταίο Run στην Παράγραφο. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1); doc.save("Output.pdf", saveOptions);
Εκτέλεση κώδικα

Πώς να φτιάξετε το PDF στο Java

  1. Εγκαταστήστε Aspose.Words for Java
  2. Προσθέστε μια αναφορά βιβλιοθήκης (εισάγετε τη βιβλιοθήκη) στο έργο σας Java
  3. Δημιουργήστε ένα νέο PDF έγγραφο
  4. Καλέστε τη μέθοδο save(), περνώντας το όνομα του αρχείου
  5. Λάβετε το αποτέλεσμα ως ξεχωριστό αρχείο

Java βιβλιοθήκη για δημιουργία PDF

Φιλοξενούμε τα πακέτα Java μας στα αποθετήρια Maven. 'Aspose.Words για Java' είναι ένα κοινό JAR που περιέχει byte-κώδικα. Ακολουθήστε τις οδηγίες βήμα προς βήμα σχετικά με τον τρόπο εγκατάστασης στο περιβάλλον προγραμματιστή Java.

Απαιτήσεις συστήματος

Υποστηρίζονται Java SE 7 και πιο πρόσφατες Java Παρέχουμε επίσης ένα ξεχωριστό πακέτο για το Java SE 6 σε περίπτωση που είστε υποχρεωμένοι να χρησιμοποιήσετε αυτό το ξεπερασμένο JRE.

Το Java μας είναι πολλαπλών πλατφορμών και τρέχει σε όλα τα λειτουργικά συστήματα με JVM, συμπεριλαμβανομένων των Microsoft Windows, Linux, macOS, Android και iOS.

Για πληροφορίες σχετικά με τις προαιρετικές εξαρτήσεις πακέτων, όπως JogAmp JOGL, Harfbuzz γραμματοσειράς Java Advanced Imaging JAI, ανατρέξτε στην Τεκμηρίωση προϊόντος.

Άλλες υποστηριζόμενες μορφές αρχείων

Μπορείτε να δημιουργήσετε έγγραφα σε άλλες μορφές αρχείων:

5%

Εγγραφείτε στις ενημερώσεις προϊόντων Aspose

Λάβετε μηνιαία ενημερωτικά δελτία και προσφορές απευθείας στο γραμματοκιβώτιό σας.

© Aspose Pty Ltd 2001-2024. Ολα τα δικαιώματα διατηρούνται.