Examples of RandomAccessFileOrArray


Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

      transitions = parseXmlInput(inputCommand.getInputXmlFile(), transitions);
      try{
        prefixParser = new PrefixParser(inputCommand.getOutputFilesPrefix(), inputCommand.getInputFile().getFile().getName());       
        File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
       
        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()),inputCommand.getInputFile().getPasswordBytes());
        pdfReader.removeUnusedObjects();
        pdfReader.consolidateNamedDestinations();
       
        //version
        LOG.debug("Creating a new document.");
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

          tableItem.setInputFile(fileToAdd);
          tableItem.setPassword(password);
          tableItem.setPageSelection(pageSelection);
            try{
                //fix 04/11/08 for memory usage
               pdfReader = new PdfReader(new RandomAccessFileOrArray(fileToAdd.getAbsolutePath()), (password != null)?password.getBytes():null);                 
                 tableItem.setEncrypted(pdfReader.isEncrypted());
                 tableItem.setFullPermission(pdfReader.isOpenedWithFullPermissions());
                 if(tableItem.isEncrypted()){
                   tableItem.setPermissions(getPermissionsVerbose(pdfReader.getPermissions()));
                   int cMode = pdfReader.getCryptoMode();
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

      if (c1 == 'B' && c2 == 'M') {
        return  BmpImage.getImage(url);
      }
      if ((c1 == 'M' && c2 == 'M' && c3 == 0 && c4 == 42)
          || (c1 == 'I' && c2 == 'I' && c3 == 42 && c4 == 0)) {
        RandomAccessFileOrArray ra = null;
        try {
          if (url.getProtocol().equals("file")) {
            String file = url.getFile();
                        file = Utilities.unEscapeURL(file);
            ra = new RandomAccessFileOrArray(file);
          } else
            ra = new RandomAccessFileOrArray(url);
          LwgImage img = TiffImage.getTiffImage(ra, 1);
          img.url = url;
          return img;
        } finally {
          if (ra != null)
            ra.close();
        }

      }
      if ( c1 == 0x97 && c2 == 'J' && c3 == 'B' && c4 == '2' &&
          c5 == '\r' && c6 == '\n' && c7 == 0x1a && c8 == '\n' ) {
        RandomAccessFileOrArray ra = null;
        try {
          if (url.getProtocol().equals("file")) {
            String file = url.getFile();
            file = Utilities.unEscapeURL(file);
                  ra = new RandomAccessFileOrArray(file);
          } else
            ra = new RandomAccessFileOrArray(url);
          LwgImage img = JBIG2Image.getJbig2Image(ra, 1);
          img.url = url;
          return img;
        } finally {
            if (ra != null)
              ra.close();
        }
      }
      throw new IOException(url.toString()
          + " is not a recognized imageformat.");
    } finally {
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

      if (c1 == 'B' && c2 == 'M') {
        return BmpImage.getImage(imgb);
      }
      if ((c1 == 'M' && c2 == 'M' && c3 == 0 && c4 == 42)
          || (c1 == 'I' && c2 == 'I' && c3 == 42 && c4 == 0)) {
        RandomAccessFileOrArray ra = null;
        try {
          ra = new RandomAccessFileOrArray(imgb);
          LwgImage img = TiffImage.getTiffImage(ra, 1);
                    if (img.getOriginalData() == null)
                        img.setOriginalData(imgb);
          return img;
        } finally {
          if (ra != null)
            ra.close();
        }

      }
      if ( c1 == 0x97 && c2 == 'J' && c3 == 'B' && c4 == '2' ) {
        is = new java.io.ByteArrayInputStream(imgb);
        is.skip(4);
        int c5 = is.read();
        int c6 = is.read();
        int c7 = is.read();
        int c8 = is.read();
        if ( c5 == '\r' && c6 == '\n' && c7 == 0x1a && c8 == '\n' ) {
          int file_header_flags = is.read();
          int number_of_pages = -1;
          if ( (file_header_flags & 0x2) == 0x2 ) {
            number_of_pages = (is.read() << 24) | (is.read() << 16) | (is.read() << 8) | is.read();
          }
          is.close();
          // a jbig2 file with a file header.  the header is the only way we know here.                                                          
          // embedded jbig2s don't have a header, have to create them by explicit use of Jbig2Image?
          // nkerr, 2008-12-05  see also the getInstance(URL)
          RandomAccessFileOrArray ra = null;
          try {
            ra = new RandomAccessFileOrArray(imgb);
            LwgImage img = JBIG2Image.getJbig2Image(ra, 1);
            if (img.getOriginalData() == null)
              img.setOriginalData(imgb);
            return img;
          } finally {
            if (ra != null)
              ra.close();
          }
        }
      }
      throw new IOException(MessageLocalization.getComposedMessage("the.byte.array.is.not.a.recognized.imageformat"));
    } finally {
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;
      LwgDocument document = new LwgDocument(LwgPageSize.A4);
            float width = LwgPageSize.A4.getWidth() - 40;
            float height = LwgPageSize.A4.getHeight() - 120;
      if ("ORIGINAL".equals(getValue("pagesize"))) {
        LwgImage img = TiffImage.getTiffImage(ra, 1);
                if (img.getDpiX() > 0 && img.getDpiY() > 0) {
                    img.scalePercent(7200f / img.getDpiX(), 7200f / img.getDpiY());
                }
        document.setPageSize(new LwgRectangle(img.getScaledWidth(), img.getScaledHeight()));
        adjustSize = true;
      }
      else if ("LETTER".equals(getValue("pagesize"))) {
        document.setPageSize(LwgPageSize.LETTER);
                width = LwgPageSize.LETTER.getWidth() - 40;
                height = LwgPageSize.LETTER.getHeight() - 120;
      }
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdf_file));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
            for (int c = 0; c < comps; ++c) {
                LwgImage 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 LwgRectangle(img.getScaledWidth(),
                  img.getScaledHeight()));
                        document.newPage();
                    img.setAbsolutePosition(0, 0);
                  }
                  else {
                    if (img.getScaledWidth() > width || img.getScaledHeight() > height) {
                            if (img.getDpiX() > 0 && img.getDpiY() > 0) {
                                float adjx = width / img.getScaledWidth();
                                float adjy = height / img.getScaledHeight();
                                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

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

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

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

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());
      LwgImage img = TiffImage.getTiffImage(odd, 1);
      LwgDocument document = new LwgDocument(new LwgRectangle(img.getScaledWidth(),
          img.getScaledHeight()));
      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 {
          LwgImage imgOdd = TiffImage.getTiffImage(odd, c + 1);
          LwgImage imgEven = TiffImage.getTiffImage(even, count - c);
          document.setPageSize(new LwgRectangle(imgOdd.getScaledWidth(),
              imgOdd.getScaledHeight()));
          document.newPage();
          imgOdd.setAbsolutePosition(0, 0);
          cb.addImage(imgOdd);
          document.setPageSize(new LwgRectangle(imgEven.getScaledWidth(),
              imgEven.getScaledHeight()));
          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

        levelCombo.removeAllItems();
        byte[] password = null;
        if((item.getPassword()) != null && (item.getPassword()).length()>0){
          password = item.getPassword().getBytes();
        }
        PdfReader pdfReader = new PdfReader(new RandomAccessFileOrArray(item.getInputFile().getAbsolutePath()),password);       
        pdfReader.consolidateNamedDestinations();
        List bookmarks = SimpleBookmark.getBookmark(pdfReader);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        SimpleBookmark.exportToXML(bookmarks, out, "UTF-8", false);
        ByteArrayInputStream input = new ByteArrayInputStream(out.toByteArray());     
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

        for(int i = 0; i<fileList.length; i++){
          try{           
               
            prefixParser = new PrefixParser(inputCommand.getOutputFilesPrefix(), fileList[i].getFile().getName());
            File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
            pdfReader = new PdfReader(new RandomAccessFileOrArray(fileList[i].getFile().getAbsolutePath()),fileList[i].getPasswordBytes());
            pdfReader.removeUnusedObjects();
            pdfReader.consolidateNamedDestinations();
           
            //version
            LOG.debug("Creating a new document.");
View Full Code Here

Examples of com.lowagie.text.pdf.RandomAccessFileOrArray

        }
       
        for(int i = 0; i<fileList.length; i++){
          int unpackedFiles = 0;
          try{
            pdfReader = new PdfReader(new RandomAccessFileOrArray(fileList[i].getFile().getAbsolutePath()),fileList[i].getPasswordBytes());
            pdfReader.removeUnusedObjects();
            pdfReader.consolidateNamedDestinations();
           
            PdfDictionary catalog = pdfReader.getCatalog();
            PdfDictionary names = (PdfDictionary) PdfReader.getPdfObject(catalog.get(PdfName.NAMES));
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.