Writing content into a
ZipArchiveEntry using the
PdfStreamWriter leads to a wrong offset of the xref table and the objects in it:
MemoryStream ms1 = new MemoryStream();
using (ZipArchive archive = new ZipArchive(ms1, ZipArchiveMode.Create, false, null))
{
using (PdfFileSource fileSource = new PdfFileSource(File.OpenRead(documentToSplit)))
{
string splitDocumentName = "1st page.pdf";
using (ZipArchiveEntry entry = archive.CreateEntry(splitDocumentName))
{
using (PdfStreamWriter writer = new PdfStreamWriter(entry.Open()))
{
PdfPageSource page = fileSource.Pages[0];
writer.WritePage(page);
}
}
}
}
File.WriteAllBytes("exported.zip", ms1.ToArray());