0

I have a PDF file file (say A.pdf) and would like to create a copy of that file (B.pdf). But I would like to skip some text when I copy the file.

For example A.pdf has a text of Hello World and I will skip the text Hello and eventually B.pdf will have World only.

Edit: The word World shall stay where it is and it is not going to shift.

I tried to solve that problem using PDFTextStripper class but the text remained same. I'm quite new to the PDFBox and using version 2.

Thanks.

The_Cute_Hedgehog
  • 1,280
  • 13
  • 22
  • likely tricky. See the RemoveAllText.java example, also have a look at the content stream of the pages of your file with PDFDebugger. – Tilman Hausherr Apr 06 '20 at 13:48
  • ... and not only a bit tricky, in particular if you are after a solution for arbitrary documents. By the way, do you expect the "World" to stay in place or shall or shift left to where the "Hello" started? – mkl Apr 06 '20 at 14:08
  • @mkl I expect the "World" to stay in place (no shifting). I'll edit the question. – The_Cute_Hedgehog Apr 06 '20 at 15:09
  • That's a relevant fact. Depending on how the "Hello World" is drawn, simply removing the "Hello" string will move the "World" part. – mkl Apr 06 '20 at 15:36
  • @mkl Naively tried removing text with a sample given in the cookbook. I read many posts on removing text in a Pdf file but I haven't got a concrete example but in the cookbook. Do you have a recommendation? – The_Cute_Hedgehog Apr 06 '20 at 15:58
  • You might be interested in [this answer](https://stackoverflow.com/a/58501254/1729265) even though your use case is more complicated. – mkl Apr 06 '20 at 18:48

0 Answers0