You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Haris Javaid <Ha...@thoughtcorp.com> on 2011/12/09 18:39:11 UTC

Need help with Overlay for Layout pages

Hello there,
We are working on a product that supports highlighting PDF documents. We recently came across a situation where when trying to highlight  a pdf that was converted into a PDF from word by some third part library, threw UnsupportedOperationException. It happened in Overlay.java.

private void collectLayoutPages( List pages) throws IOException
    {
        Iterator pagesIter = pages.iterator();
        while( pagesIter.hasNext() )
        {
            PDPage page = (PDPage)pagesIter.next();
            COSBase contents = page.getCOSDictionary().getDictionaryObject( COSName.CONTENTS );
            PDResources resources = page.findResources();
            if( resources == null )
            {
                resources = new PDResources();
                page.setResources( resources );
            }
            COSDictionary res = resources.getCOSDictionary();

            if( contents instanceof COSStream )
            {
                COSStream stream = (COSStream) contents;
                Map objectNameMap = new TreeMap();
                stream = makeUniqObjectNames(objectNameMap, stream);

                layoutPages.add(new LayoutPage(stream, res, objectNameMap));
            }
            else if( contents instanceof COSArray )
            {
                throw new UnsupportedOperationException("Layout pages with COSArray currently not supported.");
                // layoutPages.add(new LayoutPage(contents, res));
            }
            else
            {
                throw new IOException( "Contents are unknown type:" + contents.getClass().getName() );
            }
        }
    }

Below is the exception:


ava.lang.UnsupportedOperationException: Layout pages with COSArray currently not supported.

      at org.apache.pdfbox.Overlay.collectLayoutPages(Overlay.java:269)

      at org.apache.pdfbox.Overlay.overlay(Overlay.java:224)

      at com.thoughtcorp.annotation.AnnotatedFile.applyAnnotationsToPDF(AnnotatedFile.java:54)

      at com.thoughtcorp.services.SyncAnnotationsService.syncAnnotations(SyncAnnotationsService.java:26)

      at com.thoughtcorp.SyncRequestHandler.handle(SyncRequestHandler.java:60)

      at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:47)

      at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)

      at org.eclipse.jetty.server.Server.handle(Server.java:346)

      at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)

      at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1065)

      at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:823)

      at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:220)

      at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)

      at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)

      at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)

      at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)

      at java.lang.Thread.run(Thread.java:662)

Can you please ask the developer who worked on the code highlighted above was it not implemented coz it required a lot of work or was it coz he thought the functionality would not be required by many people? We were thinking if we could just implement LayoutPage.java to take in COSArray and operate on it. Would it be too hard to implement to support our solution? Another approach was to convert COSArray into COSStream so the code always catches if block.

We are currently trying to meet a deadline and this has become a road blocker for us. Any help in this matter would be really appreciated!

Thanks,

Haris