Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfReader


            }
        }

        System.out.println( "Converting: " + input +  " to " + output + " scaling by " + factor + " shifting by (" + left + ", " + down + ")");

        PdfReader reader = new PdfReader( input );
        int n = reader.getNumberOfPages();

        Rectangle psize = reader.getPageSize(1);
        float width = psize.getHeight();
        float height = psize.getWidth();

        Document document = new Document(new Rectangle(height, width));
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream( output ));
View Full Code Here


       Map model, HttpServletRequest request, HttpServletResponse response) throws Exception{

    // IE workaround: write into byte array first.
    ByteArrayOutputStream baos = createTemporaryOutputStream();

    PdfReader reader = readPdfResource();
    PdfStamper stamper = new PdfStamper(reader, baos);
    mergePdfDocument(model, stamper, request, response);
    stamper.close();

    // Flush to HTTP response.
View Full Code Here

   * @return the PdfReader instance
   * @throws IOException if resource access failed
   * @see #setUrl
   */
  protected PdfReader readPdfResource() throws IOException {
    return new PdfReader(getApplicationContext().getResource(getUrl()).getInputStream());
  }
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  public VerificationResult verify(final String aFileName, byte[] aPassword) {
    final VerificationResult tmpResult = new VerificationResult();
    try {
      final PdfReader tmpReader = getPdfReader(aFileName, aPassword);

      final AcroFields tmpAcroFields = tmpReader.getAcroFields();
      final ArrayList<String> tmpNames = tmpAcroFields.getSignatureNames();
      tmpResult.setTotalRevisions(tmpAcroFields.getTotalRevisions());

      for (String name : tmpNames) {
        final SignatureVerification tmpVerif = new SignatureVerification(name);
View Full Code Here

   * @param aSignatureName
   * @return
   * @throws IOException
   */
  public InputStream extractRevision(String aFileName, byte[] aPassword, String aSignatureName) throws IOException {
    final PdfReader tmpReader = getPdfReader(aFileName, aPassword);
    final AcroFields tmpAcroFields = tmpReader.getAcroFields();
    return tmpAcroFields.extractRevision(aSignatureName);
  }
View Full Code Here

   *            password
   * @return
   * @throws IOException
   */
  public static PdfReader getPdfReader(final String aFileName, byte[] aPassword) throws IOException {
    PdfReader tmpReader = null;
    try {
      // try to read without password
      tmpReader = new PdfReader(aFileName);
    } catch (Exception e) {
      try {
        tmpReader = new PdfReader(aFileName, new byte[0]);
      } catch (Exception e2) {
        tmpReader = new PdfReader(aFileName, aPassword);
      }
    }
    return tmpReader;
  }
View Full Code Here

    try {
      final PrivateKeyInfo pkInfo = KeyStoreUtils.getPkInfo(options);
      final PrivateKey key = pkInfo.getKey();
      final Certificate[] chain = pkInfo.getChain();
      options.log("console.createPdfReader", options.getInFile());
      PdfReader reader;
      try {
        // try to read without password
        reader = new PdfReader(options.getInFile());
      } catch (Exception e) {
        try {
          reader = new PdfReader(options.getInFile(), new byte[0]);
        } catch (Exception e2) {
          reader = new PdfReader(options.getInFile(), options.getPdfOwnerPwdStr().getBytes());
        }
      }

      options.log("console.createOutPdf", outFile);
      fout = new FileOutputStream(outFile);

      final HashAlgorithm hashAlgorithm = options.getHashAlgorithmX();

      options.log("console.createSignature");
      char tmpPdfVersion = '\0'; // default version - the same as input
      if (reader.getPdfVersion() < hashAlgorithm.getPdfVersion()) {
        tmpPdfVersion = hashAlgorithm.getPdfVersion();
        options.log("console.updateVersion", new String[] { String.valueOf(reader.getPdfVersion()),
            String.valueOf(tmpPdfVersion) });
      }
      final PdfStamper stp = PdfStamper.createSignature(reader, fout, tmpPdfVersion, null, options.isAppendX());
      if (!options.isAppendX()) {
        // we are not in append mode, let's remove existing signatures
View Full Code Here

      } else {
        newFileName = tmpFile + "_uncompressed.pdf";
      }
      System.out.println("Uncompressing " + tmpFile + " to " + newFileName);
      try {
        PdfReader reader = new PdfReader(tmpFile);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(newFileName), '\0');
        int total = reader.getNumberOfPages() + 1;
        for (int i = 1; i < total; i++) {
          reader.setPageContent(i, reader.getPageContent(i));
        }
        stamper.close();
      } catch (NullPointerException npe) {
        npe.printStackTrace();
      } catch (DocumentException e) {
View Full Code Here

   *
   * @return number of pages (or -1 if error occures)
   */
  public int getNumberOfPages() {
    int tmpResult = 0;
    PdfReader reader = null;
    try {
      try {
        // try to read without password
        reader = new PdfReader(options.getInFile());
      } catch (Exception e) {
        try {
          reader = new PdfReader(options.getInFile(), new byte[0]);
        } catch (Exception e2) {
          reader = new PdfReader(options.getInFile(), options.getPdfOwnerPwdStr().getBytes());
        }
      }
      tmpResult = reader.getNumberOfPages();
    } catch (Exception e) {
      tmpResult = -1;
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (Exception e) {
        }
      }
    }

View Full Code Here

   *            number of page for which size should be returned
   * @return FloatPoint or null
   */
  public FloatPoint getPageSize(int aPage) {
    FloatPoint tmpResult = null;
    PdfReader reader = null;
    try {
      try {
        // try to read without password
        reader = new PdfReader(options.getInFile());
      } catch (Exception e) {
        try {
          reader = new PdfReader(options.getInFile(), new byte[0]);
        } catch (Exception e2) {
          reader = new PdfReader(options.getInFile(), options.getPdfOwnerPwdStr().getBytes());
        }
      }
      final Rectangle tmpRect = reader.getPageSize(aPage);
      if (tmpRect != null) {
        tmpResult = new FloatPoint(tmpRect.getRight(), tmpRect.getTop());
      }
    } catch (Exception e) {
      // nothing to do
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (Exception e) {
        }
      }
    }

View Full Code Here

TOP

Related Classes of com.lowagie.text.pdf.PdfReader

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.