Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Feb 21, 2023 5:19 am

I want to replace a text in pdf with background on it. How can I drawRectangle with custom color?

Code: Select all
  List rect;

        //Loop through the find collection
        for (int i = 0; i < findCollection.length; i++) {

            //Get the bounds of a specific find result
            rect = findCollection[i].getTextBounds();
            Rectangle2D a =(Rectangle2D) rect.get(0);
            PdfRGBColor CustomColor= new PdfRGBColor(235,235,235);

           // How to implement CustomColor into DrawRectangle function
            page.getCanvas().drawRectangle(PdfBrushes.getLightGray(), a.getBounds2D());

            //Draw new text at the position of the old text
            page.getCanvas().drawString(newText, pdfTrueTypeFont, PdfBrushes.getBlack(), a.getX(), a.getMinY() - 1);

        }

11111444rqrwwq124
 
Posts: 1
Joined: Thu Feb 16, 2023 8:08 am

Tue Feb 21, 2023 9:07 am

Hi,

Thanks for your inquiry.
Please see the following code for reference.
Code: Select all
        PdfRGBColor color = new PdfRGBColor(235,235,235);
        PdfBrush brush = new PdfSolidBrush(color);
        page.getCanvas().drawRectangle(brush, rectangle2D.getBounds2D());

If the code does not meet your requirement, please provide us with your document and the effect you want. Thanks for your assistance.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Thu Mar 02, 2023 8:58 am

Hi,

Greetings from E-iceblue.
Does the code meet your requirement? Could you give us some feedback at your convenience? Thanks in advance.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF