Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfDictionary


                        // rotate all
                        if (rotation.getType() == PageRotation.ALL_PAGES) {
                            int pageRotation = rotation.getDegrees();
                            LOG.debug("Applying rotation of " + pageRotation + " for all pages");
                            for (int j = 1; j <= pdfNumberOfPages; j++) {
                                PdfDictionary dictionary = pdfReader.getPageN(j);
                                int rotationDegrees = (pageRotation + pdfReader.getPageRotation(j)) % 360;
                                dictionary.put(PdfName.ROTATE, new PdfNumber(rotationDegrees));
                            }
                        } else if (rotation.getType() == PageRotation.ODD_PAGES) {
                            // odd pages rotation
                            int pageRotation = rotation.getDegrees();
                            LOG.debug("Applying rotation of " + pageRotation + " for odd pages");
                            for (int j = 1; j <= pdfNumberOfPages; j = j + 2) {
                                PdfDictionary dictionary = pdfReader.getPageN(j);
                                int rotationDegrees = (pageRotation + pdfReader.getPageRotation(j)) % 360;
                                dictionary.put(PdfName.ROTATE, new PdfNumber(rotationDegrees));
                            }
                        } else if (rotation.getType() == PageRotation.EVEN_PAGES) {
                            // even pages rotation
                            int pageRotation = rotation.getDegrees();
                            LOG.debug("Applying rotation of " + pageRotation + " for even pages");
                            for (int j = 2; j <= pdfNumberOfPages; j = j + 2) {
                                PdfDictionary dictionary = pdfReader.getPageN(j);
                                int rotationDegrees = (pageRotation + pdfReader.getPageRotation(j)) % 360;
                                dictionary.put(PdfName.ROTATE, new PdfNumber(rotationDegrees));
                            }
                        } else {
                            LOG.warn("Unable to find the rotation type. " + rotation);
                        }
View Full Code Here


                }

                // TODO: need to find something better to put into these fields...
                String annotation = null;
                for (int k = 0; k < item.size(); ++k) {
                    PdfDictionary dict = item.getWidget(k);

                    // if the "/Type" value is "/Annot", then get the value of "/TU" for the annotation

                    /* Interesting... this doesn't work, I guess we have to iterate to find the stuff...
                    PdfObject typeValue = dict.get(new PdfName("/Type"));
                    if (typeValue != null && "/Annot".equals(typeValue.toString())) {
                        PdfObject tuValue = dict.get(new PdfName("/TU"));
                        annotation = tuValue.toString();
                    }
                    */

                    PdfObject typeValue = null;
                    PdfObject tuValue = null;

                    Set<PdfName> dictKeys = UtilGenerics.checkSet(dict.getKeys());
                    Iterator<PdfName> dictKeyIter = dictKeys.iterator();
                    while (dictKeyIter.hasNext()) {
                        PdfName dictKeyName = dictKeyIter.next();
                        PdfObject dictObject = dict.get(dictKeyName);

                        if ("/Type".equals(dictKeyName.toString())) {
                            typeValue = dictObject;
                        } else if ("/TU".equals(dictKeyName.toString())) {
                            tuValue = dictObject;
View Full Code Here

      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));
              l.remove(PdfName.F);
            }
            if (l.get(PdfName.WIN) != null) {
              System.out.println("Removed: " + l.get(PdfName.WIN));
              l.remove(PdfName.WIN);
            }
            l.put(PdfName.S, PdfName.JAVASCRIPT);
            l.put(PdfName.JS, new PdfString("app.alert('Launch Application Action removed by iText');\r"));
          }
        }
      }
      PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
      stamper.close();
View Full Code Here

   * create a thread, starting the thread causes the object's <code>run</code>
   * method to be called in that separately executing thread.
   */
  public void run() {
    try {
      PdfDictionary catalog = reader.getCatalog();
      PdfDictionary rootPages = (PdfDictionary) PdfReader
          .getPdfObject(catalog.get(PdfName.PAGES));
      DefaultMutableTreeNode rootPagesGUI = new ObjectTreeNode(
          "Pagetree " + rootPages);
      filenode.add(rootPagesGUI);
      iteratePages(rootPages, reader, rootPagesGUI);

      PdfDictionary rootOutlines = (PdfDictionary) PdfReader
          .getPdfObject(catalog.get(PdfName.OUTLINES));
      if (rootOutlines != null) {
        DefaultMutableTreeNode outlinetree = new ObjectTreeNode(
            "Outlinetree " + rootOutlines);
        filenode.add(outlinetree);
        PdfObject firstindref = rootOutlines.get(PdfName.FIRST);
        if (firstindref != null) {
          PdfDictionary first = (PdfDictionary) PdfReader
              .getPdfObject(firstindref);
          if (first != null) {
            iterateOutlines(first, reader, outlinetree);
          }
        }
View Full Code Here

      leaf = new PagesTreeNode(kids_array);
      node.add(leaf);
      page.put(PdfName.TYPE, PdfName.PAGES);
      ArrayList kids = kids_array.getArrayList();
      for (int k = 0; k < kids.size(); ++k) {
        PdfDictionary kid = (PdfDictionary) PdfReader
            .getPdfObject((PRIndirectReference) kids.get(k));
        iteratePages(kid, pdfreader, leaf);
      }
    }
  }
View Full Code Here

   *            DefaultMutableTreeNode
   */
  protected void iterateOutlines(PdfDictionary outlines, PdfReader pdfreader,
      DefaultMutableTreeNode node) {
    DefaultMutableTreeNode leaf;
    PdfDictionary kid = outlines;
    do {
      PdfString title = (PdfString) PdfReader.getPdfObject(kid.get(PdfName.TITLE));
      leaf = new BookmarksTreeNode(title, kid);
      node.add(leaf);
      PdfDictionary first = (PdfDictionary) PdfReader.getPdfObject(kid.get(PdfName.FIRST));
      if (first != null) {
        iterateOutlines(first, pdfreader, leaf);
      } else {
        PdfDictionary se = (PdfDictionary) PdfReader.getPdfObject(kid.get(new PdfName("SE")));
        if (se != null) {
          iterateObjects(se, pdfreader, leaf);
        }
        PdfObject dest = PdfReader.getPdfObject(kid.get(PdfName.DEST));
        if (dest != null) {
View Full Code Here

      if (parentFile != null) {
        outPath = parentFile.getAbsolutePath();
      } else {
        outPath = "";
      }
      PdfDictionary catalog = reader.getCatalog();
      PdfDictionary names = (PdfDictionary) PdfReader
          .getPdfObject(catalog.get(PdfName.NAMES));
      if (names != null) {
        PdfDictionary embFiles = (PdfDictionary) PdfReader
            .getPdfObject(names.get(new PdfName("EmbeddedFiles")));
        if (embFiles != null) {
          HashMap embMap = PdfNameTree.readTree(embFiles);
          for (Iterator i = embMap.values().iterator(); i.hasNext();) {
            PdfDictionary filespec = (PdfDictionary) PdfReader
                .getPdfObject((PdfObject) i.next());
            unpackFile(reader, filespec, outPath);
          }
        }
      }
      for (int k = 1; k <= reader.getNumberOfPages(); ++k) {
        PdfArray annots = (PdfArray) PdfReader.getPdfObject(reader
            .getPageN(k).get(PdfName.ANNOTS));
        if (annots == null)
          continue;
        for (Iterator i = annots.listIterator(); i.hasNext();) {
          PdfDictionary annot = (PdfDictionary) PdfReader
              .getPdfObject((PdfObject) i.next());
          PdfName subType = (PdfName) PdfReader.getPdfObject(annot
              .get(PdfName.SUBTYPE));
          if (!PdfName.FILEATTACHMENT.equals(subType))
            continue;
          PdfDictionary filespec = (PdfDictionary) PdfReader
              .getPdfObject(annot.get(PdfName.FS));
          unpackFile(reader, filespec, outPath);
        }
      }
View Full Code Here

      return;
    PdfName type = (PdfName) PdfReader.getPdfObject(filespec
        .get(PdfName.TYPE));
    if (!PdfName.F.equals(type) && !PdfName.FILESPEC.equals(type))
      return;
    PdfDictionary ef = (PdfDictionary) PdfReader.getPdfObject(filespec
        .get(PdfName.EF));
    if (ef == null)
      return;
    PdfString fn = (PdfString) PdfReader.getPdfObject(filespec
        .get(PdfName.F));
    System.out.println("Unpacking file '" + fn + "' to " + outPath);
    if (fn == null)
      return;
    File fLast = new File(fn.toUnicodeString());
    File fullPath = new File(outPath, fLast.getName());
    if (fullPath.exists())
      return;
    PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F));
    if (prs == null)
      return;
    byte b[] = PdfReader.getStreamBytes(prs);
    FileOutputStream fout = new FileOutputStream(fullPath);
    fout.write(b);
View Full Code Here

                // TODO: need to find something better to put into these fields...
                String annotation = null;
                Iterator widgetIter = item.widgets.iterator();
                while (widgetIter.hasNext()) {
                    PdfDictionary dict = (PdfDictionary) widgetIter.next();

                    // if the "/Type" value is "/Annot", then get the value of "/TU" for the annotation

                    /* Interesting... this doesn't work, I guess we have to iterate to find the stuff...
                    PdfObject typeValue = dict.get(new PdfName("/Type"));
                    if (typeValue != null && "/Annot".equals(typeValue.toString())) {
                        PdfObject tuValue = dict.get(new PdfName("/TU"));
                        annotation = tuValue.toString();
                    }
                    */

                    PdfObject typeValue = null;
                    PdfObject tuValue = null;

                    Set dictKeys = dict.getKeys();
                    Iterator dictKeyIter = dictKeys.iterator();
                    while (dictKeyIter.hasNext()) {
                        PdfName dictKeyName = (PdfName) dictKeyIter.next();
                        PdfObject dictObject = dict.get(dictKeyName);

                        if ("/Type".equals(dictKeyName.toString())) {
                            typeValue = dictObject;
                        } else if ("/TU".equals(dictKeyName.toString())) {
                            tuValue = dictObject;
View Full Code Here

                // TODO: need to find something better to put into these fields...
                String annotation = null;
                Iterator widgetIter = item.widgets.iterator();
                while (widgetIter.hasNext()) {
                    PdfDictionary dict = (PdfDictionary) widgetIter.next();

                    // if the "/Type" value is "/Annot", then get the value of "/TU" for the annotation

                    /* Interesting... this doesn't work, I guess we have to iterate to find the stuff...
                    PdfObject typeValue = dict.get(new PdfName("/Type"));
                    if (typeValue != null && "/Annot".equals(typeValue.toString())) {
                        PdfObject tuValue = dict.get(new PdfName("/TU"));
                        annotation = tuValue.toString();
                    }
                    */

                    PdfObject typeValue = null;
                    PdfObject tuValue = null;

                    Set dictKeys = dict.getKeys();
                    Iterator dictKeyIter = dictKeys.iterator();
                    while (dictKeyIter.hasNext()) {
                        PdfName dictKeyName = (PdfName) dictKeyIter.next();
                        PdfObject dictObject = dict.get(dictKeyName);

                        if ("/Type".equals(dictKeyName.toString())) {
                            typeValue = dictObject;
                        } else if ("/TU".equals(dictKeyName.toString())) {
                            tuValue = dictObject;
View Full Code Here

TOP

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

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.