You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "Emmadi, Santhosh K." <SE...@firstam.com> on 2017/10/09 06:08:24 UTC

PDFBox Font Color Issue

Hi Team,

I have one issue with font color.

My requirement is , I have PDField and need to display text with limited size with black color and once reach the length of the characters need to display overflow text with different color .

I am trying with below code but its overriding with blue color font for all the text.

int normalTextSize=ucc1_opt.substring(0,84).length();
int overFlowTextSize=ucc1_opt.substring(84,ucc1_opt.length()).length();

PDField ucc1_Optional_nonColor=null;
PDField ucc1_Optional_Color=null;


                                                                if(normalTextSize>0){

                                                                                ucc1_Optional_nonColor = form.getField("8");

                                                                                nonColorText=ucc1_opt.substring(0,84);  //get limited text 0 to 84

                                                                                ucc1_Optional_nonColor.setValue(nonColorText);

                                                                                ((PDVariableText) ucc1_Optional_nonColor).setDefaultAppearance(Constants.FONT_BLACK);

                                                                }
                                                                if(overFlowTextSize>0){

                                                                                ucc1_Optional_Color=form.getField("8");

                                                                                colorText=ucc1_opt.substring(84,ucc1_opt.length());   //For over flow text

                                                                                ucc1_Optional_Color.setValue(colorText);

                                                                                ((PDVariableText) ucc1_Optional_Color).setDefaultAppearance(Constants.FONT_BLUE);

                                                                }


Could you please suggest/help is it possible to set 2 different font colors for single text field text in pdfbox. (partial text colors)

Thank you in advance for your help.

Regards,
Santhosh


******************************************************************************************
This message may contain confidential or proprietary information intended only for the use of the
addressee(s) named above or may contain information that is legally privileged. If you are
not the intended addressee, or the person responsible for delivering it to the intended addressee,
you are hereby notified that reading, disseminating, distributing or copying this message is strictly
prohibited. If you have received this message by mistake, please immediately notify us by
replying to the message and delete the original message and any copies immediately thereafter.

If you received this email as a commercial message and would like to opt out of future commercial
messages, please let us know and we will remove you from our distribution list.

Thank you.~
******************************************************************************************
FAFLD

Re: PDFBox Font Color Issue

Posted by Tilman Hausherr <TH...@t-online.de>.
You'd have to generate a different appearance stream. Nothing out of the 
box is available for this. Have a look at AppearanceGeneratorHelper.java 
and possibly PlainTextFormatter.java in the source code download. 
However this would only appear when the PDF is displayed, not when the 
field is edited in an application.

Tilman

Am 09.10.2017 um 08:08 schrieb Emmadi, Santhosh K.:
> Hi Team,
>
> I have one issue with font color.
>
> My requirement is , I have PDField and need to display text with limited size with black color and once reach the length of the characters need to display overflow text with different color .
>
> I am trying with below code but its overriding with blue color font for all the text.
>
> int normalTextSize=ucc1_opt.substring(0,84).length();
> int overFlowTextSize=ucc1_opt.substring(84,ucc1_opt.length()).length();
>
> PDField ucc1_Optional_nonColor=null;
> PDField ucc1_Optional_Color=null;
>
>
>                                                                  if(normalTextSize>0){
>
>                                                                                  ucc1_Optional_nonColor = form.getField("8");
>
>                                                                                  nonColorText=ucc1_opt.substring(0,84);  //get limited text 0 to 84
>
>                                                                                  ucc1_Optional_nonColor.setValue(nonColorText);
>
>                                                                                  ((PDVariableText) ucc1_Optional_nonColor).setDefaultAppearance(Constants.FONT_BLACK);
>
>                                                                  }
>                                                                  if(overFlowTextSize>0){
>
>                                                                                  ucc1_Optional_Color=form.getField("8");
>
>                                                                                  colorText=ucc1_opt.substring(84,ucc1_opt.length());   //For over flow text
>
>                                                                                  ucc1_Optional_Color.setValue(colorText);
>
>                                                                                  ((PDVariableText) ucc1_Optional_Color).setDefaultAppearance(Constants.FONT_BLUE);
>
>                                                                  }
>
>
> Could you please suggest/help is it possible to set 2 different font colors for single text field text in pdfbox. (partial text colors)
>
> Thank you in advance for your help.
>
> Regards,
> Santhosh
>
>
> ******************************************************************************************
> This message may contain confidential or proprietary information intended only for the use of the
> addressee(s) named above or may contain information that is legally privileged. If you are
> not the intended addressee, or the person responsible for delivering it to the intended addressee,
> you are hereby notified that reading, disseminating, distributing or copying this message is strictly
> prohibited. If you have received this message by mistake, please immediately notify us by
> replying to the message and delete the original message and any copies immediately thereafter.
>
> If you received this email as a commercial message and would like to opt out of future commercial
> messages, please let us know and we will remove you from our distribution list.
>
> Thank you.~
> ******************************************************************************************
> FAFLD
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org