I quess the simplest way is to mark the object of the last page as free in the cross-reference table. If you have "old-style" cross-reference table which is in the end of file and looks like
xref
0 42
0000000003 65535 f
0000000017 00000 n
0000000081 00000 n
...
then all you need to do is change the n
of the appropriote object record to f
.
If you have file which uses cross-reference stream then it's bit more complicated as the stream is typically compressed and while you only change one/few bytes in it after recompressing it it's length might change so that it wouldn't fit to the original space.
So the safest bet seems to be to make an incremental update to the file which marks the last page object as free. This would mean to add to the end of the original file new cross-reference info where the desired page object is marked as free. Or perhaps better would be to write new version of the Page Tree object...
These solutions require that you know the object id of the last page, I don't know the itextsharp
so I don't know would it help you to find it. You might have to analyse the file yourselt to find the id.