This article demonstrates how to extract files from a PDF portfolio in Java using Spire.PDF for Java.
The input PDF:
import com.spire.pdf.PdfDocument; import com.spire.pdf.attachments.PdfAttachment; import java.io.*; public class ReadPortfolio { public static void main(String []args) throws IOException { //Create a PdfDocument instance PdfDocument pdf = new PdfDocument(); //Load the PDF file pdf.loadFromFile("Portfolio.pdf"); //Loop through the attachments in the file for(PdfAttachment attachment : (Iterable)pdf.getAttachments()){ //Extract files String fileName = attachment.getFileName(); OutputStream fos = new FileOutputStream("extract/" + fileName); fos.write(attachment.getData()); } pdf.dispose(); } }
Output: