Skip to main content
February 28, 2017
Answered

"Bad parameter." When Calling PDDocDeletePages()

  • February 28, 2017
  • 1 reply
  • 962 views

I have a plug-in that deletes all pages from a document using the following code:

// get the active PDF document

AVDoc currentAVDoc = AVAppGetActiveDoc();

PDDoc originalDocument = AVDocGetPDDoc(currentAVDoc);

// number of pages in the document

int numPages = PDDocGetNumPages(originalDocument);

// delete all pages from the document

PDDocDeletePages(originalDocument, 0, numPages - 1, NULL, NULL);

The problem is that I'm getting an error message that simply says "Bad parameter" when my code calls the PDDocDeletePages() function. So I tried to delete each individual page one at a time by doing this:

  for (int i = numPages - 1; i >= 0; i--)

  {

    PDDocDeletePages(originalDocument, i, i, NULL, NULL);

  }

The same error message still appears, but it happens once there is only 1 page remaining. The other pages are deleted without any problem. I have even tried reversing the loop and deleting the pages in the opposite order, but the error still comes when there is only 1 page remaining.

Can you think of any reason why this would happen? I have even tried using the constant PDLastPage to delete the last remaining page, but that does not seems to be the answer.

This topic has been closed for replies.
Correct answer Bernd Alheit

You can't delete all pages. A PDF document must have at least one page.

1 reply

Bernd Alheit
Bernd AlheitCorrect answer
Community Expert
February 28, 2017

You can't delete all pages. A PDF document must have at least one page.

February 28, 2017

Ah, that makes perfect sense. This was indeed the problem. Thank you very much for the quick response.