1 package it.stefanochizzolini.clown.samples; 2 3 import it.stefanochizzolini.clown.bytes.FileInputStream; 4 import it.stefanochizzolini.clown.documents.Document; 5 import it.stefanochizzolini.clown.documents.Page; 6 import it.stefanochizzolini.clown.files.File; 7 import it.stefanochizzolini.clown.tokens.FileFormatException; 8 9 import java.io.RandomAccessFile ; 10 11 18 public class SplitSample 19 implements ISample 20 { 21 public void run( 22 PDFClownSampleLoader loader 23 ) 24 { 25 32 33 String filePath = loader.getPdfFileChoice("Please select a PDF file"); 35 36 File file; 38 try 39 { 40 file = new File( 42 new FileInputStream( 43 new RandomAccessFile (filePath,"r") 44 ) 45 ); 46 } 47 catch(FileFormatException e) 48 {throw new RuntimeException (filePath + " file has a bad file format.",e);} 49 catch(Exception e) 50 {throw new RuntimeException (filePath + " file access error.",e);} 51 52 Document document = file.getDocument(); 54 55 int index = 0; 57 for(Page page : document.getPages()) 58 { 59 File pageFile = new File(); 61 Document pageDocument = pageFile.getDocument(); 62 66 pageDocument.getPages().add((Page)page.clone(pageDocument)); 67 loader.serialize(pageFile,this.getClass().getSimpleName() + "." + (++index),false); 69 } 70 } 71 } | Popular Tags |