Skip to content

Commit 7bcad52

Browse files
Merge pull request #277 from SyncfusionExamples/1053818
1053818: Created sample project for PDF/A-1B PDF/A-2B PDF/A-3B PDF/A-4
2 parents 53d5a7d + bfda52a commit 7bcad52

16 files changed

Lines changed: 278 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="Convert-PDF-to-PDF-A-2b/Convert-PDF-to-PDF-A-2b.csproj" />
3+
</Solution>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Convert_PDF_to_PDF_A_2b</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Imaging.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Input.pdf">
17+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
21+
</Project>
Binary file not shown.

PDF Conformance/Convert-PDF-to-PDF-A-2b/.NET/Convert-PDF-to-PDF-A-2b/Output/.gitkeep

Whitespace-only changes.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using SkiaSharp;
2+
using Syncfusion.Pdf;
3+
using Syncfusion.Pdf.Graphics;
4+
using Syncfusion.Pdf.Parsing;
5+
6+
// Load the PDF document
7+
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
8+
{
9+
// Handle font substitution during PDF/A conversion
10+
loadedDocument.SubstituteFont += LoadedDocument_SubstituteFont;
11+
// Convert the document to PDF/A-2B format
12+
loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A2B);
13+
// Save the PDF document
14+
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
15+
}
16+
17+
// Event handler to substitute missing fonts during conversion
18+
void LoadedDocument_SubstituteFont(object sender, PdfFontEventArgs args)
19+
{
20+
// Extract the font name (ignoring style suffixes)
21+
string fontName = args.FontName.Split(',')[0];
22+
// Determine the font style
23+
PdfFontStyle fontStyle = args.FontStyle;
24+
SKFontStyle skFontStyle = SKFontStyle.Normal;
25+
// Map PDF font styles to SkiaSharp font styles
26+
if (fontStyle == PdfFontStyle.Bold)
27+
skFontStyle = SKFontStyle.Bold;
28+
else if (fontStyle == PdfFontStyle.Italic)
29+
skFontStyle = SKFontStyle.Italic;
30+
else if (fontStyle == (PdfFontStyle.Bold | PdfFontStyle.Italic))
31+
skFontStyle = SKFontStyle.BoldItalic;
32+
// Load the typeface using SkiaSharp
33+
SKTypeface typeface = SKTypeface.FromFamilyName(fontName, skFontStyle);
34+
SKStreamAsset typeFaceStream = typeface.OpenStream();
35+
36+
// Create a memory stream from the font data
37+
MemoryStream memoryStream = null;
38+
if (typeFaceStream != null && typeFaceStream.Length > 0)
39+
{
40+
byte[] fontData = new byte[typeFaceStream.Length];
41+
typeFaceStream.Read(fontData, fontData.Length);
42+
typeFaceStream.Dispose();
43+
memoryStream = new MemoryStream(fontData);
44+
}
45+
// Assign the font stream to the event arguments
46+
args.FontStream = memoryStream;
47+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="Convert-PDF-to-PDF-A-3b/Convert-PDF-to-PDF-A-3b.csproj" />
3+
</Solution>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Convert_PDF_to_PDF_A_3b</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Imaging.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Input.pdf">
17+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Data\ZUGFeRD_invoice.xml">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Binary file not shown.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<dataroot>
3+
<Report>
4+
<ProductID>CA-1098</ProductID>
5+
<Product>AWC Logo Cap</Product>
6+
<Price>8.99</Price>
7+
<Quantity></Quantity>
8+
<TotalPrice></TotalPrice>
9+
</Report>
10+
<Report>
11+
<ProductID>LJ-0192-M</ProductID>
12+
<Product>Long-Sleeve Logo Jersey, M</Product>
13+
<Price>49.99</Price>
14+
<Quantity></Quantity>
15+
<TotalPrice></TotalPrice>
16+
</Report>
17+
<Report>
18+
<ProductID>SO-B909-M</ProductID>
19+
<Product>Mountain Bike Socks, M</Product>
20+
<Price>9.50</Price>
21+
<Quantity></Quantity>
22+
<TotalPrice></TotalPrice>
23+
</Report>
24+
<Report>
25+
<ProductID>LJ-0192-M</ProductID>
26+
<Product>Long-Sleeve Logo Jersey, M</Product>
27+
<Price>49.99</Price>
28+
<Quantity></Quantity>
29+
<TotalPrice></TotalPrice>
30+
</Report>
31+
<Report>
32+
<ProductID>FK-5136</ProductID>
33+
<Product>ML Fork</Product>
34+
<Price>175.49</Price>
35+
<Quantity></Quantity>
36+
<TotalPrice></TotalPrice>
37+
</Report>
38+
<Report>
39+
<ProductID>HL-U509</ProductID>
40+
<Product>Sport-100 Helmet, Black</Product>
41+
<Price>34.99</Price>
42+
<Quantity></Quantity>
43+
<TotalPrice></TotalPrice>
44+
</Report>
45+
</dataroot>

PDF Conformance/Convert-PDF-to-PDF-A-3b/.NET/Convert-PDF-to-PDF-A-3b/Output/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)