This example shows how to delete pages from a PDF document.

 

   

Setup
 

First we create an ABCpdf Doc object and read our source document. We store the number of pages we're going to delete - we're going to delete all but one.

[C#]

using (Doc doc = new Doc()) {
  doc.Read(Server.MapPath("../mypics/sample.pdf"));
  int theCount = doc.PageCount - 1;


[Visual Basic]
Using doc As New Doc()
  doc.Read(Server.MapPath("../mypics/sample.pdf"))
  Dim theCount As Integer = doc.PageCount - 1

 

   

Delete
 

We go round a loop deleting the second page each time.

[C#]

  for (int i = 0; i < theCount; i++) {
    doc.PageNumber = 2;
    doc.Delete(doc.Page);
  }


[Visual Basic]
  For i As Integer = 0 To theCount - 1
    doc.PageNumber = 2
    doc.Delete(doc.Page)
  Next i

 

   

Save
 

We add some text to the PDF so that we know how many pages we've deleted. Finally we save the PDF.

[C#]

  doc.FontSize = 500;
  doc.Color.String = "255 0 0";
  doc.TextStyle.HPos = 0.5;
  doc.TextStyle.VPos = 0.3;
  doc.AddText(theCount.ToString());
  doc.Save(Server.MapPath("deletion.pdf"));
}


[Visual Basic]
  doc.FontSize = 500
  doc.Color.String = "255 0 0"
  doc.TextStyle.HPos = 0.5
  doc.TextStyle.VPos = 0.3
  doc.AddText(theCount.ToString())
  doc.Save(Server.MapPath("deletion.pdf"))
End Using

 

   

Results
 


deletion.pdf