PDFBOX - WordUtils.wrap - need to display bold and non-bolded text on same line - pdfbox

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!!

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!!!

Related

Conditional Merge in Word is adding an Extra character "I" before each conditional paragraph

I am doing a conditional merge in Word from an excel list. One of the conditions is If Program Restriction = XYZ, then add this paragraph. If Program Restriction = ABC, then add this paragraph.
For the first letter, it adds the paragraph perfectly. From that point on, it will add an "I" in front of the paragraph for all addition conditional paragraphs.
Here is the conditional Merge formatting:
Can anyone tell me why this is doing that? I checked the document to ensure I do not have an "I" anywhere in the document that could be throwing off the code.
Any help is so appreciated.
Thanks
Cathy
I have tried seeing if there is conditional coding that contains the character. It does not.
I have tried seeing if there is an "I" in the previous fields to see if that is throwing it off. there is not.

How to find and replace mixing format text in MS-Word or using VBA

Here is an example of what I want. Suppose a text:
paper[1], some texts[2], paper[3]
Here is the expected result ==>
paper[1], some texts[2], paper[3]
That is, I want to replace all "paper[1]" with "paper[1]" and similarly, replace "paper[3]" with "paper[3]" but keep the texts[2] unchanged.
I have noticed that word can not search the mixing format text, e.g., I can not find the text "paper[3]". So I may need the VBA to achieve this. Any ideas? Thanks!
You don't even need VBA for that! A wildcard Find/Replace can be used, where:
Find = paper\[[13]\]
Replace = ^&
and the replacement font is set to 'not superscript'. If you really want a macro, record the above.

Word VBA search for adjacent (non-space) characters with different formatting

I need to be able to find every place in my document (hundreds of pages) where there is a formatting change without a space. For example:
a bold partnext to regular text
Or red text next to black with no space. I want to have my macro find each "word" (in the vba sense) like this, and execute code based on that character location accordingly. (The loop should identify the character position where the format change occurs... although I can do that part with a loop through the characters within the found word).
Is there a simpler way to do this than by looping character by character through the whole document and checking for a difference in formatting, which would be too resource-intensive?
Thanks for your help.

MS Word, how to change formatting of entire paragraphs automatically in whole document?

I have a 20-page word document punctuated with descriptive notes throughout, like this:
3 Input Data Requirements
Some requirement text.
NOTE: This is a descriptive note about the requirement, which is the paragraph that I would like to use find-and-replace or a VBA script to select automatically and change the formatting to italicized. The notes invariably end in a carriage-return: ΒΆ.
If it was just a text document, not MS-Word, I would just use a regex in a code editor like sublime to wrap it with <I>...</I> or something along those lines.
Preferably, is there a way to do this in Word's "advanced" find-and-replace feature? Or if not, what's the best way to do it in VBA?
I've tried using a search string like this in find-and-replace: NOTE: *[a-z0-9,. A-Z)(-]{1,255}^l but the line-break part doesn't seem to work, and the 255 char max isn't enough for many of the paragraphs.
EDIT: Another slightly important detail: The doc is automatically generated from another piece of software as a .RTF, which I promptly converted to .docx.
Attempt #2: Use Notepad++ to find and replace using regex. Remove quotes.
Find: "( NOTE: .*?)\r"
Replace with: " \i \1 \i0 \r "
//OLD
Sure is. No VBA or fancy tricks needed.
CTRL + H to bring up the replace dialog.
Click "More".
Select "Font" in the drop down menu called "Format".
Click italics.
Enter find and replace text as the same thing. Make sure you set this up right so that you don't accidentally replace substrings (e.g. goal to replace all " test " with " nice ", testing -> niceing).
Should work. If you need to alter entire paragraphs, consistently, then you probably should have used the styles on those paragraphs to begin with. That way, you can change all of them at once by updating the style itself.
You can use Advance Find, yes. Find Next and then Replace makes the selection Italic.

How do I add a subscript to a string?

I need to add a subscript (a little number next to a character, like 2 or 3 - note: not a power of...) to a string [variable]. Is this possible? I don't want the code to be lengthy as I will need to process a lot of formulas, one at a time. Thanks.
You will have to use the character set subscript numbers. Strings do not contain formatting.
http://www.fileformat.info/info/unicode/char/2082/index.htm
Is this possible? No - string variables do not contain formatting.
In order to achieve this you will need to add some sort of formatting to your string and display it in something that can show different formats - for example a RichTextBox control
Try adding a RichTextBox control and running the following line:
RichTextBox1.Rtf = "{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}{\f1\fnil\fcharset0 Segoe UI;}}\viewkind4\uc1\pard\ltrpar\sa200\sl276\slmult1\f0\fs22 sometext\fs12 subscript\fs22\par\pard\ltrpar\f1\fs17\par}"
I don't claim to know what all the formatting is in here so I will leave you to figure that out yourself - hope that helps...