1 package it.stefanochizzolini.clown.samples; 2 3 import it.stefanochizzolini.clown.bytes.FileInputStream; 4 import it.stefanochizzolini.clown.bytes.IInputStream; 5 import it.stefanochizzolini.clown.documents.Document; 6 import it.stefanochizzolini.clown.documents.Page; 7 import it.stefanochizzolini.clown.documents.Pages; 8 import it.stefanochizzolini.clown.files.File; 9 import it.stefanochizzolini.clown.tokens.FileFormatException; 10 11 import java.io.RandomAccessFile ; 12 import java.util.Collection ; 13 14 21 public class MergeSample 22 implements ISample 23 { 24 public void run( 25 PDFClownSampleLoader loader 26 ) 27 { 28 34 35 String mainFilePath = loader.getPdfFileChoice("Please select main PDF file"); 37 String secondaryFilePath = loader.getPdfFileChoice("Please select secondary PDF file"); 38 39 File mainFile; 43 try 44 { 45 mainFile = new File( 46 new FileInputStream( 47 new RandomAccessFile (mainFilePath,"r") 48 ) 49 ); 50 } 51 catch(FileFormatException e) 52 {throw new RuntimeException (mainFilePath + " file has a bad file format.",e);} 53 catch(Exception e) 54 {throw new RuntimeException (mainFilePath + " file access error.",e);} 55 56 File secondaryFile; 58 try 59 { 60 secondaryFile = new File( 61 new FileInputStream( 62 new RandomAccessFile (secondaryFilePath,"r") 63 ) 64 ); 65 } 66 catch(FileFormatException e) 67 {throw new RuntimeException (secondaryFilePath + " file has a bad file format.",e);} 68 catch(Exception e) 69 {throw new RuntimeException (secondaryFilePath + " file access error.",e);} 70 71 Document mainDocument = mainFile.getDocument(); 73 Pages mainPages = mainDocument.getPages(); 74 Document secondaryDocument = secondaryFile.getDocument(); 75 76 82 mainPages.addAll( 83 (Collection <Page>)mainDocument.contextualize( 84 (Collection <Page>)secondaryDocument.getPages() 85 ) 86 ); 87 mainPages.update(); 89 loader.serialize(mainFile,this.getClass().getSimpleName()); 91 } 92 } | Popular Tags |