package com.vrs.selfserv.util;

import java.io.*;
import java.net.URL;

import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class MBPSplitter {

  public MBPSplitter() {
  }

  /**
   * @param args
   */
  public static void main(String[] args) {
    System.out.println("Here we go...");
    try {
    byte pswd[] = null; 
    URL inputFile = new URL("file://fileserver1/MBPS/vrs2005/vrsmbpSORTED_File10_092805.txt.pdf");
//    String inputFile = "h:/Downloads/ivadobe.pdf";
    RandomAccessFileOrArray accessor = new RandomAccessFileOrArray(inputFile); 
    PdfReader reader = new PdfReader(accessor,null);
    System.out.println("File size: " + reader.getFileLength());
    Document document = new Document(reader.getPageSizeWithRotation(1));
    PdfCopy copy = new PdfCopy(document, new FileOutputStream("h:\\downloads\\e.pdf"));
    document.open();
    PdfImportedPage page = copy.getImportedPage(reader, 3);
    System.out.println("page number: " + page.getPageNumber());
    copy.addPage(page);
    document.close();
//    copy.close();
    }
    catch (RuntimeException e) {
      System.out.println("Runtime Exception: " + e.getMessage());
      e.printStackTrace();
    }
    catch (Exception e) {
      System.out.println("Exception: " + e.getMessage());
      e.printStackTrace();
    }
    finally {
      System.out.println("done...");
    }
  }

}
