pdfbox icon indicating copy to clipboard operation
pdfbox copied to clipboard

add ChangeTextColor example to modify text color in PDF documents

Open KrishVij opened this issue 2 months ago β€’ 4 comments

PDFBOX-3.6: Add ChangeTextColor example

This pull request adds a new example class ChangeTextColor to the PDFBox examples module
(org.apache.pdfbox.examples.pdmodel).

The example demonstrates how to modify the text color in an existing PDF by parsing its content streams,
identifying text sections, and injecting RGB color operators (rg and RG) immediately after
the BT (Begin Text) operator.


πŸ”What the example shows

  • Shows how to use PDFStreamParser to access and modify PDF operators.
  • Demonstrates rebuilding content streams with ContentStreamWriter.
  • Converts standard RGB values (0–255) into PDF-compatible color space (0.0–1.0).
  • Uses only public PDFBox API classes β€” no private/internal APIs. Before: Screenshot 2025-10-30 220526 After: Screenshot 2025-10-30 220700

PS: Both are screenshot of a resume of mine


KrishVij avatar Oct 30 '25 16:10 KrishVij

Can anybody at least tell me was my contribution not upto the mark it will mean a lot to me.

KrishVij avatar Nov 14 '25 15:11 KrishVij

Sorry for the late reaction. I'm kinda undecided. The problem is that this will work only for very simple cases, where the text is in the top content stream.

THausherr avatar Nov 14 '25 15:11 THausherr

Greetings Mr/Ms Maintainer

Pls dont be sorry! I can understand that being a maintainer of a big open source project like this will be of course time consuming and hard. Pls decide and let me know whether this will be merged and on the flip note if you can tell me where to study more about the content streams I will really appreciate it as I did read the spec but due to my current experience and current expertise it was a bit hard to understand these complex concepts

On Fri, 14 Nov 2025, 21:00 Tilman Hausherr, @.***> wrote:

THausherr left a comment (apache/pdfbox#303) https://github.com/apache/pdfbox/pull/303#issuecomment-3533302521

Sorry for the late reaction. I'm kinda undecided. The problem is that this will work only for very simple cases, where the text is in the top content stream.

β€” Reply to this email directly, view it on GitHub https://github.com/apache/pdfbox/pull/303#issuecomment-3533302521, or unsubscribe https://github.com/notifications/unsubscribe-auth/BMRREIDARXK26C7PUC4NNPD34XYSDAVCNFSM6AAAAACKV6VG3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKMZTGMYDENJSGE . You are receiving this because you authored the thread.Message ID: @.***>

KrishVij avatar Nov 14 '25 16:11 KrishVij

Look at the examples subproject and then look at the RemoveAllText.java example, this processes form objects and patterns too. But be aware that PDF is so complex that there will always be PDFs that will fail to be changed because there are so many different ways to do anything.

THausherr avatar Nov 16 '25 10:11 THausherr