Package com.itextpdf.text.pdf

Examples of com.itextpdf.text.pdf.RandomAccessFileOrArray


        resources.put(PdfName.XOBJECT, xobjects);
      }
      // parsing the content stream of the page
    PRStream stream = (PRStream)page.getAsStream(PdfName.CONTENTS);
    byte[] contentBytes = PdfReader.getStreamBytes(stream);
        PRTokeniser tokeniser = new PRTokeniser(new RandomAccessFileOrArray(RASFACTORY.createSource(contentBytes)));
        PdfContentParser ps = new PdfContentParser(tokeniser);
        ArrayList<PdfObject> operands = new ArrayList<PdfObject>();
        while (ps.parse(operands).size() > 0){
            PdfLiteral operator = (PdfLiteral)operands.get(operands.size() - 1);
            processOperator(operator, operands);
View Full Code Here


      }
    }
      try {
        // parse the content stream
        byte[] contentBytes = PdfReader.getStreamBytes(stream);
            PRTokeniser tokeniser = new PRTokeniser(new RandomAccessFileOrArray(contentBytes));
            PdfContentParser ps = new PdfContentParser(tokeniser);
            ArrayList<PdfObject> operands = new ArrayList<PdfObject>();
            while (ps.parse(operands).size() > 0){
                PdfLiteral operator = (PdfLiteral)operands.get(operands.size() - 1);
                processOperator(this, operator, operands);
View Full Code Here

  private void createPdfDocumentFileFromTIFF(File tiffFile, File pdfFile) throws Exception {
    Document document = new Document(PageSize.A4, 0.0f, 0.0f, 0.0f, 0.0f);
    PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
    document.open();
    RandomAccessFileOrArray ra = new RandomAccessFileOrArray(tiffFile.getCanonicalPath());
    int pageCount = TiffImage.getNumberOfPages(ra);
    for (int i = 0; i < pageCount; ++i) {
      Image img = TiffImage.getTiffImage(ra, i + 1);
      if (img != null) {
        if (i != 0) {
          document.newPage();
        }
        if (img.getWidth() > PageSize.A4.getWidth() || img.getHeight() > PageSize.A4.getHeight()) {
          img.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight());
        }
        document.add(img);
      }
    }
    ra.close();
    document.close();
  }
View Full Code Here

  private void createPdfDocumentFileFromTIFF(File tiffFile, File pdfFile) throws Exception {
    Document document = new Document(PageSize.A4, 0.0f, 0.0f, 0.0f, 0.0f);
    PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
    document.open();
    RandomAccessFileOrArray ra = new RandomAccessFileOrArray(tiffFile.getCanonicalPath());
    int pageCount = TiffImage.getNumberOfPages(ra);
    for (int i = 0; i < pageCount; ++i) {
      God.appWindow.getStatusBar().setInitProgress(i, pageCount);
      Image img = TiffImage.getTiffImage(ra, i + 1);
      if (img != null) {
        if (i != 0) {
          document.newPage();
        }
        if (img.getWidth() > PageSize.A4.getWidth() || img.getHeight() > PageSize.A4.getHeight()) {
          img.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight());
        }
        document.add(img);
      }
    }
    God.appWindow.getStatusBar().setInitProgress(pageCount, pageCount);
    ra.close();
    document.close();
  }
View Full Code Here

   * @throws IOException
   */
  public static List<File> convertTiffFileToPngFiles(File tiffFile, File tmpDirectory) throws IOException {
    tmpDirectory.mkdirs();
    List<File> list = new ArrayList<File>();
    RandomAccessFileOrArray ra = new RandomAccessFileOrArray(tiffFile.getCanonicalPath());
    int pageCount = TiffImage.getNumberOfPages(ra);
    for (int i = 0; i < pageCount; ++i) {
      Image img = TiffImage.getTiffImage(ra, i + 1);
      if (img != null) {
        try {
          // First - create a single PDF page from the tiff page.
          Document document = new Document(PageSize.A4, 0.0f, 0.0f, 0.0f, 0.0f);
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          PdfWriter.getInstance(document, baos);
          document.open();
          document.add(img);
          document.close();

          // Second - read the memory based PDF file and read the image. Write
          // this into PNG file.
          PdfReader reader = new PdfReader(baos.toByteArray());
          for (int j = 0; j < reader.getXrefSize(); j++) {
            PdfObject pdfobj = reader.getPdfObject(j);
            if (pdfobj != null) {
              if (pdfobj.isStream()) {
                PdfStream stream = (PdfStream) pdfobj;
                PdfObject pdfsubtype = stream.get(PdfName.SUBTYPE);
                if (pdfsubtype != null) {
                  if (pdfsubtype.toString().equals(PdfName.IMAGE.toString())) {
                    PdfImageObject image = new PdfImageObject((PRStream) stream);
                    BufferedImage bufferedImage = image.getBufferedImage();
                    if (bufferedImage != null) {
                      String pngName = IdUtils.getUniqueID() + ".png";
                      File pngFile = new File(tmpDirectory, pngName);
                      FileOutputStream out = new FileOutputStream(pngFile);
                      ImageIO.write(bufferedImage, "png", out);
                      out.close();
                      list.add(pngFile);
                    }
                  }
                }
              }
            }
          }
          reader.close();
        } catch (Exception exception) {
          // Ignore - the page may be corrupt.
        }
      }
    }
    ra.close();
    return list;
  }
View Full Code Here

      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);
          Image 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);
          Image 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

      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);
          Image 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();
          // TODO number of pages never read, can be removed?
          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);
            Image 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

        out.println("- - - - - XObject Summary - - - - - -");
        out.println(getXObjectDetail(pageDictionary.getAsDict(PdfName.RESOURCES)));
       
        out.println("- - - - - Content Stream - - - - - -");
        RandomAccessFileOrArray f = reader.getSafeFile();

        byte[] contentBytes = reader.getPageContent(pageNum, f);
        f.close();

        out.flush();

        InputStream is = new ByteArrayInputStream(contentBytes);
        int ch;
View Full Code Here

    public PRTokeniser getLocation(String location) throws IOException {
        String fullName = BaseFont.RESOURCE_PATH + "cmaps/" + location;
        InputStream inp = BaseFont.getResourceStream(fullName);
        if (inp == null)
            throw new IOException(MessageLocalization.getComposedMessage("the.cmap.1.was.not.found", fullName));
        return new PRTokeniser(new RandomAccessFileOrArray(inp));
    }
View Full Code Here

        }
    }

    public static void populateDescription(String path, BaseFont font, FontDescription descr)
            throws IOException, NoSuchFieldException, IllegalAccessException, DocumentException {
        RandomAccessFileOrArray rf = null;
        try {
            rf = new RandomAccessFileOrArray(getTTCName(path));

            rf = populateDescription0(path, font, descr, rf);
        } finally {
            if (rf != null) {
                try {
                    rf.close();
                } catch (IOException e) {
                    // ignore
                }
            }
        }
View Full Code Here

TOP

Related Classes of com.itextpdf.text.pdf.RandomAccessFileOrArray

Copyright © 2018 www.massapicom. 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.