0
votes

I have a huge pdf containing >1000 pages, need to edit existing text, offcourse it is added by me using pdfbox addtext to each page example ... the text font size was very big text runs out of page.. now i want to decrease the size of font so that it will be within page limits... or i can clear the existing text and replace a the same text with new font...

1
Can't you just restart with the original files? - Tilman Hausherr
:( made changes on the actual file didn't backup - JAVAC
If you used the code you linked to, then you will find the "added message" in the content stream array, as the second last item. Open the PDF file with PDFDebugger and you will see what I mean. You could then delete this item progranmatically (something like PDPage.getCosObject().getItem(COSName.Contents)) and save the file. Please link to such a file (maybe create one that is representative - have a look at it with PDFDebugger too). - Tilman Hausherr
tried PDFDebugger not sure what to see... by the way i used textMatrix to add text message has shown in example of pdfbox... - JAVAC
ha ha :)... wasting time on understading PDFDebugger, removing second last item done trick, COSArray array = ((COSArray) page.getCOSObject().getItem(COSName.CONTENTS)); array.remove(array.size() - 1); thanks a lot - JAVAC

1 Answers

1
votes

credits to Tilman Hausherr for answer

If you used the code you linked to, then you will find the "added message" in the content stream array, as the second last item. PDPage.getCosObject().getItem(COSName.Contents) and save the file.

public void removeStamp(File src) throws IOException {
         PDDocument doc = PDDocument.load(src);
         PDPageTree pages = doc.getPages();

         for (PDPage page : pages) {
             COSArray  array = ((COSArray) page.getCOSObject().getItem(COSName.CONTENTS));
             array.remove(array.size() - 1);
         }
         doc.save(src);
    }