Print Page | Close Window

Font has not been embedded in 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=3941
Printed Date: 29 Apr 24 at 4:16AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Font has not been embedded in pdf
Posted By: timur
Subject: Font has not been embedded in pdf
Date Posted: 23 Jul 21 at 1:30PM
Hi everyone,
PDFs Created QPDFLibrary with Version 15
Platform: Windows Server 2019
Programming Language: C# (Net Framework 4.72)

I get following message from Acrobat Reader, but not always.

"Cannot find or create the font "GWQGUD+Times New Roman". Some charachters may not display or print correctly."
GWQGUD changing every time.

In some of my created pdfs missing the obj definition for that  (I open it Notepad++)

What can be the cause of missing obj definition. How can I debug it, or how can i check whether obj definition has been added successfully before or after creating  pdf?

Thanks in advance

KR

Timur



Replies:
Posted By: Ingo
Date Posted: 26 Jul 21 at 10:02PM
Hi Timur,

did you embed the font?
If not i think that the error occurs on systems, where this font isn't installed.
Try AddTrueTypeFontFromFile:
https://www.debenu.com/docs/pdf_library_reference/AddTrueTypeFontFromFile.php

Cheers and welcome here,
Ingo



-------------
Cheers,
Ingo



Posted By: timur
Date Posted: 27 Jul 21 at 7:31AM
Hi Ingo,

thank you for response. Yes I embed it as subset (DebenuPDFLibraryAddTrueTypeSubsettedFont). 
Same code , I see in PDF "Times New Roman(Embedded Subset)" and it working.
but sometimes i see just 
"Times New Roman" without anything (In PDF Options). And if I try to open it in Adobe I get the Error.
It is a mystery for me. 

I add every time a font for creating font with 
DebenuPDFLibraryAddTrueTypeSubsettedFont.

I thought if I remove the document from Instance  (DebenuPDFLibraryRemoveDocument) fonts will be removed as well. Is not the case, how can I clear the fonts I have already added?

I get the error on PDF Exchange Editor: error loading object misaligned object




Posted By: Ingo
Date Posted: 31 Jul 21 at 3:24PM
Hi Timur,

perhaps it's better to post the relevant code parts?
QuickPDF uses unicode strings.
What option (0-5) did you use?



-------------
Cheers,
Ingo



Posted By: timur
Date Posted: 02 Aug 21 at 12:51PM
Hii Ingo,

thanks again.
Option
Its a windows service. At first I created the Library on Startup and removed (RemoveDocument) the document. But now on every request I create the library again an still
I want to mention it it happens only on Windows Server 2019 (or we have not detect anywhere else).
And my Console app for testing working without problem on the same Server.

Hier is Example Class:

  public class TestClass
    {
        
        public TestClass()
        {
          // as I mentioned it I created at first only once here. 
        }

        public void StampIt()
        {
            var pdfLibrary = new PDFLibrary("pdfLibraryPath");
            pdfLibrary.UnlockKey("myKey");
            var file = "Test.pdf";
            pdfLibrary.SetTransparency(0);
            pdfLibrary.SetLineWidth(1);

            pdfLibrary.SelectPage(1);
            pdfLibrary.SetOrigin(1);
            pdfLibrary.NormalizePage(0);
            pdfLibrary.LoadFromString(ConvertDocument(file).ToArray(), string.Empty);

            var fontId = pdfLibrary.AddTrueTypeSubsettedFont("Times New Roman [Bold]", string.Empty, 4);

            pdfLibrary.SetTextAlign(1);
            pdfLibrary.SetTextColor(0.0, 0.0, 0.0);
            pdfLibrary.SetTextSize(19);

            pdfLibrary.SelectFont(fontId);
            pdfLibrary.DrawRotatedMultiLineText(121.60, 212.68, 0, "\n", "Test Test Test\n22.07.2021");
            pdfLibrary.SaveToFile(Path.GetFileNameWithoutExtension(file) + "_stamped" + Path.GetExtension(file));

        }

        public static MemoryStream ConvertDocument(string path)
        {
            var pdfFileStream = new MemoryStream();
            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                fileStream.CopyTo(pdfFileStream);
            }
            return pdfFileStream;
        }
    }

and some log:
Font Id: 1476395020
Font count: 1
Is Subsetted: 1
Font type: 10
Font encoding: 5
Selected font: 1476395020
Stamp Text TEST TEST TEST

thanks in advance

KR
Timur


Posted By: timur
Date Posted: 02 Aug 21 at 1:50PM
Hi Ingo,

is it possible to use a system font to avoid the embedding failures?
Which font can I use (Courier New?) and how to select it for my pdf without embedding it.

Thanks in advance

KR
Timur


Posted By: Ingo
Date Posted: 02 Aug 21 at 8:32PM
If these syntax shall work:
// ...
pdfLibrary.SetTransparency(0);
pdfLibrary.SetLineWidth(1);
pdfLibrary.SelectPage(1);
pdfLibrary.SetOrigin(1);
pdfLibrary.NormalizePage(0);
//...
you should post it after LoadFromString.


Here you'll find all font-related functions:
http://www.quickpdflibrary.com/help/quickpdf/Fonts.php

A kb-sample about how to draw text onto a pdf:
https://www.debenu.com/kb/generate-invoice-programmatically-pdf/

In the kb-sample any actual font is used.
To select one of the standard fonts try these steps before Drawing functions:
With FindFonts you can get the number of embedded fonts.
In a loop now you can go through all found fonts with
FontID -> SelectFont (with FontID) -> FontName.
If the fontname is the one you want you can break the loop (SelectFont is already done) beginning with the DrawText-functions.

These are the standard fonts:
https://www.debenu.com/docs/pdf_library_reference/SetFormFieldStandardFont.php





-------------
Cheers,
Ingo



Posted By: timur
Date Posted: 03 Aug 21 at 7:37AM
Thanks a lot



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