Is there a method to delete a page from an existing pdf file?

I didn't see any API methods to easily delete a page from an existing pdf file. Does one exist?, and if so does it keep all other pdf data intact (ie. embedded data of pdf file)?

Hi,

I don’t think there is a direct method to delete a page from an existing pdf file. I will discuss it with the developers and let you know if this functionality can be incorporated. In the mean time you can use the Extract method of the Aspose.Pdf.Kit.PdfFileEditor class as a work around. The following code should do it.

//Initialize the string variables storing paths of PDF files
string inFile = ".\\example1.pdf";
string outFile = ".\\ExtractStream.pdf";

//Creating stream objects holding the PDF files in Open Mode
FileStream inStream = new FileStream(inFile,FileMode.Open);

//Creating output stream object that will store the extracted pages as a PDF file
FileStream outputStream = new FileStream(outFile,FileMode.Create);

//Instantiating PdfFileEditor object
PdfFileEditor editor = new PdfFileEditor();

//Creating an array of integers having numbers of the all pages except the ones to be deleted
int[] pages = new int[]{1,2,4,5}; //page 3 is to be deleted

//Calling Extract method
editor.Extract(inStream,pages,outputStream);

//Closing output stream
outputStream.Close();

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team
http://www.aspose.com/Wiki/default.aspx/Aspose.Corporate/ContactChangsha.html

I tried this method too, quite simple but it works.

however: the bookmarks are lost? Can you solve this?

We have investigated this issue and found we can’t reserve the bookmark when a page is deleted. But you can try creating new bookmark for the new document.

This has been supported in hotfix 2.3.3.0. Please download and try it.