Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfReader


   */
  public void execute() {
    try {
      if (getValue("xmlfile") == null) throw new InstantiationException("You need to choose an xml file");
      if (getValue("pdffile") == null) throw new InstantiationException("You need to choose a source PDF file");
      PdfReader reader = new PdfReader(((File)getValue("pdffile")).getAbsolutePath());
            reader.consolidateNamedDestinations();
            List bookmarks = SimpleBookmark.getBookmark( reader );
            // save them in XML format
            FileOutputStream bmWriter = new FileOutputStream( (File)getValue("xmlfile") );
            SimpleBookmark.exportToXML(bookmarks, bmWriter, "UTF-8", false);
            bmWriter.close();
View Full Code Here


        throw new InstantiationException(
            "You need to choose a sourcefile");
      EventDispatchingThread task = new EventDispatchingThread() {
        public Object construct() {
          try {
            PdfReader reader = new PdfReader(
                ((File) getValue("srcfile")).getAbsolutePath());
            for (int i = 0; i < reader.getXrefSize(); i++) {
              PdfObject pdfobj = reader.getPdfObject(i);
              if (pdfobj != null) {
                if (pdfobj.isStream()) {
                  PdfStream pdfdict = (PdfStream) pdfobj;
                  PdfObject pdfsubtype = pdfdict
                      .get(PdfName.SUBTYPE);
View Full Code Here

      if (getValue("destfile") == null) throw new InstantiationException("You need to choose a destination file");
      byte[] ownerpassword = null;
      if (getValue("ownerpassword") != null) {
        ownerpassword = ((String)getValue("ownerpassword")).getBytes();
      }
      PdfReader reader = new PdfReader(((File)getValue("srcfile")).getAbsolutePath(), ownerpassword);
      PdfStamper stamper = new PdfStamper(reader, new FileOutputStream((File)getValue("destfile")));
      stamper.close();
    }
    catch(Exception e) {
          JOptionPane.showMessageDialog(internalFrame,
View Full Code Here

        throw new InstantiationException(
            "You need to choose a sourcefile");
      File src = (File) getValue("srcfile");

      // we create a reader for a certain document
      PdfReader reader = new PdfReader(src.getAbsolutePath());
      final File parentFile = src.getParentFile();
      final String outPath;
      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
View Full Code Here

  public void execute() {
    try {
      if (getValue("srcfile") == null) throw new InstantiationException("You need to choose a sourcefile");
      if (getValue("destfile") == null) throw new InstantiationException("You need to choose a destination file");
      boolean compress = "true".equals(getValue("compress"));
      PdfReader reader = new PdfReader(((File)getValue("srcfile")).getAbsolutePath());
      PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(getDestPathPDF()));
      synchronized(arguments) {
        Document.compress = compress;
        int total = reader.getNumberOfPages() + 1;
        for (int i = 1; i < total; i++) {
          reader.setPageContent(i, reader.getPageContent(i));
        }
        stamper.close();
        Document.compress = true;
      }
    }
View Full Code Here

      if (getValue("pdffile") == null) throw new InstantiationException("You need to choose a source PDF file");
      if (getValue("destfile") == null) throw new InstantiationException("You need to choose a destination PDF file");
            FileInputStream bmReader = new FileInputStream( (File) getValue("xmlfile") );
            List bookmarks = SimpleBookmark.importFromXML( bmReader );
            bmReader.close();
            PdfReader reader = new PdfReader(((File)getValue("pdffile")).getAbsolutePath());
            reader.consolidateNamedDestinations();
            PdfStamper stamper = new PdfStamper(reader, new FileOutputStream((File)getValue("destfile")));
            stamper.setOutlines(bookmarks);
            stamper.setViewerPreferences(reader.getSimpleViewerPreferences() | PdfWriter.PageModeUseOutlines);
            stamper.close();
    }
    catch(Exception e) {
      e.printStackTrace();
          JOptionPane.showMessageDialog(internalFrame,
View Full Code Here

      }
      int fontsize = Integer.parseInt( (String) getValue("fontsize"));
      float opacity = Float.parseFloat( (String) getValue("opacity"));
      BaseFont bf = BaseFont.createFont("Helvetica", BaseFont.WINANSI,
                                        false);
      PdfReader reader = new PdfReader( ( (File) getValue("srcfile"))
                                       .getAbsolutePath());
      int pagecount = reader.getNumberOfPages();
      PdfGState gs1 = new PdfGState();
      gs1.setFillOpacity(opacity);
      String text = (String) getValue("watermark");
      PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(
          (File) getValue("destfile")));
      float txtwidth = bf.getWidthPoint(text, fontsize);
      for (int i = 1; i <= pagecount; i++) {
        PdfContentByte seitex = stamp.getOverContent(i);
        Rectangle recc = reader.getCropBox(i);
        float winkel = (float) Math.atan(recc.height() / recc.width());
        float m1 = (float) Math.cos(winkel);
        float m2 = (float) - Math.sin(winkel);
        float m3 = (float) Math.sin(winkel);
        float m4 = (float) Math.cos(winkel);
View Full Code Here

        y1[i] = y2[i - 1] - 20f;
        y2[i] = y1[i] - height;
      }

      // 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.");

      // step 1: creation of a document-object
      Document document = new Document(PageSize.A4);
      // 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();
      PdfContentByte cb = writer.getDirectContent();
      PdfImportedPage page;
      int rotation;
      int i = 0;
      int p = 0;
      // step 4: we add content
      while (i < n) {
        i++;
        Rectangle rect = reader.getPageSizeWithRotation(i);
        float factorx = (x2 - x1) / rect.width();
        float factory = (y1[p] - y2[p]) / rect.height();
        float factor = (factorx < factory ? factorx : factory);
        float dx = (factorx == factor ? 0f : ((x2 - x1) - rect.width() * factor) / 2f);
        float dy = (factory == factor ? 0f : ((y1[p] - y2[p]) - rect.height() * factor) / 2f);
        page = writer.getImportedPage(reader, i);
        rotation = reader.getPageRotation(i);
        if (rotation == 90 || rotation == 270) {
          cb.addTemplate(page, 0, -factor, factor, 0, x1 + dx, y2[p] + dy + rect.height() * factor);
        }
        else {
          cb.addTemplate(page, factor, 0, 0, factor, x1 + dx, y2[p] + dy);
View Full Code Here

          if (getValue("destfile") == null) throw new InstantiationException("You need to choose a destination file for the first part of the PDF");
          File dest = (File)getValue("destfile");
          String selection = (String)getValue("selection");

          // we create a reader for a certain document
      PdfReader reader = new PdfReader(src.getAbsolutePath());
      System.out.println("The original file had " + reader.getNumberOfPages() + " pages.");
      reader.selectPages(selection);
      int pages = reader.getNumberOfPages();
      System.err.println("The new file has " + pages + " pages.");
      Document document = new Document(reader.getPageSizeWithRotation(1));
      PdfCopy copy = new PdfCopy(document, new FileOutputStream(dest.getAbsolutePath()));
      document.open();
            PdfImportedPage page;
            for (int i = 0; i < pages; ) {
                ++i;
                System.out.println("Processed page " + i);
                page = copy.getImportedPage(reader, i);
                copy.addPage(page);
            }
            PRAcroForm form = reader.getAcroForm();
      if (form != null)
                copy.copyAcroForm(reader);
      document.close();
        }
        catch(Exception e) {
View Full Code Here

     * @throws Exception
     */
    private void executeBurst(SplitParsedCommand inputCommand) throws Exception {
        int currentPage;
        Document currentDocument;
        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()),
                inputCommand.getInputFile().getPasswordBytes());
        pdfReader.removeUnusedObjects();
        pdfReader.consolidateNamedDestinations();

        // we retrieve the total number of pages
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.