I am trying to merge two Tagged PDF's with the iTextPDF 5.4.4 version jar. After doing all the operations while closing the document on the line: document.close();): . It throws the below error

```
java.lang.NullPointerException
PDF Creation Failed java.lang.NullPointerException
[B@1d5c1d5c
at com.itextpdf.text.pdf.PdfCopy.fixTaggedStructure(PdfCopy.java:878)
at com.itextpdf.text.pdf.PdfCopy.flushTaggedObjects(PdfCopy.java:799)
at com.itextpdf.text.pdf.PdfDocument.close(PdfDocument.java:836)
at com.itextpdf.text.Document.close(Document.java:416)
at PDFMerger.mergePDF(PDFMerger.java:189)

```

Please let me know what could be the cause of this issue.

Below is the code I use.

```
PdfReader reader = new PdfReader(pdf);

boolean setTagged=reader.isTagged() ; 

Document document = new Document();

PdfCopy copy = new PdfCopy(document, new FileOutputStream("Merged.pdf"));

copy.setTagged();

document.open();

int n;
n = reader.getNumberOfPages();
for (int page = 0; page < n; ) {

    copy.addPage(copy.getImportedPage(reader, ++page,true));

}
copy.freeReader(reader);
document.close();
reader.close();

```