צור מסמכי PDF או Word ב Java

צור מסמך חדש כמעט בכל פורמט באופן פרוגרמטי באמצעות ספריית הנאמנות הגבוהה שלנו Java

באמצעות ממשק API לתכנות שלנו, מפתחי Java יכולים ליצור בקלות מסמך ב PDF, DOC, DOCX, HTML, EPUB ופורמטים רבים אחרים עם מספר שורות קוד בלבד.

הצג את קטע הקוד

צור מסמך באמצעות Java

עם ה API החזק הנתון, מפתחי Java יכולים ליצור מסמכים כמעט בכל פורמט. כדי לעשות זאת, עליך לבצע מספר שלבים באמצעות ספריית Java שלנו:

  1. הוסף שם קובץ
  2. התחל ליצור מסמך באמצעות Java
  3. שמור את המסמך שנוצר בפורמט שנבחר

ראוי לציין שמסמך ריק אמור מבחינה טכנית להכיל פסקה אחת, כך שכשאתה יוצר מסמך באופן תוכנתי, תקבל בדיוק את מבנה המסמך הבסיסי הזה.

שים לב שאתה יכול להוסיף תוכן באופן מיידי למסמך חדש שנוצר. כך, תקבלו לא רק מסמך ריק, אלא מסמך המכיל את התוכן הדרוש. למידע נוסף על אופן עריכת מסמך, עיין בדף העריכה.

צור מסמך ב Java באופן פרוגרמטי

ספריית Java הנתונה מאפשרת לך ליצור מסמך באופן פרוגרמטי בכל פורמט נתמך - PDF, DOCX, DOC, RTF, ODT, EPUB, HTML ואחרים.

נסה את הפונקציונליות החזקה שלנו וראה כיצד ליצור מסמך בפורמטים מסוימים באמצעות הדוגמה הבאה:

צור מסמך חדש באמצעות 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.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 הוא null, סביר להניח שזו 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 הוא null, סביר להניח שזו 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 הוא null, סביר להניח שזו 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 הוא null, סביר להניח שזו 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 הוא null, סביר להניח שזו 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 הוא null, סביר להניח שזו 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 הוא null, סביר להניח שזו 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 הוא null, סביר להניח שזו 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 הוא null, סביר להניח שזו 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

  1. התקן Aspose.Words for Java
  2. הוסף הפניה לספרייה (ייבא את הספרייה) לפרויקט Java שלך
  3. צור מסמך חדש
  4. התקשר לשיטת save(), העברת שם הקובץ
  5. קבל את התוצאה כקובץ נפרד

ספריית Java ליצירת מסמכים

אנו מארחים את חבילות ה- Java שלנו במאגרי Maven. 'Aspose.Words עבור Java' הוא JAR נפוץ המכיל קוד בתים. אנא עקוב אחר ההוראות שלב אחר שלב כיצד להתקין אותו בסביבת מפתח 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. כל הזכויות שמורות.