Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfReader


     * @throws IOException
     */
    static public void listContentStream(File pdfFile) throws IOException {
        int maxPage = -1;   
       
        PdfReader reader = new PdfReader(pdfFile.getCanonicalPath());

           
            // look through the page content of each page and ensure that it does
            // not have a BT command.
            int maxPageNum = reader.getNumberOfPages();
            if (maxPage != -1)
                maxPageNum = maxPage;
           
            for (int pageNum = 1; pageNum <= maxPageNum; pageNum++){
                System.out.println("==============Page " + pageNum + "====================");
                System.out.println("- - - - - Dictionary - - - - - -");
                PdfDictionary pageDictionary = reader.getPageN(pageNum);
                System.out.println(getDictionaryDetail(pageDictionary));
                System.out.println("- - - - - Content Stream - - - - - -");
                RandomAccessFileOrArray f = reader.getSafeFile();
               
                byte[] contentBytes = reader.getPageContent(pageNum, f);
                f.close();

               
               
                InputStream is = new ByteArrayInputStream(contentBytes);
View Full Code Here


        }   
    }
   
    private void drawPDFAsImage(PDFAsImage image, int x, int y) {
        URL url = image.getURL();
        PdfReader reader = null;
       
        try {
            reader = getReader(url);
        } catch (IOException e) {
            throw new XRRuntimeException("Could not load " + url + ": " +
View Full Code Here

                (float)mx[3], (float)mx[4], (float)mx[5]);
        _currentPage.saveState();
    }
   
    public PdfReader getReader(URL url) throws IOException {
        PdfReader result = (PdfReader) _readerCache.get(url);
        if (result ==  null) {
            result = new PdfReader(url);
            _readerCache.put(url, result);
        }
        return result;
    }
View Full Code Here

  public void testSaveEncrypted() throws Exception
  {
    CountryReportSecurityXMLDemoHandler demoHandler = new CountryReportSecurityXMLDemoHandler();
    MasterReport report = demoHandler.createReport();
    byte[] b = createPDF(report);
    PdfReader reader = new PdfReader(b, DocWriter.getISOBytes("Duck"));
    assertTrue(reader.isEncrypted());
  }
View Full Code Here

    }
   
    protected static final boolean comparePdf(String inputFileName1, String inputFileName2, String outputFileName) throws Exception{   
      // Comparison Routine
      boolean equal = true;
      PdfReader reader1 = new PdfReader(inputFileName1);
      PdfReader reader2 = new PdfReader(inputFileName2);
      FileOutputStream outputStream = new FileOutputStream(outputFileName);
      if(reader1.getFileLength() != reader2.getFileLength()) {
        equal = false;
        String dataToWrite = "Files are of different length. One is "  + reader1.getFileLength() + " and the other is  " + reader2.getFileLength() + "\n";   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        outputStream.write(dataToWrite.getBytes());
      } else if(reader1.getNumberOfPages() != reader2.getNumberOfPages()) {
        equal = false;
        String dataToWrite = "Number of pages are different in both files. One has "  + reader1.getNumberOfPages() + " and the other has  " + reader2.getNumberOfPages() + "\n";   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        outputStream.write(dataToWrite.getBytes());
      } else {
        for(int i=1;i<=reader1.getNumberOfPages();i++) {
          byte[] data1 = reader1.getPageContent(i);
          byte[] data2 = reader2.getPageContent(i);
          for(int j = 0; i < data1.length; i ++) {
            if(data1[j] != data2[j]) {
              equal = false;
              String dataToWrite = "Page #" + i + "has different data. File 1 has" + data1[j] + "Whereas File 2 has " + data2[j] + "\n";   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
              outputStream.write(dataToWrite.getBytes());
            }
          }
        }
      }
      if(equal) {
        String dataToWrite = "Files are identical";//$NON-NLS-1$
        outputStream.write(dataToWrite.getBytes());
      }
      outputStream.flush();
      outputStream.close();
      reader1.close();
      reader2.close();
      return equal;
    }
View Full Code Here

  protected static boolean comparePdf(String inputFileName1, String inputFileName2, String outputFileName)
      throws Exception
  {
    // Comparison Routine
    boolean equal = true;
    PdfReader reader1 = new PdfReader(inputFileName1);
    PdfReader reader2 = new PdfReader(inputFileName2);
    FileOutputStream outputStream = new FileOutputStream(outputFileName);
/*    if (reader1.getFileLength() != reader2.getFileLength()) {
      equal = false;
      String dataToWrite = "Files are of different length. One is " + reader1.getFileLength() + " and the other is  " + reader2.getFileLength() + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      outputStream.write(dataToWrite.getBytes());
    } else */
    if (reader1.getNumberOfPages() != reader2.getNumberOfPages())
    {
      equal = false;
      String dataToWrite = "Number of pages are different in both files. One has " + reader1.getNumberOfPages() + " and the other has  " + reader2.getNumberOfPages() + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      outputStream.write(dataToWrite.getBytes());
    }
    else
    {
      for (int i = 1; i <= reader1.getNumberOfPages(); i++)
      {
        byte[] data1 = reader1.getPageContent(i);
        byte[] data2 = reader2.getPageContent(i);
        for (int j = 0; i < data1.length; i++)
        {
          if (data1[j] != data2[j])
          {
            equal = false;
            String dataToWrite = "Page #" + i + "has different data. File 1 has" + data1[j] + "Whereas File 2 has " + data2[j] + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            outputStream.write(dataToWrite.getBytes());
          }
        }
      }
    }
    if (equal)
    {
      String dataToWrite = "Files are identical";//$NON-NLS-1$
      outputStream.write(dataToWrite.getBytes());
    }
    outputStream.flush();
    outputStream.close();
    reader1.close();
    reader2.close();
    return equal;
  }
View Full Code Here

    if ((parsedCommand != null) && (parsedCommand instanceof DocumentInfoParsedCommand)) {
      DocumentInfoParsedCommand inputCommand = (DocumentInfoParsedCommand) parsedCommand;
      setPercentageOfWorkDone(0);
      try {
        File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()), inputCommand
            .getInputFile().getPasswordBytes());
        pdfReader.removeUnusedObjects();
        pdfReader.consolidateNamedDestinations();

        // version
View Full Code Here

              encType = PdfWriter.STANDARD_ENCRYPTION_128;
            }

            prefixParser = new PrefixParser(inputCommand.getOutputFilesPrefix(), fileList[i].getFile().getName());
            File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
            pdfReader = new PdfReader(new RandomAccessFileOrArray(fileList[i].getFile().getAbsolutePath()), fileList[i]
                .getPasswordBytes());
            pdfReader.removeUnusedObjects();
            pdfReader.consolidateNamedDestinations();

            // version
View Full Code Here

        }
        for(int i = 0; i<fileList.length; i++){
          try{
            prefixParser = new PrefixParser(inputCommand.getOutputFilesPrefix(), fileList[i].getFile().getName());
            File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
            pdfReader = new PdfReader(new RandomAccessFileOrArray(fileList[i].getFile().getAbsolutePath()),fileList[i].getPasswordBytes());
            pdfReader.removeUnusedObjects();
            pdfReader.consolidateNamedDestinations();
           
            //version
            LOG.debug("Creating a new document.");
View Full Code Here

                        currentPageSelection = pageSelections[i].toLowerCase();
                    }

                    String[] selectionGroups = StringUtils.split(currentPageSelection, ",");

                    pdfReader = new PdfReader(new RandomAccessFileOrArray(fileList[i].getFile().getAbsolutePath()),
                            fileList[i].getPasswordBytes());
                    pdfReader.removeUnusedObjects();
                    pdfReader.consolidateNamedDestinations();
                    int pdfNumberOfPages = pdfReader.getNumberOfPages();
                    BookmarksProcessor bookmarkProcessor = new BookmarksProcessor(SimpleBookmark.getBookmark(pdfReader), pdfNumberOfPages);
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.