Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfReader


   */
  public void execute() {
    try {
      if (getValue("srcfile") == null) throw new InstantiationException("You need to choose a sourcefile");
      File src = (File)getValue("srcfile");
      PdfReader reader;
      if (getValue("ownerpassword") == null) {
        reader = new PdfReader(src.getAbsolutePath());
      }
      else {
        reader = new PdfReader(src.getAbsolutePath(), ((String)getValue("ownerpassword")).getBytes());
      }
            File directory = src.getParentFile();
            String name = src.getName();
            name = name.substring(0, name.lastIndexOf('.'));
            File html = new File(directory, name + "_index.html");
      Document document = new Document();
      HtmlWriter.getInstance(document, new FileOutputStream(html));
      Object css = getValue("css");
      if (css != null) {
        document.add(new Header(HtmlTags.STYLESHEET, css.toString()));
      }
      Object title = reader.getInfo().get("Title");
      if (title == null)
        document.addTitle("Index for " + src.getName());
      else
        document.addKeywords("Index for '" + title + "'");
      Object keywords = reader.getInfo().get("Keywords");
      if (keywords != null)
        document.addKeywords((String)keywords);
      Object description = reader.getInfo().get("Subject");
      if (keywords != null)
        document.addSubject((String)description);
      document.open();
      Paragraph t;
      if (title == null)
View Full Code Here


      }
      byte[] ownerpassword = null;
      if (getValue("ownerpassword") != null) {
        ownerpassword = ((String)getValue("ownerpassword")).getBytes();
      }
      PdfReader reader = new PdfReader(((File)getValue("srcfile")).getAbsolutePath());
      PdfEncryptor.encrypt(
            reader,
        new FileOutputStream((File)getValue("destfile")),
        userpassword,
        ownerpassword,
View Full Code Here

          if (getValue("destfile2") == null) throw new InstantiationException("You need to choose a destination file for the second part of the PDF");
          File file2 = (File)getValue("destfile2");
          int pagenumber = Integer.parseInt((String)getValue("pagenumber"));

          // we create a reader for a certain document
      PdfReader reader = new PdfReader(src.getAbsolutePath());
      // we retrieve the total number of pages
      int n = reader.getNumberOfPages();
      System.out.println("There are " + n + " pages in the original file.");

      if (pagenumber < 2 || pagenumber > n) {
        throw new DocumentException("You can't split this document at page " + pagenumber + "; there is no such page.");
      }

      // step 1: creation of a document-object
      Document document1 = new Document(reader.getPageSizeWithRotation(1));
      Document document2 = new Document(reader.getPageSizeWithRotation(pagenumber));
      // step 2: we create a writer that listens to the document
      PdfWriter writer1 = PdfWriter.getInstance(document1, new FileOutputStream(file1));
      PdfWriter writer2 = PdfWriter.getInstance(document2, new FileOutputStream(file2));
      // step 3: we open the document
      document1.open();
      PdfContentByte cb1 = writer1.getDirectContent();
      document2.open();
      PdfContentByte cb2 = writer2.getDirectContent();
      PdfImportedPage page;
      int rotation;
      int i = 0;
      // step 4: we add content
      while (i < pagenumber - 1) {
        i++;
        document1.setPageSize(reader.getPageSizeWithRotation(i));
        document1.newPage();
        page = writer1.getImportedPage(reader, i);
        rotation = reader.getPageRotation(i);
        if (rotation == 90 || rotation == 270) {
          cb1.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(i).height());
        }
        else {
          cb1.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
        }
      }
      while (i < n) {
        i++;
        document2.setPageSize(reader.getPageSizeWithRotation(i));
        document2.newPage();
        page = writer2.getImportedPage(reader, i);
        rotation = reader.getPageRotation(i);
        if (rotation == 90 || rotation == 270) {
          cb2.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(i).height());
        }
        else {
          cb2.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
        }
      }
View Full Code Here

      }
      catch(Exception e) {
        pow2 = 1;
      }
      // we create a reader for a certain document
      PdfReader reader = new PdfReader(src.getAbsolutePath());
      // we retrieve the total number of pages and the page size
      int total = reader.getNumberOfPages();
      System.out.println("There are " + total + " pages in the original file.");
            Rectangle pageSize = reader.getPageSize(1);
            Rectangle newSize = (pow2 % 2) == 0 ? new Rectangle(pageSize.width(), pageSize.height()) : new Rectangle(pageSize.height(), pageSize.width());
            Rectangle unitSize = new Rectangle(pageSize.width(), pageSize.height());
            Rectangle currentSize;
            for (int i = 0; i < pow2; i++) {
              unitSize = new Rectangle(unitSize.height() / 2, unitSize.width());
            }
            int n = (int)Math.pow(2, pow2);
            int r = (int)Math.pow(2, (int)pow2 / 2);
            int c = n / r;
      // step 1: creation of a document-object
      Document document = new Document(newSize, 0, 0, 0, 0);
      // step 2: we create a writer that listens to the document
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
      // step 3: we open the document
      document.open();
      // step 4: adding the content
      PdfContentByte cb = writer.getDirectContent();
      PdfImportedPage page;
      float offsetX, offsetY, factor;
      int p;
      for (int i = 0; i < total; i++) {
        if (i % n == 0) {
          document.newPage();
        }
        p = i + 1;
        offsetX = unitSize.width() * ((i % n) % c);
        offsetY = newSize.height() - (unitSize.height() * (((i % n) / c) + 1));
        currentSize = reader.getPageSize(p);
        factor = Math.min(unitSize.width() / currentSize.width(), unitSize.height() / currentSize.height());
        offsetX += (unitSize.width() - (currentSize.width() * factor)) / 2f;
        offsetY += (unitSize.height() - (currentSize.height() * factor)) / 2f;
        page = writer.getImportedPage(reader, p);
        cb.addTemplate(page, factor, 0, 0, factor, offsetX, offsetY);
View Full Code Here

            "You need to choose a destination file");
      }
      File dest = (File) getValue("destfile");

      // we create a reader for a certain document
      PdfReader reader = new PdfReader(src.getAbsolutePath());
      // we retrieve the total number of pages and the page size
      int total = reader.getNumberOfPages();
      System.out.println("There are " + total
          + " pages in the original file.");

      Rectangle pageSize = reader.getPageSize(1);
      Rectangle newSize = new Rectangle(pageSize.width() / 2, pageSize
          .height());
      // step 1: creation of a document-object
      Document document = new Document(newSize, 0, 0, 0, 0);
      // step 2: we create a writer that listens to the document
      PdfWriter writer = PdfWriter.getInstance(document,
          new FileOutputStream(dest));
      // step 3: we open the document
      document.open();
      // step 4: adding the content
      PdfContentByte cb = writer.getDirectContent();
      PdfImportedPage page;
      float offsetX, offsetY;
      int p;
      for (int i = 0; i < total; i++) {
        p = i + 1;
        pageSize = reader.getPageSize(p);
        newSize = new Rectangle(pageSize.width() / 2, pageSize.height());

        document.newPage();
        offsetX = 0;
        offsetY = 0;
View Full Code Here

   * @see com.lowagie.tools.AbstractTool#execute()
   */
  public void execute() {
    try {
      if (getValue("srcfile") == null) throw new InstantiationException("You need to choose a sourcefile");
      PdfReader reader;
      if (getValue("ownerpassword") == null) {
        reader = new PdfReader(((File)getValue("srcfile")).getAbsolutePath());
      }
      else {
        reader = new PdfReader(((File)getValue("srcfile")).getAbsolutePath(), ((String)getValue("ownerpassword")).getBytes());
      }
      // Some general document information and page size
      System.out.println("=== Document Information ===");
      System.out.println("PDF Version: " + reader.getPdfVersion());
      System.out.println("Number of pages: " + reader.getNumberOfPages());
      System.out.println("Number of PDF objects: " + reader.getXrefSize());
      System.out.println("File length: " + reader.getFileLength());
      System.out.println("Encrypted? " + reader.isEncrypted());
      if (reader.isEncrypted()) {
        System.out.println("Permissions: " + PdfEncryptor.getPermissionsVerbose(reader.getPermissions()));
        System.out.println("128 bit? " + reader.is128Key());
      }
      System.out.println("Rebuilt? " + (!reader.isRebuilt()));
      // Some metadata
      System.out.println("=== Metadata ===");
      HashMap info = reader.getInfo();
      String key;
      String value;
      for (Iterator i = info.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry entry = (Map.Entry) i.next();
        key = (String) entry.getKey();
        value = (String) entry.getValue();
        System.out.println(key + ": " + value);
      }
      if (reader.getMetadata() == null) {
        System.out.println("There is no XML Metadata in the file");
      }
      else {
        System.out.println("XML Metadata: " + new String(reader.getMetadata()));
      }
    }
    catch(Exception e) {
          JOptionPane.showMessageDialog(internalFrame,
                e.getMessage(),
View Full Code Here

            "You need to choose a destination file");
      }
      File dest = (File) getValue("destfile");

      // we create a reader for a certain document
      PdfReader reader = new PdfReader(src.getAbsolutePath());
      PdfObject o;
      PdfDictionary d;
      PdfDictionary l;
      PdfName n;
      for (int i = 1; i < reader.getXrefSize(); i++) {
        o = reader.getPdfObject(i);
        if (o instanceof PdfDictionary) {
          d = (PdfDictionary)o;
          o = d.get(PdfName.A);
          if (o == null) continue;
          if (o instanceof PdfDictionary) {
            l = (PdfDictionary)o;
          }
          else {
            PRIndirectReference r =(PRIndirectReference)o;
            l = (PdfDictionary)reader.getPdfObject(r.getNumber());
          }
          n = (PdfName)l.get(PdfName.S);
          if (PdfName.LAUNCH.equals(n)) {
            if (l.get(PdfName.F) != null) {
              System.out.println("Removed: " + l.get(PdfName.F));
View Full Code Here

     * @param progressbar PageProgressDialog
     */
    public AnalyzePDF(String infile, PageProgressDialog progressbar) {
    this.progressdialog = progressbar;
    try {
      reader = new PdfReader(infile);
      root = new ObjectTreeNode("Document");
      filenode = new FileTreeNode(infile, reader);
      root.add(filenode);
    } catch (IOException ex) {
    }
View Full Code Here

     * @param file File
     */
    public void createTextFromPDF(File file) {
    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() + "*"
            + reader.getCropBox(page).width() + "<p>");
        sb.append("PDF Version: " + reader.getPdfVersion() + "<p>");
        sb.append("Number of pages: " + reader.getNumberOfPages()
            + "<p>");
        sb.append("Number of PDF objects: " + reader.getXrefSize()
            + "<p>");
        sb.append("File length: " + reader.getFileLength() + "<p>");
        sb.append("Encrypted= " + reader.isEncrypted() + "<p>");
        if (pdfinfo.get("Title") != null) {
          sb.append("Title= " + pdfinfo.get("Title") + "<p>");
        }
        if (pdfinfo.get("Author") != null) {
          sb.append("Author= " + pdfinfo.get("Author") + "<p>");
View Full Code Here

            ArrayList master = new ArrayList();
            Document document = null;
            PdfCopy  writer = null;
            for (int i = 0; i < 2; i++) {
              // we create a reader for a certain document
                PdfReader reader = new PdfReader(files[i]);
                reader.consolidateNamedDestinations();
                // we retrieve the total number of pages
                int n = reader.getNumberOfPages();
                List bookmarks = SimpleBookmark.getBookmark(reader);
                if (bookmarks != null) {
                    if (pageOffset != 0)
                        SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null);
                    master.addAll(bookmarks);
                }
                pageOffset += n;
                System.out.println("There are " + n + " pages in " + files[i]);
                if (i == 0) {
                    // step 1: creation of a document-object
                    document = new Document(reader.getPageSizeWithRotation(1));
                    // step 2: we create a writer that listens to the document
                    writer = new PdfCopy(document, new FileOutputStream(pdf_file));
                    // step 3: we open the document
                    document.open();
                }
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.