Hello,
Thanks a lot for the replay.
Yes, my bad, I should include appendPDF method from the beginning.
Here is the code :
private static final void appendPDF( final PdfCopy target, final PdfReader
source )
throws BadPdfFormatException, IOException
{
final int pages = source.getNumberOfPages();
for ( int i = 1; i <= pages; i++ )
{
target.addPage( target.getImportedPage( source, i ) );
}
}
Thank you,
Alexandre Pichtchikov
From: iText mailing list [mailto:i...@1t3xt.info]
Sent: Thursday, August 07, 2014 10:16 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] method PdfCopy.fixTaggedStructure throws
NullPointerException
On 8/6/2014 10:01 AM, Pichtchikov, Alexandre wrote:
I am merging tagged pdf with untagged pdf. I am getting exception when I close
Document object:
NullPointerException(PdfCopy.java:890)
Call stack
com.itextpdf.text.pdf.PdfCopy.fixTaggedStructure(PdfCopy.java:890)
com.itextpdf.text.pdf.PdfCopy.flushTaggedObjects(PdfCopy.java:866)
com.itextpdf.text.pdf.PdfDocument.close(PdfDocument.java:855)
com.itextpdf.text.Document.close(Document.java:416)
......
Code:
PdfReader basePDF = new PdfReader( byteArray );
PdfReader legendInformation = new PdfReader( legendsStaticPDFs.get(
language ) );
boolean isBasePDFTagged = basePDF.isTagged();
boolean islegendInformationTagged = legendInformation.isTagged();
// Representation of the resultant, merged, PDF
Document document = new Document( basePDF.getPageSize( 1 ) );
// Wrap the target PDF in something concrete to facilitate adding pages
ByteArrayOutputStream outputStreamNew = new ByteArrayOutputStream();
PdfCopy newPDF = new PdfCopy( document, outputStreamNew );
newPDF.setTagged();
// Set the PDF language (Accessibility standards)
newPDF.getExtraCatalog().put(PdfName.LANG,
new PdfString( language.locale.getLanguage() ) );
// Set the PDF document title (Accessibility standards)
newPDF.getInfo().put(PdfName.TITLE, new PdfString(
messageSourceAccessor.getMessage(
"statement.pdf.title." + language.locale.getLanguage()
) ) );
document.open();
appendPDF( newPDF, basePDF );
//appendPDF( newPDF, legendInformation );
document.close();
I checked this Merging Tagged PDF without ruining the
tags<http://stackoverflow.com/questions/19839445/merging-tagged-pdf-without-ruining-the-tags>,
and have found that it should be fixed, but it still exist at least in iText
5.5.2 I used. Is it any work around? Could PageName.PG be set manually? Thanks
in advance.
It looks like NullPointerException(PdfCopy.java:890) is generated at this line:
HashMap<Integer, PdfIndirectReference> numTree =
structureTreeRoot.getNumTree();//iText 5.5.2;PdfCopy.java:890
structureTreeRoot can be null in case the method getImportedPage(PdfReader,
int, boolean) was used without keeping tagged structure (which would be wrong
use of iText). Unfortunately, this code is hidden in your appendPDF() method so
we can't check if you're doing something wrong or if there's really a problem
inside iText.
The issue with a PG key has been fixed in iText 5.5.0.
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls.
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php