إضافة مرفق

إضافة مرفق مستند

  1. اربط ملف PDF المصدر بـ PdfContentEditor الواجهة.
  2. افتح ملف المرفق كدفق إدخال.
  3. استدعِ addDocumentAttachment(...) مع الدفق، اسم الملف، والوصف.
  4. احفظ مستند PDF المحدث.
public static void addAttachment(Path inputFile, Path attachmentFile, Path outputFile) throws Exception {
    PdfContentEditor editor = new PdfContentEditor();
    try (InputStream attachmentStream = Files.newInputStream(attachmentFile)) {
        editor.bindPdf(inputFile.toString());
        editor.addDocumentAttachment(attachmentStream, attachmentFile.getFileName().toString(), "Sample attachment.");
        editor.save(outputFile.toString());
    } finally {
        editor.close();
    }
}