The following example shows the most common use case for converting PDF document to PDF/A. The source PDF file is loaded from a current folder. The converted file is saved to the same folder.
usingSystem;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Create a converter for the PDF filevarconverter=newPdfToPdfAConverter("business-plan.pdf");// Convert PDF to PDF/Aconverter.Convert("archived.pdf");
ImportsSystemImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Create a converter from file path
DimconverterAsNewPdfToPdfAConverter("business-plan.pdf")' Convert PDF to PDF/A
converter.Convert("archived.pdf")EndSubEndModule
openSystemopenGroupDocs.Conversion.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Create a converter from file path
letconverter=newPdfToPdfAConverter("business-plan.pdf")// Convert PDF to PDF/A
converter.Convert("archived.pdf")0
This section covers only the main scenarious you also reffer to the API references for the PdfLoadOptions for a complete list of options that you can specify.
Convert Protected PDF to PDF/A
The following example shows how to convert protected PDF file and save it to unprotected PDF/A file.
In case you do not specify password for protected document PasswordRequiredException is going to be thrown.
usingSystem;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply licenseLicense.Set(publicKey,privateKey);// Provide password through load optionsvarconverter=newPdfToPdfAConverter("protected.pdf",options=>{options.Password="12345";});// Convert PDF to PDF/Aconverter.Convert("not-protected.pdf");
ImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply license
License.Set(publicKey,privateKey)' Provide password through load options
DimconverterAsNewPdfToPdfAConverter("protected.pdf",Sub(options)options.Password="12345"EndSub)' Convert PDF to PDF/A
converter.Convert("not-protected.pdf")EndSubEndModule
openSystemopenGroupDocs.Conversion.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply license
License.Set(publicKey,privateKey)// Provide password through load options
letconverter=newPdfToPdfAConverter("protected.pdf",funoptions->options.Password<-"12345")// Convert PDF to PDF/A
converter.Convert("not-protected.pdf")0
Convert PDF with Annotations to PDF/A without Annotations
By default, annotations are added to the output PDF file, see this with-annotations.pdf (text HOME BASED PROFESSIONAL SERVICES is highlighted) as an example of PDF file with annotations.
The following example shows how to convert a PDF file that contains annotations and save a PDF/A file without annotations.
usingSystem;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply licenseLicense.Set(publicKey,privateKey);// Hide annotations using HidePdfAnnotationsvarconverter=newPdfToPdfAConverter("with-annotations.pdf",options=>{options.HidePdfAnnotations=true;});// Convert PDF to PDF/Aconverter.Convert("no-annotations.pdf");
ImportsSystemImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKeyAsString=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKeyAsString=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply license
License.Set(publicKey,privateKey)' Hide annotations using HidePdfAnnotations
DimconverterAsNewPdfToPdfAConverter("with-annotations.pdf",Sub(options)options.HidePdfAnnotations=TrueEndSub)' Convert PDF to PDF/A
converter.Convert("no-annotations.pdf")EndSubEndModule
openSystemopenGroupDocs.Conversion.LowCode[<EntryPoint>]letmainargv=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply license
License.Set(publicKey,privateKey)// Hide annotations using HidePdfAnnotations
letconverter=newPdfToPdfAConverter("with-annotations.pdf",funoptions->options.HidePdfAnnotations<-true)// Convert PDF to PDF/A
converter.Convert("no-annotations.pdf")0//returnanintegerexitcode
The examples in this section shows how you can adjust the output using PdfConvertOptions.
Convert Specific PDF Pages to PDF/A
To convert only a portion of the document instead of all pages. You can specify which pages to include in the output PDF using the Pages property of PdfConvertOptions class.
As an alternative you can use PageNumber to specify the page number to start conversion from and PagesCount to set number of pages to convert starting from PageNumber.
The following example shows how to convert the first three pages of a PDF file to PDF/A:
usingSystem;usingSystem.Collections.Generic;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply licenseLicense.Set(publicKey,privateKey);// Create the convertervarconverter=newPdfToPdfAConverter("business-plan.pdf");// Save first three pages to PDF/Aconverter.Convert("pages-1-2-3.pdf",(convertOptions)=>{convertOptions.Pages=newList<int>{1,2,3};});
ImportsSystemImportsSystem.Collections.GenericImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKeyAsString=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKeyAsString=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply license
License.Set(publicKey,privateKey)' Create the converter
DimconverterAsNewPdfToPdfAConverter("business-plan.pdf")' Save first three pages to PDF/A
converter.Convert("pages-1-2-3.pdf",Sub(convertOptions)convertOptions.Pages=NewList(OfInteger)From{1,2,3}EndSub)EndSubEndModule
openSystemopenSystem.Collections.GenericopenGroupDocs.Conversion.LowCode[<EntryPoint>]letmainargv=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply license
License.Set(publicKey,privateKey)// Create the converter
letconverter=newPdfToPdfAConverter("business-plan.pdf")// Save first three pages to PDF/A
converter.Convert("pages-1-2-3.pdf",funconvertOptions->convertOptions.Pages<-List<int>([1;2;3]))0//returnexitcode