Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42220

VS 2008 itextsharp question - append static PDF page to PDF I am generating

$
0
0
This is the first time I've worked with itextsharp. I'm maintaining existing code so most of the work was already done for me. I have a question on how to do this enhancement.

My code currently dynamically generates a PDF with n-pages. I want to remove the code that generates the nth page and instead pull in a static PDF document. So in other words I have these variable data that I'm creating cells and tables from, but my last page is non-changing and we want to move from dynamically generating it to just pulling it in from an existing file.

I think this is the relevant code you would want to see:
Code:

            // This method builds the PDF
            byte[] bytes = (byte[])BuildPdf(startDT, endDT);

            //Clear out the response
            Response.Clear();
            Response.ClearContent();
            //clear out the headers
            Response.ClearHeaders();

            //add the new PDF headers
            int length = bytes.Length;
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-length", length.ToString());
            Response.AppendHeader("Content-Disposition", "inline; filename=MyPDF.PDF");

            //stream the data to the browser
            Response.BinaryWrite(bytes);
            // changed to flush/close vs. end for F5
            Response.Flush();
            Response.Close();
            //Response.End();

BuildPDF() does all the work with the variably-occurring pages and ends with this:
Code:

            // Add footer page
            CreateFooterPage();

            // Close the document to complete it
            PDFDocument.Close();

            stream.Flush();
            stream.Position = 0;
           
            //Clean up.
            this.PDFDocument = null;

            byte[] data = new byte[stream.Length];
            stream.Read(data, 0, data.Length);
            stream.Close();

            return data;

It is CreateFooterPage() that I want to change to just open an existing pdf, read it into some object and append it to this.PDFDocument. I know I am way oversimplifying it but simply stated, that's it.

I'm not sure what would get the right hits in google. Do you know where I can start to find documentation on this?

Viewing all articles
Browse latest Browse all 42220

Trending Articles