Skip to content

Commit 5842a90

Browse files
committed
1005969-How to convert PDF to PDF/A‑2A documents
1 parent c28924a commit 5842a90

File tree

7 files changed

+184
-0
lines changed

7 files changed

+184
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="Convert-PDF-to-PDFA2A-conformance-document/Convert-PDF-to-PDFA2A-conformance-document.csproj" Id="5a06001d-287a-4b5f-a79e-52ad2871bf43" />
3+
</Solution>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{5A06001D-287A-4B5F-A79E-52AD2871BF43}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>Convert_PDF_to_PDFA2A_conformance_document</RootNamespace>
10+
<AssemblyName>Convert-PDF-to-PDFA2A-conformance-document</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="Syncfusion.Compression.Base, Version=32.2462.8.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
37+
<HintPath>..\packages\Syncfusion.Compression.Base.32.2.8\lib\net462\Syncfusion.Compression.Base.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Syncfusion.Licensing, Version=32.2462.8.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
40+
<HintPath>..\packages\Syncfusion.Licensing.32.2.8\lib\net462\Syncfusion.Licensing.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Syncfusion.Pdf.Base, Version=32.2462.8.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Syncfusion.Pdf.WinForms.32.2.8\lib\net462\Syncfusion.Pdf.Base.dll</HintPath>
44+
</Reference>
45+
<Reference Include="System" />
46+
<Reference Include="System.Core" />
47+
<Reference Include="System.Xml.Linq" />
48+
<Reference Include="System.Data.DataSetExtensions" />
49+
<Reference Include="Microsoft.CSharp" />
50+
<Reference Include="System.Data" />
51+
<Reference Include="System.Net.Http" />
52+
<Reference Include="System.Xml" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<Compile Include="Program.cs" />
56+
<Compile Include="Properties\AssemblyInfo.cs" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<None Include="App.config" />
60+
<None Include="packages.config" />
61+
</ItemGroup>
62+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
63+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using Syncfusion.Pdf;
2+
using Syncfusion.Pdf.Parsing;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
6+
namespace Convert_PDF_to_PDFA2A_conformance_document
7+
{
8+
internal class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
13+
var numPages = 0;
14+
//Set the PDF merge options.
15+
var pdfMergeOptions = new PdfMergeOptions
16+
{
17+
//Enable the Merge Accessibility Tags.
18+
MergeAccessibilityTags = true,
19+
OptimizeResources = true
20+
};
21+
//Create an array to store the PDF document streams.
22+
var streamInArray = new Stream[]
23+
{
24+
File.OpenRead(Path.GetFullPath("Input.pdf")),
25+
File.OpenRead(Path.GetFullPath("Input.pdf"))
26+
};
27+
//Create a list to store the PDF document streams.
28+
var streamInList = new List<MemoryStream>();
29+
30+
foreach (var stream in streamInArray)
31+
{
32+
stream.Position = 0;
33+
//Load the PDF document.
34+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);
35+
//Set the compression options.
36+
loadedDocument.CompressionOptions = new PdfCompressionOptions()
37+
{
38+
CompressImages = false,
39+
OptimizeFont = false,
40+
OptimizePageContents = false,
41+
RemoveMetadata = true
42+
};
43+
//Save the document into stream.
44+
MemoryStream ms = new MemoryStream();
45+
loadedDocument.Save(ms);
46+
loadedDocument.Close(true);
47+
streamInList.Add(new MemoryStream(ms.ToArray()));
48+
}
49+
50+
51+
using (var intermediatePdfStream = new MemoryStream())
52+
{
53+
//Create a new PDF document with PDF/A-2A conformance level.
54+
using (var pdfDocument = new PdfDocument(PdfConformanceLevel.Pdf_A2A))
55+
{
56+
//Set the AutoTag property to true.
57+
pdfDocument.AutoTag = true;
58+
//Set the PDF version to 1.7.
59+
pdfDocument.FileStructure.Version = PdfVersion.Version1_7;
60+
//Merge the PDF documents into a single PDF document.
61+
PdfDocumentBase.Merge(pdfDocument, pdfMergeOptions, streamInList.ToArray());
62+
numPages = pdfDocument.Pages.Count;
63+
//Save the document into stream.
64+
pdfDocument.Save(Path.GetFullPath("Output/Output.pdf"));
65+
//Close the document.
66+
pdfDocument.Close(true);
67+
}
68+
}
69+
70+
71+
}
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Convert-PDF-to-PDFA2A-conformance-document")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Convert-PDF-to-PDFA2A-conformance-document")]
13+
[assembly: AssemblyCopyright("Copyright © 2026")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("5a06001d-287a-4b5f-a79e-52ad2871bf43")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
[assembly: AssemblyVersion("1.0.0.0")]
33+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Syncfusion.Compression.Base" version="32.2.8" targetFramework="net472" />
4+
<package id="Syncfusion.Licensing" version="32.2.8" targetFramework="net472" />
5+
<package id="Syncfusion.Pdf.WinForms" version="32.2.8" targetFramework="net472" />
6+
</packages>

0 commit comments

Comments
 (0)