Created
October 29, 2023 08:49
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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