create document from memory stream

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for .NET (v3 and older)  /  create document from memory stream

DynamicPDF Generator for .NET (v3 and older) Forum

 Oct 27 2005 5:36 PM
I posted this to Google Groups, and thought I'd see if anyone here had a thought...

I am using vb.net with DynamicPDF
(http://www.DynamicPDF.com/Products/GeneratorForNET/) to create one page of a two page report.  The second page (that will actually be page one in the joined document) of the report that gets returned to the browser is created using SQL reporting services.  I have a script that returns the second page as a PDF document via URL (aka http://host.here/ReportRender.aspx?parameters=here).  I can get both pages to work in a browser.

What I am trying to do is use the first script that creates a DynamicPDF document and then use the webclient or httpwebrequest/response objects to create the second page and accept it as a stream.  What I want to do is grab the stream as a document object
(http://www.DynamicPDF.com/Support/NET_Help_Library/html/ceTeDynamicPDFDocument.htm)
and then add the pages together in one document.  Once I have the second page in the document object I know how to combine them.

I see a lot of posts on sending a stream to the client (binarywrite) or saving the stream to the filesystem (webclient.downloadfile), but not on how to convert it to an object to use in the code behind.  The image class has the fromstream method that I would like to use except for the stream is a pdf, not an image. :)

I have gotten a hold on the memorystream using webclient.downloaddata, but cannot find how to get the information into an object.  A simple Ctype(stream, document) won't build, and if I use a binaryformatter.deserialize, I get the 'BinaryFormatter Version incompatibility' error that I think actually means I can't deserialize a stream into an object.

Has anyone done this or have an idea how to do it?  Or another idea on how to combine these two separately-created reports into one pdf?  Any assistance will be met with sincere appreciation. :)

Brian
Posted by a ceTe Software moderator
Hello Brian,

This can be done using our DynamicPDF Merger for .NET product.

Following is the code snippet that will merge the PDF document coming as a stream to the page of an existing the PDF document:

// URL to retrieve PDF
string url = "http://www.adobe.com/products/acrobat/pdfs/docsforms.pdf";

// Create a MemoryStream from the URL
WebClient wc = new WebClient();
byte[] webPdfBytes = wc.DownloadData( url ) ;
System.IO.MemoryStream webPdf = new MemoryStream( webPdfBytes );

// Create PdfDocument object out of stream from URL        
PdfDocument pdfDocument = new PdfDocument( webPdf );
MergeDocument document = new MergeDocument();
// Create first page
Page page = new Page( PageSize.Letter, PageOrientation.Portrait, 54.0f );
TextArea area = new TextArea( "Hello World", 0, 0, 504, 100, Font.Helvetica, 18, TextAlign.Center );
page.Elements.Add( area );
// Add first page to the document
document.Pages.Add( page );
// Append PDF document from URL
document.Append( pdfDocument );
// Output PDF to the browser
document.DrawToWeb( this, "HelloWorld.pdf" );

Thanks,
ceTe Software Support Team
 Oct 28 2005 11:23 AM
Thanks for the reply!

Brian

All times are US Eastern Standard time. The time now is 11:37 PM.