@@ -55,7 +55,7 @@ public async Task BasicSaveFileAndEmbedFonts()
5555 string sourcePath = @"..\..\..\not-embedded.pdf" ;
5656 sourcePath = _makeSurePathIsCrossPlatformCompatible ( sourcePath ) ;
5757
58- string targetPath = @"output-not- embedded.pdf" ;
58+ string targetPath = @"output-embedded.pdf" ;
5959 targetPath = _makeSurePathIsCrossPlatformCompatible ( targetPath ) ;
6060
6161 InvoiceDescriptor descriptor = new InvoiceProvider ( ) . CreateInvoice ( ) ;
@@ -123,6 +123,77 @@ public async Task BasicSaveFileAndEmbedFonts()
123123 } // !BasicSaveFileAndEmbedFonts()
124124
125125
126+ [ TestMethod ]
127+ public async Task VeraPdfLikeFontEmbeddingTest ( )
128+ {
129+ // --- Arrange ---
130+ string sourcePath = @"..\..\..\not-embedded.pdf" ;
131+ sourcePath = _makeSurePathIsCrossPlatformCompatible ( sourcePath ) ;
132+
133+ string targetPath = @"output-embedded.pdf" ;
134+ targetPath = _makeSurePathIsCrossPlatformCompatible ( targetPath ) ;
135+
136+ InvoiceDescriptor descriptor = new InvoiceProvider ( ) . CreateInvoice ( ) ;
137+
138+ // --- Act ---
139+ await InvoicePdfProcessor . SaveToPdfAsync (
140+ targetPath ,
141+ ZUGFeRDVersion . Version23 ,
142+ Profile . Comfort ,
143+ ZUGFeRDFormats . CII ,
144+ sourcePath ,
145+ descriptor
146+ ) ;
147+
148+ Assert . IsTrue ( File . Exists ( targetPath ) , "Output PDF was not created." ) ;
149+
150+ // --- Assert: open pdf and analyse ---
151+ PdfDocument document = PdfReader . Open ( targetPath ) ;
152+ Assert . IsTrue ( document . Pages . Count > 0 ) ;
153+
154+ HashSet < string > usedFonts = new HashSet < string > ( ) ;
155+ Dictionary < string , bool > embeddedStatus = new Dictionary < string , bool > ( ) ;
156+
157+ foreach ( var page in document . Pages . Cast < PdfPage > ( ) )
158+ {
159+ var resources = page . Elements . GetDictionary ( "/Resources" ) ;
160+ if ( resources == null ) continue ;
161+
162+ var fonts = resources . Elements . GetDictionary ( "/Font" ) ;
163+ if ( fonts == null ) continue ;
164+
165+ foreach ( var entry in fonts . Elements )
166+ {
167+ var reference = entry . Value as PdfReference ;
168+ if ( reference == null ) continue ;
169+
170+ var fontDict = document . Internals . GetObject ( reference . ObjectID ) as PdfDictionary ;
171+ if ( fontDict == null ) continue ;
172+
173+ var fontDescriptor = fontDict . Elements . GetDictionary ( "/FontDescriptor" ) ;
174+ Assert . IsNotNull ( fontDescriptor , $ "FontDescriptor missing for { entry . Key } .") ;
175+
176+ string fontName = fontDescriptor . Elements . GetString ( "/FontName" ) ? . TrimStart ( '/' ) ;
177+ usedFonts . Add ( fontName ) ;
178+
179+ bool embedded =
180+ fontDescriptor . Elements . ContainsKey ( "/FontFile" ) ||
181+ fontDescriptor . Elements . ContainsKey ( "/FontFile2" ) ||
182+ fontDescriptor . Elements . ContainsKey ( "/FontFile3" ) ;
183+
184+ embeddedStatus [ fontName ] = embedded ;
185+ }
186+ }
187+
188+ // not embedded fonts
189+ var notEmbedded = embeddedStatus . Where ( x => ! x . Value ) . Select ( x => x . Key ) . ToList ( ) ;
190+
191+ Assert . IsFalse (
192+ notEmbedded . Any ( ) ,
193+ "These fonts that are not embedded in PDF: " + string . Join ( ", " , notEmbedded ) ) ;
194+ } // !VeraPdfLikeFontEmbeddingTest()
195+
196+
126197 [ TestMethod ]
127198 public async Task BasicSaveExampleAsStream ( )
128199 {
0 commit comments