Examples of RandomAccessFileOrArray


Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

      File odd_file = (File)getValue("odd");
      if (getValue("even") == null) throw new InstantiationException("You need to choose a sourcefile for the even pages");
      File even_file = (File)getValue("even");
      if (getValue("destfile") == null) throw new InstantiationException("You need to choose a destination file");
      File pdf_file = (File)getValue("destfile");
      RandomAccessFileOrArray odd = new RandomAccessFileOrArray(odd_file.getAbsolutePath());
      RandomAccessFileOrArray even = new RandomAccessFileOrArray(even_file.getAbsolutePath());
      Image img = TiffImage.getTiffImage(odd, 1);
      Document document = new Document(new Rectangle(img.scaledWidth(),
          img.scaledHeight()));
      PdfWriter writer = PdfWriter.getInstance(document,
          new FileOutputStream(pdf_file));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      int count = Math.max(TiffImage.getNumberOfPages(odd), TiffImage
          .getNumberOfPages(even));
      for (int c = 0; c < count; ++c) {
        try {
          Image imgOdd = TiffImage.getTiffImage(odd, c + 1);
          Image imgEven = TiffImage.getTiffImage(even, count - c);
          document.setPageSize(new Rectangle(imgOdd.scaledWidth(),
              imgOdd.scaledHeight()));
          document.newPage();
          imgOdd.setAbsolutePosition(0, 0);
          cb.addImage(imgOdd);
          document.setPageSize(new Rectangle(imgEven.scaledWidth(),
              imgEven.scaledHeight()));
          document.newPage();
          imgEven.setAbsolutePosition(0, 0);
          cb.addImage(imgEven);

        } catch (Exception e) {
          System.out.println("Exception page " + (c + 1) + " "
              + e.getMessage());
        }
      }
      odd.close();
      even.close();
      document.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

    if (file.exists()) {
      int page = 1;
      PdfReader reader = null;

      try {
        reader = new PdfReader(new RandomAccessFileOrArray(file.getAbsolutePath()), null);
        HashMap pdfinfo = reader.getInfo();

        StringBuffer sb = new StringBuffer();
        sb.append("<html>=== Document Information ===<p>");
        sb.append(reader.getCropBox(page).height() + "*"
 
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

    try {
      if (getValue("srcfile") == null) throw new InstantiationException("You need to choose a sourcefile");
      File tiff_file = (File)getValue("srcfile");
      if (getValue("destfile") == null) throw new InstantiationException("You need to choose a destination file");
      File pdf_file = (File)getValue("destfile");
      RandomAccessFileOrArray ra = new RandomAccessFileOrArray(tiff_file.getAbsolutePath());
            int comps = TiffImage.getNumberOfPages(ra);
      boolean adjustSize = false;
      Document document = new Document(PageSize.A4);
            float width = PageSize.A4.width() - 40;
            float height = PageSize.A4.height() - 120;
      if ("ORIGINAL".equals(getValue("pagesize"))) {
        Image img = TiffImage.getTiffImage(ra, 1);
                if (img.getDpiX() > 0 && img.getDpiY() > 0) {
                    img.scalePercent(7200f / img.getDpiX(), 7200f / img.getDpiY());
                }
        document.setPageSize(new Rectangle(img.scaledWidth(), img.scaledHeight()));
        adjustSize = true;
      }
      else if ("LETTER".equals(getValue("pagesize"))) {
        document.setPageSize(PageSize.LETTER);
                width = PageSize.LETTER.width() - 40;
                height = PageSize.LETTER.height() - 120;
      }
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdf_file));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
            for (int c = 0; c < comps; ++c) {
                Image img = TiffImage.getTiffImage(ra, c + 1);
                if (img != null) {
                    if (img.getDpiX() > 0 && img.getDpiY() > 0) {
                        img.scalePercent(7200f / img.getDpiX(), 7200f / img.getDpiY());
                    }
                  if (adjustSize) {
              document.setPageSize(new Rectangle(img.scaledWidth(),
                  img.scaledHeight()));
                        document.newPage();
                    img.setAbsolutePosition(0, 0);
                  }
                  else {
                    if (img.scaledWidth() > width || img.scaledHeight() > height) {
                            if (img.getDpiX() > 0 && img.getDpiY() > 0) {
                                float adjx = width / img.scaledWidth();
                                float adjy = height / img.scaledHeight();
                                float adj = Math.min(adjx, adjy);
                                img.scalePercent(7200f / img.getDpiX() * adj, 7200f / img.getDpiY() * adj);
                            }
                            else
                                img.scaleToFit(width, height);
                    }
                    img.setAbsolutePosition(20, 20);
                        document.newPage();
                        document.add(new Paragraph(tiff_file + " - page " + (c + 1)));
                  }
                    cb.addImage(img);
                    System.out.println("Finished page " + (c + 1));
                }
            }
            ra.close();
            document.close();
    } catch (Exception e) {
          JOptionPane.showMessageDialog(internalFrame,
                e.getMessage(),
                e.getClass().getName(),
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

     * @throws Exception
     */
    private void executeBurst(SplitParsedCommand inputCommand) throws Exception {
        int currentPage;
        Document currentDocument;
        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()),
                inputCommand.getInputFile().getPasswordBytes());
        pdfReader.removeUnusedObjects();
        pdfReader.consolidateNamedDestinations();

        // we retrieve the total number of pages
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

     *
     * @param inputCommand
     * @throws Exception
     */
    private void executeSplitOddEven(SplitParsedCommand inputCommand) throws Exception {
        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()),
                inputCommand.getInputFile().getPasswordBytes());
        pdfReader.removeUnusedObjects();
        pdfReader.consolidateNamedDestinations();

        // we retrieve the total number of pages
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

     * @param bookmarksTable
     *            bookmarks table. It's populated only when splitting by bookmarks. If null or empty it's ignored
     * @throws Exception
     */
    private void executeSplit(SplitParsedCommand inputCommand, Hashtable bookmarksTable) throws Exception {
        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()),
                inputCommand.getInputFile().getPasswordBytes());
        pdfReader.removeUnusedObjects();
        pdfReader.consolidateNamedDestinations();

        int n = pdfReader.getNumberOfPages();
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

     * @throws Exception
     */
    private void executeNSplit(SplitParsedCommand inputCommand) throws Exception {
        Integer[] numberPages = inputCommand.getSplitPageNumbers();
        if (numberPages != null && numberPages.length == 1) {
            pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile()
                    .getAbsolutePath()), inputCommand.getInputFile().getPasswordBytes());
            pdfReader.removeUnusedObjects();
            pdfReader.consolidateNamedDestinations();
            int n = pdfReader.getNumberOfPages();
            int numberPage = numberPages[0].intValue();
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

     *
     * @param inputCommand
     * @throws Exception
     */
    private void executeBookmarksSplit(SplitParsedCommand inputCommand) throws Exception {
        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()),
                inputCommand.getInputFile().getPasswordBytes());
        int bLevel = inputCommand.getBookmarksLevel().intValue();
        Hashtable bookmarksTable = new Hashtable();
        if (bLevel > 0) {
            pdfReader.removeUnusedObjects();
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

     *
     * @param inputCommand
     * @throws Exception
     */
    private void executeSizeSplit(SplitParsedCommand inputCommand) throws Exception {
        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()),
                inputCommand.getInputFile().getPasswordBytes());
        pdfReader.removeUnusedObjects();
        pdfReader.consolidateNamedDestinations();
        int n = pdfReader.getNumberOfPages();
        BookmarksProcessor bookmarkProcessor = new BookmarksProcessor(SimpleBookmark.getBookmark(pdfReader), n);
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

      setPercentageOfWorkDone(0);
      Document currentDocument;
      try{                               
        File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
        LOG.debug("Opening "+inputCommand.getInputFile().getFile().getAbsolutePath());
        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()),inputCommand.getInputFile().getPasswordBytes());
        pdfReader.removeUnusedObjects();
          pdfReader.consolidateNamedDestinations();
          int n = pdfReader.getNumberOfPages();
            currentDocument = new Document(pdfReader.getPageSizeWithRotation(1));
           
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.