Ultimate PDF Component for .NET http://www.pdfcomponent.net How to use PDF Component in C#, VB.NET and ASP.NET posterous.com Wed, 09 Feb 2011 10:13:00 -0800 Adding and removing a new page http://www.pdfcomponent.net/adding-and-removing-a-new-page http://www.pdfcomponent.net/adding-and-removing-a-new-page

Creating a page 


Firstly, you need to load an existing document by using the PdfImportedDocument class and then add a new page to the loaded document by calling doc.Pages.Add method. The following example illustrates how to do that.

C#

PdfImportedDocument lDoc = new PdfImportedDocument("myfile.pdf"); PdfPage page = lDoc.Pages.Add() as PdfPage; // Use the predefined fonts to draw the text. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10.0f, PdfFontStyle.Regular); PdfGraphics g = page.Graphics; g.DrawString("My Text", font, PdfBrushes.Black, PointF.Empty); lDoc.Save("AddNewPages.pdf"); lDoc.Close();

VB.NET

Dim lDoc As New PdfImportedDocument("myfile.pdf") Dim page As PdfPage = TryCast(lDoc.Pages.Add(), PdfPage) ' Use the predefined fonts to draw the text. Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 10.0F, PdfFontStyle.Regular) Dim g As PdfGraphics = page.Graphics g.DrawString("My Text", font, PdfBrushes.Black, PointF.Empty) lDoc.Save("AddNewPages.pdf") lDoc.Close()

Removing a page 


You can also remove pages from the existing PDF document by using the Remove or RemoveAt methods of the PdfImportedPageCollection class.


The following code example illustrates this.

C#:

PdfImportedDocument lDoc = new PdfImportedDocument("myfile.pdf"); // Remove the first page. lDoc.Pages.RemoveAt(0); lDoc.Pages.Remove(lDoc.Pages[0]); lDoc.Save("AddNewPages.pdf"); lDoc.Close();

VB.NET

Dim lDoc As New PdfImportedDocument("myfile.pdf") ' Remove the first page. lDoc.Pages.RemoveAt(0) lDoc.Pages.Remove(lDoc.Pages(0)) lDoc.Save("AddNewPages.pdf") lDoc.Close()

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1901417/Logo.jpg http://posterous.com/users/5AqhTle47UWJ ATP Incorporated ATP Inc ATP Incorporated