Print Page | Close Window

Use embedded font of a PDF

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3108
Printed Date: 05 May 24 at 10:29AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Use embedded font of a PDF
Posted By: datasportdev
Subject: Use embedded font of a PDF
Date Posted: 29 Apr 15 at 10:16AM
Hi
I'm trying to use an embedded font when I LoadFromFile() a PDF and then I AddTrueTypeFont() with the parameter embed = 0, because the font is already in the PDF.

But event if I read (Windows CMD --> findstr FontName "FileName") all the included font names and I take the exactly same font name or font family name, my new text does not use this font. Instead the new text is diplayed with a "default" font (Arial in my case, since the font is not installed on my PC.

What Do I do wrong??

Here a snippet:

Count := QuickPDF.FontCount;
  Found := FALSE;
  Index := 1;
  WHILE (Index <= Count) AND NOT Found DO BEGIN
    FontID := QuickPDF.GetFontID(Index);
    IF FontID > 0 then begin
      QuickPDF.SelectFont(FontID);
      if QuickPDF.FontName = FontName then Found := TRUE;
    end;
    if NOT Found then INC(Index);
  END;
  if NOT Found then begin
    FontID := QuickPDF.AddTrueTypeFont(FontName,0);
    QuickPDF.SelectFont(FontID);
  end;



Replies:
Posted By: erico
Date Posted: 29 Apr 15 at 3:02PM
Originally posted by datasportdev datasportdev wrote:


 if NOT Found then begin
    FontID := QuickPDF.AddTrueTypeFont(FontName,0);
    QuickPDF.SelectFont(FontID);
  end;


You cannot add a font you do not have. Thus the AddTrueTypeFont call above will always fail, regardless of the embed flag unless you have the font.

If the font is already in the PDF, you should be able to use it unless it has been subsetted, in which case not all characters will be available (and probably not in the standard encoding either) so adding text would be problematic at best.


-------------
Eric O


Posted By: datasportdev
Date Posted: 29 Apr 15 at 4:20PM
Thx 4 ur reply.

I know that the font is embedded. My task is now to add a text with the already embedded form.
When I do FontCount the Result = 2. One is Arial and the other is the other font I need.

When I want to add a text to the loaded PDF with this second font, I get a FontId > 0 and use this ID for my text.
Yet the new text in the PDF doesn't use that embedded fobt, but a 'default' obe from the PC where the file has been opened.


Posted By: erico
Date Posted: 29 Apr 15 at 4:55PM
You indicate that QuickPDF.FontCount is 2. Did you check that result, or do you just believe that to be true because Acrobat says there are 2 fonts embedded? Unless you call QuickPDF.FindFonts() any fonts that are already embedded in the PDF will not be seen by QuickPDF.FontCount (Check the documentation for FontCount).

Originally posted by datasportdev datasportdev wrote:

    IF FontID > 0 then begin
      QuickPDF.SelectFont(FontID);
      if QuickPDF.FontName = FontName then Found := TRUE;
    end;


Are you positive that the FontName you specify is an exact match for QuickPDF.FontName ?
(Is Found being set to TRUE?)

Just for a test, try selecting the first font found to see if it will be used:

    FontID := QuickPDF.GetFontID(1);
    IF FontID > 0 then QuickPDF.SelectFont(FontID);
    ... add some text ...



-------------
Eric O


Posted By: datasportdev
Date Posted: 29 Apr 15 at 8:36PM
Sorry! Problem found!
Confused

I was comparing the FontFamily with the FontName Embarrassed
My BIG mistake!

Now everything works fine!

Thx a lot for your feedback!!





Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk