اجعل PDF باستخدام مكتبة Java

تتيح مكتبتنا Java القوية للمطورين إنشاء PDF برمجيًا في بضع خطوات فقط

يمكن للمطورين Java إنشاء PDF بسهولة باستخدام واجهة برمجة تطبيقات منتجنا الفعالة فقط. هذا يعني أن الحل الذي نقدمه سيزود المبرمجين بكل ما يحتاجونه للإنشاء 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 for 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 Product Updates

احصل على رسائل إخبارية وعروض شهرية يتم تسليمها مباشرة إلى صندوق البريد الخاص بك.

© Aspose Pty Ltd 2001-2024. كل الحقوق محفوظة.