0

I am a newbie to pdfbox AND java - trying to replicate a pdf letter with logos formatting etc. I need to use mixed font (bold) within a sentence. Presently appending paragraph string, using WordUtils.wrap, then begin.Text , etc. to parse and display (drawString has strikethrough cannot select this - I did find info for multi font using it). As field values will vary in text and length, I cannot simply search on, split and change font to display. Unable to use tags to do this (OMG I've tried everything I can think of!), but hoping there is a way to use a single char identifier for beginning of bold and another for end of bold??? One issue is that no guarantee the identifiers would end up on the same line of the paragraph. UGH. Everything else is perfect, EXCEPT the text I need to bold. Does anyone have any suggestions?? I am required to use pdfbox to accomplish this - cannot use Itext. Help please! Thank you!!

Jo Co
  • 1
  • 1
    PDFBox is low level and doesn't make paragraphs / formatting for you. What might help are these URLs, because it's all about length and positioning: https://stackoverflow.com/questions/13701017/calculation-string-width-in-pdfbox-seems-only-to-count-characters and https://stackoverflow.com/questions/27600166/calculate-correct-width-of-a-text . I'd recommend you edit your question to show what code you did, and what you want to do. (Not all problems, just one). – Tilman Hausherr Jun 17 '17 at 15:32
  • `WordUtils.wrap` - do you mean the apache commons utility? Unless you only use monospaced fonts, you should consider individual glyph widths for line wrapping, cf. e.g. [this answer](https://stackoverflow.com/a/19683618/1729265). – mkl Jun 18 '17 at 06:07

1 Answers1

0

SOLVED - I figured it out. Thank you for your suggestions!

I did not want to use positioning, needing to keep it as simple as possible. We'll eventually need to implement hundreds of letters. I Am using Utils.wrap strictly as a line parser, not formatting, so that is cool. Using 2 identifiers - 3 checks -

  • 1) both on the same line,
  • 2) beginning bold on one line, and
  • 3) end bold on another line.

Using split string by " " and checks equal to identifiers. Formatting is perfect. Going forward may need to modify, if for some crazy reason identifiers are contained in letter text.

It works for the 1st roll-out. Thanks again - your help is much appreciated!!!

Bentaye
  • 9,403
  • 5
  • 32
  • 45
Jo Co
  • 1