Print Page | Close Window

Font embedded multiple times

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=273
Printed Date: 10 May 24 at 5:38PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Font embedded multiple times
Posted By: StanMarshall
Subject: Font embedded multiple times
Date Posted: 18 Jan 06 at 5:04PM

Hi all...

It was great to stumble across this forum. Thanks to all who started it. I share your dismay at the apparent demise of ISED.

I have a question: Does anyone know how to get QuickPDF to only embed a font if that font has not already been embedded in the document? And, if it has already been embedded in the document, to use that font for a specific call to DrawText?

At first, I was hoping AddTrueTypeFont would just be smart enough to realize the font I am asking it to add to the document was already there and, so, to not add it again. However, that does not seem to be the case.

So I tried this:

function CheckPDFDocumentForFont(thePDF : TiSEDQuickPDF; FontName : String) : LongInt;
var
  FontCtr : Integer;
  FontCount : Integer;
  FontID : LongInt;
begin
  Result := -999;

  FontCount := thePDF.FindFonts;

  for FontCtr := 1 to FontCount do
  begin
    FontID := thePDF.FontID(FontCtr);
    thePDF.SelectFont(FontID);
    if UpperCase(thePDF.FontName) = UpperCase(FontName) then
    begin
      Result := FontID;
      exit;
    end;
  end;

  Result := -1; {font not found}
end;


function PrintTextControlOnPDFPage(...)
begin
  FontID := CheckPDFDocumentForFont(thePDF,FontName);

  if FontID < 0 then FontID := thePDF.AddTrueTypeFont(FontName,1);

  thePDF.SelectFont(FontID);

...

end;

(The PDF is already properly opened etc. before either of these routines is called.)

However, it still seems to re-embed the font for each text control that uses it. (My printing routines iterate through each visible control on a form and print each control independently...it's sort of a homegrown wysiwyg report designer.)

The font does not show up multiple times in Acrobat's "Document Properties|Fonts" list, but the space used by fonts increases (substantially) with each text control I add to the form I am printing...even if the text is only a three letter word.

Can anybody see any problems with the code I have pasted above (like why it would not find the font, or, if it does find the font, why it would re-embedd it anyway)? Or, does anyone have any ideas on how to get QuickPDF to stop embedding the same font multiple times (assuming that is really what is happening)?

I can think of a few possibilities like figuring out all of the necessary fonts and embedding them ahead of time or maintaining my own list of fonts that have been used. However, I would rather not use either of those approaches for reasons beyond the scope of this post (the second wouldn't be too bad if it works).

I would really like to be able to just ask QuickPDF "is the font used by this text control already embedded in the document? if so, just use it...if not, embed it" I can't figure out why the code I have pasted above does not seem to be doing that.

Any help would be greatly appreciated.

Thanks.

Stan




Replies:
Posted By: StanMarshall
Date Posted: 18 Jan 06 at 6:13PM

I have done some more playing around and have determined that this only happens with bold or italic fonts.

For example, "Arial [Bold]".

I think it has to do with the naming convention. Seems like QuickPDF recognizes the naming convention "fontname [Bold]" for adding fonts, but not for finding them.

A little more poking around should allow me to discover the naming convention it will use to find the fonts...then, hopefully, I'll just need to do some systematic name translation and it will work...hopefully

If I figure it out, I will post the solution so anyone else who might run into this can find the answer.

In the meantime, if anyone has any thoughts, please post them.

Thanks.

Stan



Posted By: Ingo
Date Posted: 19 Jan 06 at 1:46AM
Hi Stan!

I've made own code searching through the whole pdf-file collecting all embedded fonts and offer the result as a user information in a combobox.
First i decrypt the file and read the file-content into a string. There i'm looking for all font objects. It's fast enough for big files, too.

Best regards,
Ingo


Posted By: StanMarshall
Date Posted: 20 Jan 06 at 11:04AM

Thanks for the idea Ingo. I'll play around with that.




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