Skip to content

Commit feae334

Browse files
committed
version bump for ZUGFeRD.PDF
1 parent 7c9a9c4 commit feae334

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

ZUGFeRD.PDF.Test/SaveTests.cs

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
{

ZUGFeRD.PDF/ZUGFeRD.PDF.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ A special favor is the so-called XRechnung which is also supported by this libra
7878
<ItemGroup>
7979
<PackageReference Include="PDFsharp-extended" Version="1.2.0-preview-1" />
8080
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.9" />
81-
<PackageReference Include="ZUGFeRD-csharp" Version="18.0.0-beta1" />
81+
<PackageReference Include="ZUGFeRD-csharp" Version="18.0.0-beta3" />
8282
</ItemGroup>
8383

8484
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0' Or '$(TargetFramework)' == 'netstandard2.1' Or '$(TargetFramework)' == 'netstandard2.0'">

ZUGFeRD/ZUGFeRD.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net480;net8.0</TargetFrameworks>
4-
<Version>18.0.0-beta2</Version>
4+
<Version>18.0.0-beta3</Version>
55
<Authors>Stephan Stapel</Authors>
66
<Company>s2 industries</Company>
77
<Description>ZUGFeRD and it's successor Factur-X/ XRechnung are initiatives from German (respectively European) government to foster electronic invoices.

0 commit comments

Comments
 (0)