Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Embedding font subset vs. text align
  FAQ FAQ  Forum Search   Register Register  Login Login

Embedding font subset vs. text align

 Post Reply Post Reply
Author
Message
LuProch View Drop Down
Beginner
Beginner
Avatar

Joined: 01 Feb 13
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote LuProch Quote  Post ReplyReply Direct Link To This Post Topic: Embedding font subset vs. text align
    Posted: 01 Feb 13 at 1:50PM
Hey everyone,

I'm trying to create a PDF/A document and I'm using AddTrueTypeSubsettedFont for font embedding. When I draw aligned text with DrawHTMLText and open the document in Adobe Reader, it displays left/center/right aligned text correctly, but instead of justified text it displays left aligned text. But when I try to select that text or move cursor in it, then it behaves like if there was justified text.

When I use AddTrueTypeFont to embed a font, then the justification works correctly. But I want to avoid that function, because it produces too large PDFs.

So when I embed a whole font, it works, when I embed a subset, it does not. Do I need to add some special character to the font subset, like a space or something, which is needed to draw the justified text?

I'm using Quick PDF 9.11, Microsoft Visual C# 2008 Express Edition, Windows 7.
Code snippet and picture below.

quickPDF.SetMeasurementUnits(1); // EDIT - I forgot to mention, that my values are in millimetres.
int ID = quickPDF.AddTrueTypeSubsettedFont("Times New Roman", "a ", 0);
quickPDF.SetHTMLNormalFont("Default", ID);
quickPDF.DrawHTMLText(10.0, 10.0, 100.0, "<font size=\"20pt\"><p align=\"left\">aaaaaaaa aaaaa aaaa aaaaa aaaaa aaaaa aaaaaaaaaaaa</p></font>");
quickPDF.DrawHTMLText(10.0, 30.0, 100.0, "<font size=\"20pt\"><p align=\"center\">aaaaaaaa aaaaa aaaa aaaaa aaaaa aaaaa aaaaaaaaaaaa</p></font>");
quickPDF.DrawHTMLText(10.0, 50.0, 100.0, "<font size=\"20pt\"><p align=\"right\">aaaaaaaa aaaaa aaaa aaaaa aaaaa aaaaa aaaaaaaaaaaa</p></font>");
quickPDF.DrawHTMLText(10.0, 70.0, 100.0, "<font size=\"20pt\"><p align=\"justified\">aaaaaaaa aaaaa aaaa aaaaa aaaaa aaaaa aaaaaaaaaaaa</p></font>");


http://s18.postimage.org/q8pxktrs9/Justify.png


Edited by LuProch - 04 Mar 13 at 12:00PM
Back to Top
edvoigt View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 Mar 11
Location: Berlin, Germany
Status: Offline
Points: 111
Post Options Post Options   Thanks (0) Thanks(0)   Quote edvoigt Quote  Post ReplyReply Direct Link To This Post Posted: 07 Feb 13 at 5:57PM
Hi,

you wrote the solution by yourself. You need to embed all characters, which you like to use.

In your sample is a space between the a-words. Dont forget capitals, punctuation makrs ect.

Cheers,

Werner
Back to Top
LuProch View Drop Down
Beginner
Beginner
Avatar

Joined: 01 Feb 13
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote LuProch Quote  Post ReplyReply Direct Link To This Post Posted: 25 Feb 13 at 10:07AM
OK, so when I have that text containing just "a"-letters and spaces, then I have to embed "a" and " ". Which I did. But the justification doesn't work. So what other characters do I need to embed to make the justification work? I actually tried to embed all UTF characters from 0x0000 to 0xFFFF and it didn't help.


Edited by LuProch - 25 Feb 13 at 10:12AM
Back to Top
edvoigt View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 Mar 11
Location: Berlin, Germany
Status: Offline
Points: 111
Post Options Post Options   Thanks (0) Thanks(0)   Quote edvoigt Quote  Post ReplyReply Direct Link To This Post Posted: 25 Feb 13 at 2:28PM
Hi,

sorry, my first answer was wrong. I didnt see the blank in "a ". But I'll try it again.

In your png all looks fine, without the justified text on bottom. So left, right an center is ok.

First it looks, as you found an issue in QPL at DrawHTMLtext with align="justified". But its not sure. Try the correct HTML-spelling align="justify". It may be an mistake in the QPL-reference.

If not so, use SetTextAlign in connection with DrawText, DrawWrappedText or DrawMultiLineText. Your have there different options for justify.


I hope I could help now.

Werner

Back to Top
LuProch View Drop Down
Beginner
Beginner
Avatar

Joined: 01 Feb 13
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote LuProch Quote  Post ReplyReply Direct Link To This Post Posted: 01 Mar 13 at 3:38PM
DrawHTMLtext only works with "justified", not with "justify".
And I need DrawHTMLtext to draw text, which has different parts in different font styles (normal/bold/italic/underline). If I wanted to use DrawText, I would have to split the text and write each part separately, am I right?
Back to Top
edvoigt View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 Mar 11
Location: Berlin, Germany
Status: Offline
Points: 111
Post Options Post Options   Thanks (0) Thanks(0)   Quote edvoigt Quote  Post ReplyReply Direct Link To This Post Posted: 01 Mar 13 at 3:51PM
Hi,

you are right. With Drawtext you have more to do (splitting as you assume), because you can't use text with different styles as a unit.

Sorry, I see no easy way. But you should the wrong working "justified" report as issue to Debenu.

Werner
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 03 Mar 13 at 7:57AM
Can you try the following code which will make it simpler to understand and debug.

            QP.SetOrigin(1);

            int ID = QP.AddTrueTypeSubsettedFont("Times New Roman", "abcd ", 1);
            QP.SetHTMLNormalFont("Default", ID);

            double w = 150;
            double ypos = 10;

            QP.DrawBox(10, 0, w, 800, 0);
            QP.SetTextSpacing(-10);

            QP.DrawHTMLText(10.0, ypos, w, "<font size=\"20pt\"><p align=\"left\">aaaaaaaa aaaaa aaaa aaaaa aaaaa aaaaa aaaaaaaaaaaa</p></font>");
            ypos += 180;
            QP.DrawHTMLText(10.0, ypos, w, "<font size=\"20pt\"><p align=\"center\">bbbbbbbb bbbbb bbbb bbbbb bbbbb bbbbb bbbbbbbbbbbb</p></font>");
            ypos += 180;
            QP.DrawHTMLText(10.0, ypos, w, "<font size=\"20pt\"><p align=\"right\">cccccccc ccccc cccc ccccc ccccc ccccc cccccccccccc</p></font>");
            ypos += 180;
            QP.DrawHTMLText(10.0, ypos, w, "<font size=\"20pt\"><p align=\"justified\">dddddddd ddddd dddd ddddd ddddd ddddd dddddddddddd</p></font>");
            ypos += 180;

            QP.SaveToFile("out.pdf");
            Process.Start("out.pdf");
Back to Top
LuProch View Drop Down
Beginner
Beginner
Avatar

Joined: 01 Feb 13
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote LuProch Quote  Post ReplyReply Direct Link To This Post Posted: 04 Mar 13 at 11:58AM
edvoigt:
I reported the issue to Debenu.

AndrewC:
I tried your code and played a little with the values. I changed all the "ypos += 180;" to "ypos += 110;", because spaces between texts were too big. Then I changed width and discovered a strange behavior: Justification seems to work when the width is small (w = 150), but not with bigger widths (w = 200).
Width 150
Width 200

PS: Why did you use AddTrueTypeSubsettedFont with third parameter set to "1"? Documentation says it should be "0". (I tried both and it didn't affect the justification.)
AddTrueTypeSubsettedFont

PPS: I forgot to mention in my first post, that my values are in millimetres. Yours are in points. (I again tried both and it doesn't affect the justification, once you convert the values.)
SetMeasurementUnits


Edited by LuProch - 04 Mar 13 at 12:07PM
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 04 Mar 13 at 12:13PM
I later realised that your measurements were in mm. 

AddTrueTypeSubsettedFont - should be 0.  I have a bad habit of using 1 thinking that it will embed the font - but that is what the function is doing anyway.

I also discovered the same behaviour with the various widths which is quite strange.  I haven't been able to try down why it doesn't work as expected.

I will keep working on it but have many other cases I am working on at the same time.

Andrew.
Back to Top
LuProch View Drop Down
Beginner
Beginner
Avatar

Joined: 01 Feb 13
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote LuProch Quote  Post ReplyReply Direct Link To This Post Posted: 05 Mar 13 at 10:25AM
I did some more experiments with the PDF file created with your code (w = 200).

CREATING
When I create the file with QuickPDF DLL 9.11, 9.12 or 9.13, it doesn't change anything.

DISPLAYING
I tried to view the created file in Adobe, Foxit, Chrome and also with the Quick PDF Library application on the "PDF Preview" tab.

Justification is not displayed correctly in:
- Adobe Reader 10.1.6
- Foxit Reader 4.3.0.1110
- Google Chrome 25.0.1364.152
- Quick PDF Library application 9.11
- Quick PDF Library application 9.12

Justification is displayed correctly in:
- Quick PDF Library application 9.13

PRINTING
I tried to print the created file to printer with PrintDocument function from Quick PDF DLL.

Justification is not printed correctly with:
- Quick PDF DLL 9.11
- Quick PDF DLL 9.12

Justification is printed correctly with:
- Quick PDF DLL 9.13
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 05 Mar 13 at 11:05AM
This code is working correctly

            int ID = QP.AddStandardFont(8);       // Standard Font = Times New Roman
            QP.SetHTMLNormalFont("Default", ID);

            double w = 180;
            double ypos = 10;

            QP.DrawBox(10, 0, w, 800, 0);

            QP.DrawHTMLText(10.0, ypos, w, "<font size=\"20pt\"><p align=\"justified\">dddddddd ddddd dddd ddddd ddddd ddddd dddddddddddd</p></font>");
            ypos += 180;

            QP.SaveToFile("out.pdf");


I believe it is because the AddTrueTypeSubsettedFont is creating a Composite font and Composite fonts do not support the PDF WordSpacing operator that we are using to space the text out correctly.  I will need to spend some time to see if I can work on a work-around for subsetted fonts but it the existing HTML code could require some fundamental changes for rendering justified text.

Andrew
Back to Top
LuProch View Drop Down
Beginner
Beginner
Avatar

Joined: 01 Feb 13
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote LuProch Quote  Post ReplyReply Direct Link To This Post Posted: 05 Mar 13 at 2:53PM
In summary:
- AddTrueTypeFont: Produces too big PDF files with embedded fonts.
- AddTrueTypeSubsettedFont: Justification of HTML text doesn't work.
- AddStandardFont: Offers only the few standard fonts. Also first line of text is shifted up and line spacing is smaller.

I'm starting to be a bit desperate here... Nevertheless, thank you both for your help. I hope this issue will be eventually resolved in Quick PDF library.


Edited by LuProch - 07 Mar 13 at 11:25AM
Back to Top
LuProch View Drop Down
Beginner
Beginner
Avatar

Joined: 01 Feb 13
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote LuProch Quote  Post ReplyReply Direct Link To This Post Posted: 07 Mar 13 at 3:31PM
So my last option was to use AddStandardFont, but I found out that some letters with diacritics are missing in the resulting PDF file. I'm doomed.

Code snippet:
(I put it in a picture, because my browser didn't display the letters with diacritics correctly either.)
http://s12.postimage.org/voeep7qn1/Diacritics_code.png

Result:
http://s23.postimage.org/kpds3xshn/Diacritics.png


Edited by LuProch - 07 Mar 13 at 3:43PM
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 27 Mar 13 at 12:45AM
The upcoming QPL 9.14 Beta 2 will support justified text using TrueType subsetted fonts that also include foreign characters such as German and French characters with diacritics etc.

Andrew.


Edited by AndrewC - 27 Mar 13 at 1:05AM
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store