Convert PDF to PDF/A
The code below shows you how to convert a PDF file to a PDF/A file.
It is recommended that you have already reviewed the Getting Started sample, since that includes Licensing and Framework initialization code required to make this sample run.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using SolidFramework.Converters;
using SolidFramework.Converters.Plumbing;
namespace CSharp_Tutorials
{
public static partial class Tutorials
{
public static bool ConvertPdfToPdfA(string pdfPath, string outputPath)
{
// Create a PdfToPdfAConverter
using (var converter = new PdfToPdfAConverter())
{
// Add the PDF file to convert
converter.AddSourceFile(pdfPath);
// Set the PDF/A mode to convert to
converter.ValidationMode = SolidFramework.Plumbing.ValidationMode.PdfA2B;
Console.WriteLine("Converting " + pdfPath + " to " + outputPath);
// Convert the file
var result = converter.ConvertTo(outputPath, true);
// Check if it was successful (PdfAError means it wasn't PDF/A but was fixed)
if (result != ConversionStatus.Success && result != ConversionStatus.PdfAError)
{
Console.WriteLine("Converting " + pdfPath + " to " + outputPath + " failed with status: " + result);
Console.WriteLine();
return false;
}
}
Console.WriteLine("Successfully converted " + pdfPath + " to " + outputPath);
Console.WriteLine();
return true;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Imports System
Imports SolidFramework.Converters
Imports SolidFramework.Converters.Plumbing
Namespace VBNet_Tutorials
Partial Module Tutorials
Function ConvertPdfToPdfA(ByVal pdfPath As String, ByVal outputPath As String) As Boolean
' Create a PdfToPdfAConverter
Using converter As PdfToPdfAConverter = New PdfToPdfAConverter()
' Add the PDF file to convert
converter.AddSourceFile(pdfPath)
' Set the PDF/A mode to convert to
converter.ValidationMode = SolidFramework.Plumbing.ValidationMode.PdfA2B
Console.WriteLine("Converting " & pdfPath & " to " & outputPath)
' Convert the file
Dim result As ConversionStatus = converter.ConvertTo(outputPath, True)
' Check if it was successful (PdfAError means it wasn't PDF/A but was fixed)
If result <> ConversionStatus.Success AndAlso result <> ConversionStatus.PdfAError Then
Console.WriteLine("Converting " & pdfPath & " to " & outputPath & " failed with status: " & result)
Console.WriteLine()
Return False
End If
End Using
Console.WriteLine("Successfully converted " & pdfPath & " to " & outputPath)
Console.WriteLine()
Return True
End Function
End Module
End Namespace
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "Tutorials.h"
using namespace SolidFramework::Converters::Plumbing;
using namespace SolidFramework::Converters;
bool ConvertPdfToPdfA(const wstring & pdfPath, const wstring & outputPath)
{
// Create a PdfToPdfAConverter
auto converter = make_shared<PdfToPdfAConverter>();
// Add the PDF file to convert
converter->AddSourceFile(pdfPath);
// Set the PDF/A mode to convert to
converter->SetValidationMode(SolidFramework::Plumbing::ValidationMode::PdfA2B);
wcout << L"Converting " << pdfPath << L" to " << outputPath << endl;
// Convert the file
auto result = converter->ConvertTo(outputPath, true);
// Check if it was successful (PdfAError means it wasn't PDF/A but was fixed)
if (result != ConversionStatus::Success && result != ConversionStatus::PdfAError)
{
wcout << L"Converting " << pdfPath << L" to " << outputPath << L" failed with status: " << (int)result << endl << endl;
return false;
}
wcout << L"Successfully converted " << pdfPath << L" to " << outputPath << endl << endl;
return true;
}