1 31 package org.pdfbox; 32 33 import java.io.IOException ; 34 35 import org.pdfbox.pdmodel.PDDocument; 36 import org.pdfbox.pdmodel.PDDocumentCatalog; 37 38 import org.pdfbox.pdmodel.fdf.FDFDocument; 39 40 import org.pdfbox.pdmodel.interactive.form.PDAcroForm; 41 42 49 public class ImportFDF 50 { 51 54 public ImportFDF() 55 { 56 } 57 58 67 public void importFDF( PDDocument pdfDocument, FDFDocument fdfDocument ) throws IOException 68 { 69 PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog(); 70 PDAcroForm acroForm = docCatalog.getAcroForm(); 71 acroForm.setCacheFields( true ); 72 acroForm.importFDF( fdfDocument ); 73 } 74 75 84 public static void main(String [] args) throws Exception 85 { 86 ImportFDF importer = new ImportFDF(); 87 importer.importFDF( args ); 88 } 89 90 private void importFDF( String [] args ) throws Exception 91 { 92 PDDocument pdf = null; 93 FDFDocument fdf = null; 94 95 try 96 { 97 if( args.length != 3 ) 98 { 99 usage(); 100 } 101 else 102 { 103 ImportFDF importer = new ImportFDF(); 104 105 pdf = PDDocument.load( args[0] ); 106 fdf = FDFDocument.load( args[1] ); 107 importer.importFDF( pdf, fdf ); 108 109 pdf.save( args[2] ); 110 } 111 } 112 finally 113 { 114 close( fdf ); 115 close( pdf ); 116 } 117 } 118 119 122 private static void usage() 123 { 124 System.err.println( "usage: org.pdfbox.ImportFDF <pdf-file> <fdf-file> <output-file>" ); 125 } 126 127 134 public void close( FDFDocument doc ) throws IOException 135 { 136 if( doc != null ) 137 { 138 doc.close(); 139 } 140 } 141 142 149 public void close( PDDocument doc ) throws IOException 150 { 151 if( doc != null ) 152 { 153 doc.close(); 154 } 155 } 156 } | Popular Tags |