I have a web form that appends several PDF fils, fills in form elements, and outputs a PDF using MergeDocument.DrawToWeb()
I am trying to create another web form that makes a WebRequest to this form, reads into a MemoryStream, creates a new PDFDocument from this stream, and appends that to a new MergeDocument, which will also draw to web.
The code I am using to retrieve the first document is below:
WebRequest req = WebRequest.Create(string.Format("http://{0}/Products/LTC/BuildPDF.aspx", Request.Url.Host));
WebResponse resp = req.GetResponse();
Stream str = resp.GetResponseStream();
System.IO.MemoryStream ms = new MemoryStream();
WriteToStream(str, ms, resp.ContentLength);
PdfDocument originalDoc = new PdfDocument(ms);
document = new MergeDocument();
document.DrawToWeb();
I am getting this error at "PdfDocument originalDoc = new PdfDocument(ms);":
"ceTe.DynamicPDF.Merger.MergerException: Invalid PDF File. Cross-Reference not found."
Is there anyway to include this 'Cross-Reference' through DynamicPDF? Or tell the PDFDocument constructor to ignore it?
Open PDF from .aspx stream
Re: Open PDF from .aspx stream
Support · Jul 26, 2007Hello,
You will need to move the MemoryStream back to the beginning before using it in the PdfDocument object. That is likely the cause of the error:
[C# Code]
WebResponse resp = req.GetResponse();
Stream str = resp.GetResponseStream();
System.IO.MemoryStream ms = new MemoryStream();
WriteToStream(str, ms, resp.ContentLength);
ms.Seek(0, SeekOrigin.Begin); // <-- Add this line here
PdfDocument originalDoc = new PdfDocument(ms);
document = new MergeDocument();
document.DrawToWeb();
Thanks,
ceTe Software Support Team
Re: Open PDF from .aspx stream
Forum member · Jul 26, 2007Yep, working now. Thanks for you help.