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 thro
The Code was written in C#
public static byte[] mergeTest(byte[] pdf) {
PdfReader reader = null;
Document doc = null;
PdfCopy copy = null;
MemoryStream stream = new MemoryStream();
byte[] output = null;
try {
reader = new PdfReader(pdf);
doc = new Document();
copy = new PdfCopy(doc, stream);
bool tagged = reader.IsTagged();
if (tagged)
copy.SetTagged();
doc.Open();
for (int x = 1; x <= reader.NumberOfPages; x++) {
copy.AddPage(copy.GetImportedPage(reader, x, tagged));
}
copy.FreeReader(reader);
doc.Close();
copy.Close();
output = stream.ToArray();
stream.Flush();
stream.Dispose();
} catch (Exception ex) {
} finally {
try {
if (reader != null)
reader.Close();
} catch (Exception) { }
}
return output;
}