You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Stefan Schubert (JIRA)" <ji...@apache.org> on 2014/05/21 21:26:38 UTC

[jira] [Created] (PDFBOX-2087) Using the LayerUtil on Documents which contains empty pages, results in an NullPointer exception.

Stefan Schubert created PDFBOX-2087:
---------------------------------------

             Summary: 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


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
(v6.2#6252)