Unplanned
Last Updated: 11 Oct 2021 15:18 by ADMIN
Robby
Created on: 11 Oct 2021 15:07
Category: ZipLibrary
Type: Bug Report
0
ZipLibrary: Writing content into a ZipArchiveEntry using the PdfStreamWriter leads to a wrong offset of the xref table and the objects in it
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());


0 comments