embed/stream PDF into Another PDF

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for .NET (v4)  /  embed/stream PDF into Another PDF

DynamicPDF Generator for .NET (v4) Forum

 Apr 24 2009 8:30 AM
I have multiple programs that generate PDF's.  One of the programs needs to pull in the PDF of another website.  I am set on the secondary website to output what I need, but I can not figure out how to get the calling page to retreive the additional document and/or pages to import them into the current document being generated.  Any advise?

I tried outputing in a byte[] and a PageList object, but how do I get that into the calling PDF?

Thanks,
Brad
Posted by a ceTe Software moderator
Hello Brad,

Yes, you can merge the PDF document from another website to your current PDF document object. You will have to get the byte array or stream data of the PDF document from the other website and then you can create a PdfDocument object using the byte array or stream. Then you can append this PdfDocument object to your current MergeDocument object. You can use the WebClient class from .NET to get the byte data of a PDF from a URL.

PdfDocument pdf = new PdfDocument( byteDataOfAPdf );
MergeDocument document = new MergeDocument();
document.Append( pdf );

Thanks,
ceTe Software Support Team.
Thanks.  Now I am having a problem with the:
PdfDocument pdf = new PdfDocument( byteDataOfAPdf );

I get the following error:
Invalid PDF File. Cross-Reference table not found.


if i run the PDFPageStream directly, it renders fine, but when I put it into a byte[] and append it to the other doc, I run into problems.

PDFPrint.aspx:
MergeDocument document = new MergeDocument();


ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page( PageSize.Letter, PageOrientation.Portrait, 31.0f);

page.Elements.Add(new ceTe.DynamicPDF.PageElements.Image(@"C:\images\DefaultHFLogo.gif", 125, 0, .5f));

document.Pages.Add(page);

WebClient MyWebClient = new WebClient();
 
byte[] byteDataOfAPdf;

byteDataOfAPdf = MyWebClient.DownloadData(@"http://localhost/sandboxweb/PDFPageStream.aspx");
                        
PdfDocument pdf = new PdfDocument( byteDataOfAPdf );
document.Append( pdf );

document.DrawToWeb("HomeFacts.pdf");

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



PDFPageStream.aspx:

byte[] byteDataOfAPdf;

ceTe.DynamicPDF.Document document = new ceTe.DynamicPDF.Document();

ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page( PageSize.Letter, PageOrientation.Portrait, 31.0f);

page.Elements.Add(new ceTe.DynamicPDF.PageElements.Image(@"C:\images\DefaultHFLogo.gif", 125, 0, .5f));

page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("Dev/Sub Name:", 0, 60, 93, eheight, sdtfontb, eheight-2, taright, RgbColor.Black));

document.Pages.Add(page);

byteDataOfAPdf = document.Draw();

Response.Write(byteDataOfAPdf);
 Apr 24 2009 10:23 AM
Nevermind,

I found my error.  I was using:
Response.Write(byteDataOfAPdf);

and I meant to use:
Response.BinaryWrite(byteDataOfAPdf);

All times are US Eastern Standard time. The time now is 10:57 PM.