إضافة صفحات PDF في Java
Contents
[
Hide
]
يتيح لك Aspose.PDF for Java إدراج صفحات فارغة أو استيراد صفحات من مستند آخر.
إدراج صفحة فارغة في موضع محدد
استخدم هذا المثال عندما تحتاج إلى إضافة صفحة فارغة في وسط ملف PDF موجود.
- افتح ملف PDF المصدر Document.
- أدرج صفحة جديدة في الموضع المستهدف في مجموعة الصفحات.
- احفظ المستند المحدث.
public static void insertEmptyPage(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
document.getPages().insert(2);
document.save(outputFile.toString());
}
}
إلحاق صفحة فارغة في النهاية
استخدم هذا المثال عندما تحتاج إلى توسيع المستند بصفحة فارغة جديدة في النهاية.
- افتح ملف PDF المصدر Document.
- أضف صفحة جديدة إلى نهاية مجموعة الصفحات.
- احفظ ملف PDF المعدل.
public static void addEmptyPageToEnd(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
document.getPages().add();
document.save(outputFile.toString());
}
}
إضافة صفحة من مستند آخر
استخدم هذا المثال عندما تريد استيراد صفحة من ملف PDF إلى ملف PDF آخر.
- أنشئ الوجهة Document وافتح المستند المصدر.
- أضف أي محتوى مطلوب للوجهة واستورد الصفحة المستهدفة من ملف PDF المصدر.
- احفظ المستند الناتج.
public static void addPageFromAnotherDocument(Path inputFile, Path outputFile) {
try (Document document = new Document();
Document anotherDocument = new Document(inputFile.toString())) {
document.getPages().add().getParagraphs().add(new TextFragment("This is first page!"));
document.getPages().add(anotherDocument.getPages().get_Item(1));
document.save(outputFile.toString());
}
}