Convert PDF to PDF/A

The code below shows you how to convert a PDF file to a PDF/A file.

This sample requires a Professional license.

C#
using System;
using System.IO;
using SolidFramework.Converters.Plumbing;
using SolidFramework.Plumbing;
using SolidFramework.Imaging.Plumbing;
using SolidFramework.Converters;

namespace PDFtoPDFA
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Call your Solid Documents License
            SolidFramework.License.Import(@"C:\MyFolder\license.xml");

            // Set the location of your the file you want to convert
            string pdfPath = @"C:\YourFolder\yourpdf.pdf";

            // Set the file extension you are creating
            String PDFAPath = Path.ChangeExtension(pdfPath, "pdfa.pdf");

            //*PDF to PDFA*//           
            using (PdfToPdfAConverter converter = new PdfToPdfAConverter())
            {
                // Add files to convert. 
                converter.AddSourceFile(pdfPath);

                //Set the preferred conversion properties 

                // Select a PDF/A Validation mode
                converter.ValidationMode = ValidationMode.PdfA2B;  // All PDF/A options are supported

                // Set to validate only to false 
                converter.ValidateOnly = false;

                // Select the type of Image Compression
                converter.OcrImageCompression = ImageCompression.PreserveOriginal;

                // Apply Solid Documents Optical Character Recognition (OCR) for scanned files
                converter.OcrEngine = TextRecoveryEngine.SolidOCR;

                // Select the OCR language for the file
                converter.OcrLanguage = "de"; //Many languages are supported

                // Create a searchable Text Layer
                converter.OcrType = OcrType.CreateSearchableTextLayer;

                // Set the Directory you wan the file to be saved to
                converter.OutputDirectory = @"C:\MyFolder\";

                // Convert the file.
                converter.ConvertTo(PDFAPath, true);

                // Show the status of the PDF file in the Console Window
                SolidFramework.Converters.Plumbing.ConversionStatus status = converter.ConvertTo(PDFAPath, true);
                if (status != ConversionStatus.Success)
                {
                    Console.WriteLine(status);
                    Console.ReadKey();
                }
            }

        }
    }
}

C++
#include "stdafx.h"
#include "SolidFramework.h"

#include <iostream>
using  namespace std;

void DoProgress(SolidFramework::ProgressEventArgsPtr args)
{
    // Not implemented
}

void DoWarning(SolidFramework::WarningEventArgsPtr args)
{
    // Not implemented
}

class PdfToPdfAConverter : public SolidFramework::Converters::PdfToPdfAConverterBase
{
public:
    void FireProgress(SolidFramework::ProgressEventArgsPtr args) override { DoProgress(args); };
    void FireWarning(SolidFramework::WarningEventArgsPtr args) override { DoWarning(args); };
};

int _tmain(int argc, _TCHAR* argv[])
{
    // Enter your License code goes here
    SolidFramework::License::Import(L"C:\\MyFolder\\license.xml");

    // Create a PDF to Word Converter called converter
    PdfToPdfAConverter *converter = new PdfToPdfAConverter();

    SolidFramework::Converters::CustomData *pData = NULL;
    pData = new SolidFramework::Converters::CustomData();
    pData->Converter = converter;
    pData->Data = nullptr;
    converter->setCustomData(pData);

    // Add the PDF file to convert.
    converter->AddSourceFile(L"C:\\YourFolder\\yourpdf.pdf");
    converter->setOutputDirectory(L"C:\\MyFolder\\");

    // Select a PDF/A Validation mode
    converter->setValidationMode(SolidFramework::Plumbing::ValidationMode::PdfA2B); // All PDF/A options are supported

    // Set to validate only to false 
    converter->setValidateOnly(false);

    // Select the type of Image Compression
    converter->setOcrImageCompression(SolidFramework::Imaging::Plumbing::ImageCompression::PreserveOriginal);

    // Apply Solid Documents Optical Character Recognition (OCR) for scanned files
    converter->setOcrEngine(SolidFramework::Converters::Plumbing::TextRecoveryEngine::SolidOCR);

    // Select the OCR language for the file
    converter->setOcrLanguage( L"de"); //Many languages are supported

    // Create a searchable Text Layer
    converter->setOcrType(SolidFramework::Converters::Plumbing::OcrType::CreateSearchableTextLayer);   

    //Start the Conversion
    cout << "Starting conversion." << endl; converter->Convert();

    SolidFramework::Converters::Plumbing::ConversionStatus status = converter->getResults()->getItem(0)->getStatus();
    if (status != SolidFramework::Converters::Plumbing::ConversionStatus::Success)
    {
        cout << "Conversion failed." << endl;
    }
    else
    {
        cout << "Conversion succeeded." << endl; } converter->Dispose();

    cout << "Press <Enter> to exit." << endl;
    cin.get();

    return 0;
}
VB.Net
Imports System.IO
Imports SolidFramework.Converters.Plumbing
Imports SolidFramework.Plumbing
Imports SolidFramework

Module PDFtoPDFA

    Sub Main()

        ' Call your Solid Documents License
        SolidFramework.License.Import("C:\MyFolder\license.xml")

        'Define a variable for your source file
        Dim sPdfPath As String

        ' Define a String for the output file
        Dim pdfaPath As String

        ' Define your Solid Framework Converter
        Dim myConverter As SolidFramework.Converters.PdfToPdfAConverter

        ' Set your file path 
        sPdfPath = "C:\YourFolder\filepdf.pdf"

        ' Set your output file and location
        pdfaPath = Path.ChangeExtension(sPdfPath, ".pdfa.pdf")

        ' Set the converter
        myConverter = New SolidFramework.Converters.PdfToPdfAConverter

        'Set the preferred conversion properties 

        ' Add files to convert. 
        myConverter.AddSourceFile(sPdfPath)

        ' Make the Converted File Searchable
        myConverter.ValidationMode = ValidationMode.PdfA2B ' All other PDFA options are available

        ' Set to validate only to false 
        myConverter.ValidateOnly = False

        ' Select the type of Image Compression
        myConverter.OcrImageCompression = Imaging.Plumbing.ImageCompression.PreserveOriginal

        ' Apply Solid Documents Optical Character Recognition (OCR) for scanned files
        myConverter.OcrEngine = TextRecoveryEngine.SolidOCR

        ' Select the OCR language for the File
        myConverter.OcrLanguage = "de"

        ' Create a searchable Text Layer
        myConverter.OcrType = OcrType.CreateSearchableTextLayer

        ' Convert the File.
        myConverter.ConvertTo(pdfaPath, True)

        ' Clean up
        myConverter.Dispose()

    End Sub

End Module