PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sun Aug 24, 2025 11:07 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon Jun 23, 2025 12:57 pm 
Offline

Joined: Tue Feb 18, 2020 7:40 pm
Posts: 14
Hello,
I use PDFsharp-GDI 6.2.0 (nuget package)
I have problem embedding fonts. I posted my Font resolver, I also tried without ... Everything I tried it shows in Adobe Reader:

DejaVu Sans (Embedded Subset)
Type: TrueType (CID)
Encoding: Identity-H

Why it is not fully embedded. Please help me kind people.

I call it with this:
Dim options = New XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.EmbedCompleteFontFile)
Dim font = New XFont("DejaVu Sans", 12, XFontStyleEx.Regular, options)


Public Class MyFontResolver
Implements IFontResolver

Public Function ResolveTypeface(familyName As String, isBold As Boolean, isItalic As Boolean) As FontResolverInfo Implements IFontResolver.ResolveTypeface
If familyName = "DejaVu Sans" Then
Return New FontResolverInfo("dejavusans#regular", PdfFontEmbedding.EmbedCompleteFontFile)
End If
Throw New NotImplementedException("Font not supported: " & familyName)
End Function

Public Function GetFont(faceName As String) As Byte() Implements IFontResolver.GetFont
If faceName = "dejavusans#regular" Then
Return File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DejaVuSans.ttf"))
End If
Throw New FileNotFoundException("Font not found: " & faceName)
End Function
End Class


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 25, 2025 11:21 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3135
Location: Cologne, Germany
Hi!

"PdfFontEmbedding.EmbedCompleteFontFile" works as advertised and the complete TTF file will be embedded.
I cannot say why Adobe Reader sometimes shows "(embedded)" and sometimes "(embedded subset)".

You can check the size of the stream in the PDF file to verify it is identical to the size of the TTF file.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 08, 2025 11:50 am 
Offline

Joined: Tue Feb 18, 2020 7:40 pm
Posts: 14
I cannot pass pdf/a validator:https://www.pdf-online.com/osa/validate.aspx

With this works passes the online validator:
Code:
        gfx.DrawString("ššš", font, New XSolidBrush(XColor.FromArgb(0, 0, 0)), New XRect(50, 100, 500, 30), XStringFormats.TopLeft)


But this doesnt:
Code:
        gfx.DrawString("šššččč", font, New XSolidBrush(XColor.FromArgb(0, 0, 0)), New XRect(50, 100, 500, 30), XStringFormats.TopLeft)


I tried different fonts, I tried using I custom font resolver, no luck. Please help kind people. And thank You for pdfSharp.


Here is my complete code:
Code:
   
 Sub vera()

        Dim Document As New PdfDocument()

        Dim font As XFont = New XFont("Arial", 12, XFontStyleEx.Regular, New XPdfFontOptions(PdfFontEmbedding.EmbedCompleteFontFile))

        Document.Info.Title = "PDF/A Minimal Test"
        Document.Info.Author = "Tester"
        Document.Info.Subject = "PDF/A-1b Compliance"
        Document.Info.Creator = "PDFSharp VB.NET"
        Document.Version = 14 ' PDF 1.5 for PDF/A-2
        Document.SetPdfA()

        Dim iccPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sRGB_IEC61966-2-1_black_scaled.icc")
        If Not File.Exists(iccPath) Then
            Throw New FileNotFoundException("ICC profile missing: " & iccPath)
        End If

        Dim iccBytes = File.ReadAllBytes(iccPath)
        Dim iccProfileStream As New PdfDictionary(Document)
        iccProfileStream.Elements.SetInteger("/N", 3)
        iccProfileStream.CreateStream(iccBytes)
        Document.Internals.AddObject(iccProfileStream)
        Dim iccRef As PdfReference = Document.Internals.GetReference(iccProfileStream)

        Dim UAManager As UAManager = UAManager.ForDocument(Document)
        Dim PdfPage As PdfPage = Document.AddPage()
        Dim gfx As XGraphics = XGraphics.FromPdfPage(PdfPage)

        Dim sb As StructureBuilder = UAManager.StructureBuilder
        sb.BeginElement(PdfGroupingElementTag.Article)
        sb.BeginElement(PdfBlockLevelElementTag.Paragraph)

        gfx.DrawString("ššš", font, New XSolidBrush(XColor.FromArgb(0, 0, 0)), New XRect(50, 100, 500, 30), XStringFormats.TopLeft)
        gfx.DrawLine(New XPen(XColor.FromArgb(0, 0, 0)), 0, PdfPage.Height / 2, PdfPage.Width, PdfPage.Height / 2)
        gfx.DrawLine(New XPen(XColor.FromArgb(0, 0, 0)), 0, PdfPage.Height / 4, PdfPage.Width, PdfPage.Height / 4)
        gfx.DrawLine(New XPen(XColor.FromArgb(0, 0, 0)), 0, PdfPage.Height / 6, PdfPage.Width, PdfPage.Height / 6)

        sb.End()
        sb.End()

        Dim pdfFont As XPdfFontOptions = font.PdfOptions
        Console.WriteLine("Font embedded: " & pdfFont.FontEmbedding.ToString())
        Console.WriteLine("Font embedded: " & pdfFont.FontEmbedding.EmbedCompleteFontFile.ToString)

        Dim filename = "test.pdf"
        Document.Save(filename)
    End Sub


PS: now I discovered that pdfsharp already add XMP, well even if I let that part out, still cannot get it to pass the test with


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 11, 2025 7:10 am 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1054
Location: CCAA
iluvathar wrote:
But this doesnt:
What is the exact error message?

For issue reporting, see:
https://docs.pdfsharp.net/General/Issue ... About.html

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 13, 2025 9:17 am 
Offline

Joined: Tue Feb 18, 2020 7:40 pm
Posts: 14
The error from validator https://www.pdf-online.com/osa/validate.aspx is:

Validating file "minimal_not_working.pdf" for conformance level pdfa-1a
The key CIDSet is required but missing.
The document does not conform to the requested standard.
The document contains fonts without embedded font programs or encoding information (CMAPs).
The document does not conform to the PDF/A-1a standard.
Done.


and the other validator from Vera https://demo.verapdf.org/:

Specification: ISO 19005-1:2005, Clause: 6.3.5, Test number: 3
For all CIDFont subsets referenced within a conforming file, the font descriptor dictionary shall include a CIDSet stream identifying which CIDs are present in the embedded CIDFont file, as described in PDF Reference Table 5.20 Failed
1 occurrences Hide
PDCIDFont
fontName.search(/[A-Z]{6}\+/) != 0 || (containsCIDSet == true && cidSetListsAllGlyphs == true)
root/document[0]/pages[0](9 0 obj PDPage)/contentStream[0](10 0 obj PDContentStream)/operators[10]/font[0](DQMZHK+Arial Unicode MS)/DescendantFonts[0](DQMZHK+Arial Unicode MS)


I reported the issue now:
https://github.com/empira/PDFsharp/issues/295

I am sorry, if my report is subpar, it is my first time doing this. If I am missing stuff, please tell me and I will correct it.


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 15, 2025 11:48 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3135
Location: Cologne, Germany
iluvathar wrote:
I am sorry, if my report is subpar, it is my first time doing this. If I am missing stuff, please tell me and I will correct it.
Life is easier for us if people use the IssueSubmissionTemplate to provide a ZIP file with a complete VS solution that replicates the issue.
So far, the IssueSubmissionTemplate only supports C#, but not VB.NET, so the template is not perfect for you.

Apart from that, your report was very good and included all necessary information.

See the GitHub issue for technical details about the issue.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 56 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group