Welcome Guest Search | Active Topics | Sign In | Register

Text Box behavior and font changes when Value is set in C# and saved. Options
Dragon
Posted: Friday, June 29, 2018 11:27:01 AM
Rank: Newbie
Groups: Member

Joined: 6/29/2018
Posts: 4
Support,

I have a very simple example file. It contains two Read Only text boxes.

The Font of the first text box is set to: Tahoma Bold
The Font of the second text box is set to: Lucida Console



Below is the C# code:

PdfDocument testDoc = new PdfDocument(loadPath + "Before.pdf");

testDoc.Fields["OverflowContinued"].Value = "Will the text box below retain it's font?";

testDoc.Fields["AdditionalComments"].Value = "It is time for all good people to come to the aid of their country.";

testDoc.Save(storagePath + "After.pdf");



After the save, when you click on the text in either text box, the text reacts.

First text box: When clicked, the text shifts its position up and to the right a little.

(This is the main issue) > Second text box: The font of the text has changed to what appears to be Tahoma. When the text box is clicked, the text font seems to change to Lucida Console.



What do I need to do to solve this?

I can provide the Before and After files.

Thank you.

eo_support
Posted: Friday, June 29, 2018 3:35:41 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,344
Hi,

Each field in a PDF file in fact does have two fonts. One for interactive (when user clicks the field to enter value) and one for static (when the text is displayed before user editing it). Usually these two fonts are set to the same but they can be different. So the most likely cause for this is for the second field, the two fonts are set differently. So you may want to edit your original file to reset the font and hopefully that will set both fonts to the same value.

Thanks!
Dragon
Posted: Friday, June 29, 2018 3:49:01 PM
Rank: Newbie
Groups: Member

Joined: 6/29/2018
Posts: 4
Hello.

I'm creating the test file in Acrobat. I don't see where I can set two fonts for a single field.

Am I able to set the font to be used for these two purposes (interactive and static) for a single text field in the eo.pdf code?

Thank you
eo_support
Posted: Friday, June 29, 2018 4:53:28 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,344
Hi,

No. Our library does not attempt to change the font, in fact it does the contrary, it will try to preserve the font you previously have in the PDF file. TextBox font does not work the way you expect it to work in PDF. PDF file has some very interesting limitations on textbox font, so you may want to stay with what works --- in your case, if Tahoma works for you, you may want to set both fields to Tahoma.

The root of the problem is a PDF concept that is called font subset. A typical font data contains instructions on how to draw a few hundreds characters. Large font such as Microsoft Arial covers thousands of Unicode characters. To make PDF file portable, PDF specification requires that all font data used by the file are embedded in the file (with exceptions on a few very common fonts) so that the file will still be correctly displayed on a target machine without this font installed at all. This means if a PDF file only uses letter "A" in Arial font, then only font data for this single character will be embedded in the file. This avoid embedding the whole Arial font file (some 22MB) in your PDF file.

This poses a problem for the text box field. For example, if you set the textbox's Value to "A" thus only font data for letter "A" is included in the PDF file, later when user enters letter "B" it won't be displayed properly because the file does not contain any font data for letter "B". Some PDFViewer can "borrow" font data from the host system to display such characters and some other PDDViewer program can not or sometimes borrow the wrong one.

To avoid this problem, a PDF authoring program may choose to embed a font with a relatively "full set" of character in your file and use that font for interactive editing purpose. This appears to be what you run into: the Tahoma is the font that is fully (relatively since for some font it's impossible to embed the full set) embedded in your file. If you can send the file to us and we will be happy to look into it to see if this is indeed the case. See here for more information on how to send test files to us:

https://www.essentialobjects.com/forum/test_project.aspx

If the full set is indeed Tahoma in your file, we can not change it to anything else since then font data will be missing for the new font (when you set the field's Value is different, in that case we know exactly what characters are being used thus we can create the subset for the new font for just those characters). This is why we do not change the font in this case.

Thanks!
Dragon
Posted: Friday, June 29, 2018 5:54:42 PM
Rank: Newbie
Groups: Member

Joined: 6/29/2018
Posts: 4
Thank you for your reply.

I have emailed the "before" and "after" files to the support@essentialobjects.com email address.

I added a label and textbox to the bottom of the "before" file that contains all the letters in the alphabet and many punctuation marks for the Lucida font. This is my attempt at forcing more of the font to be included/embedded.

The behavior after the file is processed using the code below is the same as before. In Acrobat Reader, the font is wrong for the "It is time for all..." text until you click on it and it changes to Lucida.


PdfDocument testDoc = new PdfDocument(loadPath + "Starting_file_from_Acrobat.pdf");

testDoc.Fields["Text1"].Value = "Will the text box below retain it's font?";
testDoc.Fields["Text1"].ReadOnly = true;

testDoc.Fields["Text2"].Value = "It is time for all good people to come to the aid of their country.";
testDoc.Fields["Text2"].ReadOnly = true;

testDoc.EmbedFont = true;

testDoc.Save(storagePath + "Processed_file_EmbedTrue.pdf");


Was this not a good test? If so, what steps would I do next to try to solve this?

Thank you for your assistance with this.
eo_support
Posted: Monday, July 2, 2018 10:51:03 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,344
Hi,

We have looked into the test file you sent to us. The root of the problem is the font name. For some reason the font name in your PDF file is saved as "LucidaConsole" without the space in between the two words. When our library generates the output, it tries to honor this font but because of the missing space, it is unable to find this font on the system thus defaults to Arial. As such to correct this problem, you will need to correct the font name in your PDF file.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.