Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfReader


         LwgDocument 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<HashMap<String, Object>> 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 LwgDocument(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


   */
  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<HashMap<String, Object>> 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 = catalog.getAsDict(PdfName.NAMES);
      if (names != null) {
        PdfDictionary embFiles = names.getAsDict(new PdfName("EmbeddedFiles"));
        if (embFiles != null) {
            HashMap<String, PdfObject> embMap = PdfNameTree.readTree(embFiles);
          for (Iterator<PdfObject> i = embMap.values().iterator(); i.hasNext();) {
            PdfDictionary filespec = (PdfDictionary) PdfReader
                .getPdfObject(i.next());
            unpackFile(reader, filespec, outPath);
          }
        }
      }
      for (int k = 1; k <= reader.getNumberOfPages(); ++k) {
        PdfArray annots = reader.getPageN(k).getAsArray(PdfName.ANNOTS);
        if (annots == null)
          continue;
        for (Iterator<PdfObject> i = annots.listIterator(); i.hasNext();) {
          PdfDictionary annot = (PdfDictionary) PdfReader
              .getPdfObject(i.next());
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) {
        LwgDocument.compress = compress;
        int total = reader.getNumberOfPages() + 1;
        for (int i = 1; i < total; i++) {
          reader.setPageContent(i, reader.getPageContent(i));
        }
        stamper.close();
        LwgDocument.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<HashMap<String, Object>> 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

  /**
   * RowContainer
   */
  RowContainer(File file) {
    this.file = file;
    PdfReader reader = null;
    try {
      reader = new PdfReader(file.
                             getAbsolutePath());
    }
    catch (IOException ex) {
    }
    this.pages = reader.getNumberOfPages();
  }
View Full Code Here

   */
  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");
      LwgDocument document = new LwgDocument();
      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

     * @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<String, String> pdfinfo = reader.getInfo();

        StringBuffer sb = new StringBuffer();
        sb.append("<html>=== Document Information ===<p>");
        sb.append(reader.getCropBox(page).getHeight() + "*"
            + reader.getCropBox(page).getWidth() + "<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

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.