multiple splits

multiple splits

Forum member · Jun 13, 2012
Hi! I'm trying out the eval version for what may be professional interest. Our requirement is to be able to split a pdf document multiple times, which after playing with you library seems to work fine, except you can't perform it multiple times. I get Cross-reference table not found on the second permutation. Am I doing this wrong, or is this not supported? Code: public byte[] Split(byte[] pdf) { MergeDocument md = new MergeDocument(new PdfDocument(pdf), start,2); MemoryStream ms1 = new MemoryStream(); md.Draw(ms1); byte[] data = ms1.GetBuffer() return data; } public void Elsewhere() { byte[] firstIteration = Split(File.ReadAllByte("test.pdf")); //crashes here byte[] secondIteration = Split(firstIteration); } ceTe.DynamicPDF.Merger.PdfParsingException: Invalid PDF File. Cross-reference table not found. at ceTe.DynamicPDF.Merger.PdfDocument.e() at ceTe.DynamicPDF.Merger.PdfDocument..ctor(f9 A_0, String A_1) at ceTe.DynamicPDF.Merger.PdfDocument..ctor(Stream stream, String password) at ceTe.DynamicPDF.Merger.PdfDocument..ctor(Byte[] data) at PDFTools.PdfService.SplitPdf(Byte[] pdf, Int32 start, Int32 end) in C:\Users\demartin\Documents\Visual Studio 2010\Projects\PDFTools\PDFTools\PdfService.asmx.cs:line 58 at PDFTools.PdfService.test() in C:\Users\demartin\Documents\Visual Studio 2010\Projects\PDFTools\PDFTools\PdfService.asmx.cs:line 78

Re: multiple splits

Support · Jun 14, 2012
Hello, You can output the merged document in the form of byte array using Draw method of MergeDocument class. Try outputting the document to byte array instead of memory stream and this will work for you. Below is the sample code for it. public static byte[] Split(byte[] pdf) { int start = 1; PdfDocument pdfDoc = new PdfDocument(pdf); MergeDocument md = new MergeDocument(pdfDoc,start,2); byte[] data = md.Draw(); return data; } public static void Elsewhere() { byte[] firstIteration = Split(File.ReadAllBytes(@"F:\temporary\DocumentD.pdf")); byte[] secondIteration = Split(firstIteration); } Thanks, ceTe Software Support Team.