[ 
https://issues.apache.org/jira/browse/PDFBOX-2087?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tilman Hausherr updated PDFBOX-2087:
------------------------------------
    Attachment: PDFBOX2087.java

> Using the LayerUtil on Documents which contains empty pages, results in an 
> NullPointer exception.
> -------------------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-2087
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2087
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 1.8.2
>         Environment: •        Win7
> •     C#, VS2010
> •     Pdfbox-1.8.2 (current release available via nu-get)
>            Reporter: Stefan Schubert
>            Priority: Minor
>         Attachments: PDFBOX2087.java
>
>
> First: Thanks a lot for maintaining PDFBox, it’s really great and helped us a 
> lot in our project!
> h4. Business-Context:
> I have to apply stationery paper to a document while considering an exclusion 
> list. I.e. on some pages the stationery paper
> is not to be applied.
> h4. Code-Sniplet (Which Leads to the NPE):
> {code:none}
> // preparing a new document containing the stationery paper and pages without 
> it
>             _targetDocument = new PDDocument();
>             var emptyPage = new PDPage();
>             emptyPage.setMediaBox(PDPage.PAGE_SIZE_A4);
> …..
>             for (int i = 1; i <= destinationPageCount; i++)
>             {
>                 if (_exclusionPages.Contains(i))
>                 {
>                     _targetDocument.importPage(emptyPage);
>                 }
>                 else 
>                 {
>                     _targetDocument.importPagestationeryPage);
>                 }
>             }          
> // now adding the original documents text via layer Util like this
>         /// <summary>
>         /// Create a document with the stationery paper in the background 
>         /// and the text as a layer in the foreground.
>         /// </summary>
>         private void AddDocumentPagesAsLayerToTargetDocument()
>         {
>             LayerUtility layerUtil = new LayerUtility(_targetDocument);
>             var transform = new AffineTransform();
>             var backgroundPages = 
> _targetDocument.getDocumentCatalog().getAllPages();
>             for (int pageIndex = 0; pageIndex < backgroundPages.size(); 
> pageIndex++)
>             {
>                 PDXObjectForm textPdfPageAsForm = 
> layerUtil.importPageAsForm(_pdfDocument, pageIndex);
>                 PDPage targetPage = (PDPage)backgroundPages.get(pageIndex);
>                 layerUtil.appendFormAsLayer(targetPage, textPdfPageAsForm, 
> transform, String.Format("ContentPage_{0:000}", pageIndex));    
>             }
>         }
> {code}
> h4. Current-Workaround:
> Creating a content stream on the empty page and printing something invisible 
> on it.
> Once again thanks a lot for maintaining PDFBox.
> Best greetings from Cologne/Germany
> Stefan Schubert



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to