Χρησιμοποιώντας το API προγραμματισμού μας, οι προγραμματιστές Java μπορούν εύκολα να δημιουργήσουν ένα έγγραφο σε PDF, DOC, DOCX, HTML, EPUB και πολλές άλλες μορφές με λίγες μόνο γραμμές κώδικα.
Με το δεδομένο ισχυρό API, οι προγραμματιστές Java μπορούν να δημιουργήσουν έγγραφα σχεδόν σε οποιαδήποτε μορφή. Για να το κάνετε αυτό, πρέπει να ακολουθήσετε μερικά βήματα χρησιμοποιώντας τη βιβλιοθήκη Java:
Αξίζει να σημειωθεί ότι ένα κενό έγγραφο τεχνικά υποτίθεται ότι περιέχει μία παράγραφο, επομένως όταν δημιουργείτε μέσω προγραμματισμού ένα έγγραφο, θα έχετε ακριβώς αυτή τη βασική δομή εγγράφου.
Σημειώστε ότι μπορείτε να προσθέσετε άμεσα περιεχόμενο σε ένα έγγραφο που δημιουργήθηκε πρόσφατα. Έτσι, δεν θα λάβετε απλώς ένα κενό έγγραφο, αλλά ένα έγγραφο που περιέχει το απαραίτητο περιεχόμενο. Για περισσότερες πληροφορίες σχετικά με τον τρόπο επεξεργασίας ενός εγγράφου, ανατρέξτε στη σελίδα Επεξεργασία.
Η δεδομένη βιβλιοθήκη Java σάς επιτρέπει να δημιουργήσετε μέσω προγραμματισμού ένα έγγραφο σε οποιαδήποτε υποστηριζόμενη μορφή – PDF, DOCX, DOC, RTF, ODT, EPUB, HTML και άλλα.
Δοκιμάστε την ισχυρή μας λειτουργικότητα και δείτε πώς μπορείτε να δημιουργήσετε ένα έγγραφο σε ορισμένες μορφές χρησιμοποιώντας το ακόλουθο παράδειγμα:
// Repository path: https://releases.aspose.com/java/repo/
// Maven, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>ver</version>
<classifier>jdk17</classifier>
</dependency>
αντίγραφο
// Repository path: https://releases.aspose.com/java/repo/
// Gradle, where 'ver' - Aspose.Words version number, for example, 24.4.
compile(group: 'com.aspose', name: 'aspose-words', version: 'ver', classifier: 'jdk17')
αντίγραφο
// Repository path: https://releases.aspose.com/java/repo/
// Ivy, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency org="com.aspose" name="aspose-words" rev="ver">
<artifact name="aspose-words" m:classifier="jdk17" ext="jar"/>
</dependency>
αντίγραφο
// Repository path: https://releases.aspose.com/java/repo/
// Sbt, where 'ver' - Aspose.Words version number, for example, 24.4.
libraryDependencies += "com.aspose" % "aspose-words" % "ver"
αντίγραφο
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.docx");
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.docx");
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.docx", 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.docx");
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.docx");
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.docx", 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.docx");
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.docx");
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.docx", 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.docx");
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.docx");
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.docx", saveOptions);
Φιλοξενούμε τα πακέτα 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, ανατρέξτε στην Τεκμηρίωση προϊόντος.