Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 5.0.0 beta1
    • Fix Version/s: 5.0
    • Component/s: Core/Parsing
    • Labels:
      None
    • Environment:
      PRO

      Description

      Update the IncrementalUpdater class to output all changed objects in the StateManager. The output format will be generic byte[][] where each element is a changed object and the respective byte stream. The byte streams could then be serialized and read back as PDF objects using the Parser class.

        Activity

        Patrick Corless made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Repository Revision Date User Message
        ICEsoft Public SVN Repository #34188 Tue Apr 02 10:28:16 MDT 2013 patrick.corless PDF-548 addition of new method getUpdatedDocumentObjects() which returnes the raw bytes of the updted PDF objects. Each array entry represents one PDF objects byte[]'s.
        Files Changed
        Commit graph MODIFY /icepdf/trunk/icepdf/core/src/org/icepdf/core/pobjects/StateManager.java
        Patrick Corless made changes -
        Fix Version/s 5.0 [ 10314 ]
        Patrick Corless made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Patrick Corless added a comment -

        Added a new method to IncrementalUpdater which will write each PDF object's byte's to an byte[]. The method getUpdatedDocumentObjects() can be used to write out the changed PDF objects made by the most recent PDF edits.

        The following code is n example of how to read the bytes back into the same PDF file.

        try {
        // get the updated bites
        byte[][] updates = IncrementalUpdater.getUpdatedDocumentObjects(document);
        // write the bytes to file
        FileOutputStream fileOutputStream = new FileOutputStream("changes.txt");
        for (byte[] update : updates)

        { fileOutputStream.write(update); }

        fileOutputStream.close();
        controller.closeDocument();

        // read the changes back into the document.
        controller.openDocument(filePath);

        FileInputStream fileInputStream = new FileInputStream("changes.txt");

        Library library = document.getCatalog().getLibrary();
        Parser parser = new Parser(fileInputStream);
        // keep a hard reference to the objects
        ArrayList<Object> libraryObjects = new ArrayList<Object>();
        for (Object streamObject = parser.getObject(library);
        streamObject != null; streamObject = parser.getObject(library))

        { libraryObjects.add(streamObject); }

        // iterate over the stream objects look for pages so we know which
        // annotations should be added to which page.
        pageComponents =
        controller.getDocumentViewController()
        .getDocumentViewModel().getPageComponents();
        myAnnotationCallback = new org.icepdf.ri.common.MyAnnotationCallback(
        controller.getDocumentViewController());
        for (Object objects : libraryObjects){
        if (objects instanceof PObject &&
        ((PObject)objects).getObject() instanceof Page){
        Page page = (Page)((PObject)objects).getObject() ;
        page.init();
        int pageNumber = document.getPageTree().getPageNumber(page.getPObjectReference());
        AbstractPageViewComponent pageViewComponent = pageComponents.get(pageNumber);

        // add our new page to the library
        List<Annotation> annotations = page.getAnnotations();
        // hook up the new annotations
        for (Annotation annotation : annotations)

        { AnnotationComponent annotationComponent = AnnotationComponentFactory.buildAnnotationComponent( annotation, controller.getDocumentViewController(), pageViewComponent, controller.getDocumentViewController().getDocumentViewModel()); myAnnotationCallback.newAnnotation(pageViewComponent, annotationComponent); }

        pageViewComponent.init();
        }
        }

        } catch (IOException e)

        { e.printStackTrace(); } catch (PDFException e) { e.printStackTrace(); }
        Show
        Patrick Corless added a comment - Added a new method to IncrementalUpdater which will write each PDF object's byte's to an byte[]. The method getUpdatedDocumentObjects() can be used to write out the changed PDF objects made by the most recent PDF edits. The following code is n example of how to read the bytes back into the same PDF file. try { // get the updated bites byte[][] updates = IncrementalUpdater.getUpdatedDocumentObjects(document); // write the bytes to file FileOutputStream fileOutputStream = new FileOutputStream("changes.txt"); for (byte[] update : updates) { fileOutputStream.write(update); } fileOutputStream.close(); controller.closeDocument(); // read the changes back into the document. controller.openDocument(filePath); FileInputStream fileInputStream = new FileInputStream("changes.txt"); Library library = document.getCatalog().getLibrary(); Parser parser = new Parser(fileInputStream); // keep a hard reference to the objects ArrayList<Object> libraryObjects = new ArrayList<Object>(); for (Object streamObject = parser.getObject(library); streamObject != null; streamObject = parser.getObject(library)) { libraryObjects.add(streamObject); } // iterate over the stream objects look for pages so we know which // annotations should be added to which page. pageComponents = controller.getDocumentViewController() .getDocumentViewModel().getPageComponents(); myAnnotationCallback = new org.icepdf.ri.common.MyAnnotationCallback( controller.getDocumentViewController()); for (Object objects : libraryObjects){ if (objects instanceof PObject && ((PObject)objects).getObject() instanceof Page){ Page page = (Page)((PObject)objects).getObject() ; page.init(); int pageNumber = document.getPageTree().getPageNumber(page.getPObjectReference()); AbstractPageViewComponent pageViewComponent = pageComponents.get(pageNumber); // add our new page to the library List<Annotation> annotations = page.getAnnotations(); // hook up the new annotations for (Annotation annotation : annotations) { AnnotationComponent annotationComponent = AnnotationComponentFactory.buildAnnotationComponent( annotation, controller.getDocumentViewController(), pageViewComponent, controller.getDocumentViewController().getDocumentViewModel()); myAnnotationCallback.newAnnotation(pageViewComponent, annotationComponent); } pageViewComponent.init(); } } } catch (IOException e) { e.printStackTrace(); } catch (PDFException e) { e.printStackTrace(); }
        Patrick Corless created issue -

          People

          • Assignee:
            Patrick Corless
            Reporter:
            Patrick Corless
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: