Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save conholdate-com-kb/2ae8ac9fb243168cc9fc437b83249178 to your computer and use it in GitHub Desktop.
Save conholdate-com-kb/2ae8ac9fb243168cc9fc437b83249178 to your computer and use it in GitHub Desktop.
How to Add an Attachment to PDF in Java. For further details: https://kb.conholdate.com/total/java/how-to-add-an-attachment-to-pdf-in-java/
import com.aspose.pdf.*;
public class Main {
public static void main(String[] args) throws Exception {// Attach file in PDF using Java
// Load a license
License lic = new License();
lic.setLicense("Aspose.Total.lic");
// Instantiate a FileSpecification object
FileSpecification fs = new FileSpecification("sample.xlsx", "Sample Excel File");
// Load the PDF
Document doc = new Document("Input.pdf");
// Add attachment
doc.getEmbeddedFiles().add("1", fs);
// Save the document
doc.save("AddAttachment.pdf");
System.out.println("Done");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment