Convert to PDFA

Create PDF/A compliant PDFs. The action lets you transform PDF documents into PDF/A standardized PDF files. Choose from a predefined list compliance profile based on your requirement.

It may well happen that it is not possible to convert a given PDF to the PDF/A format. The conversion to Compliance Level A is most critical, as it requires tagging. Tags provide a logical structure that allows the contents of an image to be described to the visually impaired. Adding tagging information without prior knowledge about the input file’s structure and content is impossible. In which case an exception is thrown.

Code Samples

Try the API in the language you prefer

  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
// create createPdfA object
var createPdfA = new CreatePdfA()
{
    // document
    Document = new Document()
    {
        DocData = File.ReadAllBytes("myPdf.pdf"),
        Name = "myPdf.pdf",
    },
    // action
    PdfAAction = new PdfAAction()
    {
        Compliance = PdfAActionCompliance.PdfA2b,
    }
};

// create PDF/A
var res = await Pdf4meClient.Pdf4me.Instance.PdfAClient.PdfAAsync(createPdfA);

// extract the PDF/A and write it to disk
byte[] pdfA = res.Document.DocData;
File.WriteAllBytes("pdfA.pdf", pdfA);
// setup the pdfAClient
PdfAClient pdfAClient = new PdfAClient(pdf4meClient);

// create createPdfA object
CreatePdfA createPdfA = new CreatePdfA();
// document
Document document = new Document();
document.setDocData(Files.readAllBytes(Paths.get("myPdf.pdf")));
createPdfA.setDocument(document);
// action
PdfAAction pdfAAction = new PdfAAction();
pdfAAction.setCompliance(ComplianceEnum.PDFA2B);
createPdfA.setPdfAAction(pdfAAction);

// create PDF/A
CreatePdfARes res = pdfAClient.pdfA(createPdfA);

// extracting the generated PDF and writing it to disk
byte[] pdfA = res.getDocument().getDocData();
FileUtils.writeByteArrayToFile(new File("pdfA.pdf"), pdfA);
// create pdf4meClient
const pdf4meClient = pdf4me.createClient('YOUR API KEY')

// create createPdfA object
const createPdfAReq = {
  // document
  document: {
    docData: fs.readFileSync(path.join(__dirname, 'myPdf.pdf')).toString('base64'),
  },
  // action
  pdfAAction: {
    compliance: 'pdfA2b',
  },
}

// create PDF/A
pdf4meClient.pdfA(createPdfAReq)
  .then(function(pdfARes) {
    // extract the PDF/A and writing it to disk
    const pdfDocument = Buffer.from(pdfARes.document.docData, 'base64')
    fs.writeFileSync(path.join(__dirname, 'pdfA_result.pdf'), pdfDocument)
  })
  .catch(error => {
    console.log(error)
    process.exit(1)
  })
# setup the pdfA_client
pdfA_client = PdfAClient(pdf4me_client)

# create the create_pdfA object
create_pdfA = CreatePdfA(
    # document
    document=Document(
        doc_data=FileReader().get_file_data('myPdf.pdf')
    ),
    # action
    pdf_a_action=PdfAAction(
        compliance='pdfA2b'
    )
)

# conversion to PDF/A
res = pdfA_client.pdfA(create_pdfA=create_pdfA)

# extracting the generated PDF/A
pdfA = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('pdfA.pdf', 'wb') as f:
    f.write(pdfA)
// create createPdfA object
$create_pdfa = [
    // document
    "document" => [
        'name' => 'test.pdf',
        'docData' => $client->getFileData('myPdf.pdf')
    ],
    // action
    "pdfAAction" => [
        "compliance" => "pdfa2b"
    ]
];

// conversion to PDF/A with pdf_compliance specification
$res = $client->pdf4me()->pdfA($create_pdfa);

// extracting the generated PDF
$pdfA = base64_decode($createPdfA->document->docData);
// and writing it to file
file_put_contents('pdfA.pdf', $pdfA);
file_path = './myPdf.pdf'

    # create the pdfA object
    action = Pdf4me::PdfA.new(
      # document
      document: Pdf4me::Document.new(
        doc_data: Base64.encode64(File.open(file_path, 'rb', &:read))
      ),
      # action
      pdf_a_action: Pdf4me::PdfAAction.new(
        compliance: 'pdfA2b',
        allowDowngrade: true,
        allowUpgrade: true,
        outputIntentProfile: 'sRGBColorSpace',
        linearize: true
      )
    )
    response = action.run

    # saving the PDF/A document
    File.open('./pdfA.pdf', 'wb') do |f|
     f.write(Base64.decode64(response.document.doc_data))
    end

Important Links

Swagger: Create PDFA