' ' PDFNet Copyright (c) 2001-2008 by PDFTron Systems Inc. All Rights Reserved. ' Imports System Imports pdftron Imports pdftron.Common Imports pdftron.Filters Imports pdftron.SDF Imports pdftron.PDF Module Module1 ' The sample code shows how to edit the page display list and how to modify graphics state ' attributes on existing Elements. In particular the sample program strips all images from ' the page and changes text color to blue. Sub Main() PDFNet.Initialize() PDFNet.SetResourcesPath("../../../../resources") ' Relative path to the folder containing test files. Dim input_path As String = "../../../TestFiles/" Dim output_path As String = "../../../TestFiles/Output/" Console.WriteLine("-------------------------------------------------") ' Open the test file Console.WriteLine("Opening the input file...") Dim doc As PDFDoc = New PDFDoc(input_path + "newsletter.pdf") doc.InitSecurityHandler() Dim num_pages As Integer = doc.GetPageCount() Dim writer As ElementWriter = New ElementWriter Dim reader As ElementReader = New ElementReader Dim element As Element Dim i As Integer For i = 1 To num_pages Step 1 Dim page As Page = doc.GetPage(1) reader.Begin(page) Dim new_page As Page = doc.PageCreate() doc.PagePushBack(new_page) writer.Begin(new_page) element = reader.Next() While (Not IsNothing(element)) ' Read page contents If element.GetType() = element.Type.e_text Then ' Set all text to blue color. Dim gs As GState = element.GetGState() gs.SetFillColorSpace(ColorSpace.CreateDeviceRGB()) gs.SetFillColor(New ColorPt(0, 0, 1)) writer.WriteElement(element) ElseIf element.GetType() = element.Type.e_image Then ' remove all images Else writer.WriteElement(element) End If element = reader.Next() End While writer.End() reader.End() new_page.SetMediaBox(page.GetCropBox()) doc.PageRemove(doc.GetPageIterator(1)) ' Remove the old page Next i doc.Save(output_path + "newsletter_edited.pdf", SDF.SDFDoc.SaveOptions.e_remove_unused) doc.Close() Console.WriteLine("Done. Result saved in out.pdf...") PDFNet.Terminate() End Sub End Module