Convert PDF to PDF/A in C#
GdPicture enables converting PDF documents and images to PDF/A format.
Converting PDF to PDF/A
The GdPicturePDF
class is a quick and easy one-step operation for converting PDF documents into any of the PDF/A conformance levels.
Here’s the code for conversion:
// We assume GdPicture has been correctly installed and unlocked. using (GdPicturePDF gdpicturePDF = new GdPicturePDF()) { // Loading a PDF document to convert. GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", false); if (status == GdPictureStatus.OK) { // Providing the conversion to a PDF/A-1b-conforming document. status = gdpicturePDF.ConvertToPDFA("converted.pdf", PdfConversionConformance.PDF_A_1b, true, true); if (status == GdPictureStatus.OK) { MessageBox.Show("The PDF file has been converted successfully.", "Conversion to PDF/A Example", MessageBoxButtons.OK, MessageBoxIcon.Information); // Checking the conformance of the converted document. using (GdPicturePDF convertedPDF = new GdPicturePDF()) { status = convertedPDF.LoadFromFile("converted.pdf", false); if (status == GdPictureStatus.OK) { PdfConformance conf = convertedPDF.GetPDFAConformance(); MessageBox.Show("The conformance of newly created PDF is: " + conf.ToString(), "Conversion to PDF/A Example", MessageBoxButtons.OK, MessageBoxIcon.Information); } convertedPDF.CloseDocument(); // You can validate the resulting document using available PDF/A validators. } } else MessageBox.Show("The file can't be converted. Status: " + status.ToString(), "Conversion to PDF/A Example", MessageBoxButtons.OK, MessageBoxIcon.Error); gdpicturePDF.CloseDocument(); } else MessageBox.Show("The file can't be loaded. Status: " + status.ToString(), "Conversion to PDF/A Example", MessageBoxButtons.OK, MessageBoxIcon.Error); }
'We assume GdPicture has been correctly installed and unlocked. Using gdpicturePDF As GdPicturePDF = New GdPicturePDF() 'Loading a PDF document to convert. Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test.pdf", False) If status = GdPictureStatus.OK Then 'Providing the conversion to a PDF/A-1b-conforming document. status = gdpicturePDF.ConvertToPDFA("converted.pdf", PdfConversionConformance.PDF_A_1b, True, True) If status = GdPictureStatus.OK Then MessageBox.Show("The PDF file has been converted successfully.", "Conversion to PDF/A Example", MessageBoxButtons.OK, MessageBoxIcon.Information) 'Checking the conformance of the converted document. Using convertedPDF As GdPicturePDF = New GdPicturePDF() status = convertedPDF.LoadFromFile("converted.pdf", False) If status = GdPictureStatus.OK Then Dim conf As PdfConformance = convertedPDF.GetPDFAConformance() MessageBox.Show("The conformance of newly created PDF is: " + conf.ToString(), "Conversion to PDF/A Example", MessageBoxButtons.OK, MessageBoxIcon.Information) End If convertedPDF.CloseDocument() 'You can validate the resulting document using available PDF/A validators. End Using Else MessageBox.Show("The file can't be converted. Status: " + status.ToString(), "Conversion to PDF/A Example", MessageBoxButtons.OK, MessageBoxIcon.Error) End If gdpicturePDF.CloseDocument() Else MessageBox.Show("The file can't be loaded. Status: " + status.ToString(), "Conversion to PDF/A Example", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Using
Converting Images to PDF/A
The GdPictureDocumentConverter
class is a quick and easy one-step operation for converting [TIFF][tiff-to-pdf], [JPG][jpg-to-pdf], [PNG][png-to-pdf], [SVG][svg-to-pdf], [BMP][bmp-to-pdf], and [50 other image formats][file type support] into any of the PDF/A conformance levels.
Here’s the code for conversion:
// We assume GdPicture has been correctly installed and unlocked. using (GdPictureDocumentConverter oConverter = new GdPictureDocumentConverter()) { // Select your source image and its image format (TIFF, JPG, PNG, SVG, and 50+ more). GdPictureStatus status = oConverter.LoadFromFile("input.png", GdPicture14.DocumentFormat.DocumentFormatPNG); if (status == GdPictureStatus.OK) { MessageBox.Show("The file has been loaded successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information); // Select the conformance of the resulting PDF document. status = oConverter.SaveAsPDF("output.pdf", PdfConformance.PDF_A_1b); if (status == GdPictureStatus.OK) { MessageBox.Show("The file has been saved successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("The file has failed to save. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("The file has failed to load. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
'We assume GdPicture has been correctly installed and unlocked. Using oConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter() 'Select your source image and its image format (TIFF, JPG, PNG, SVG, and 50+ more). Dim status As GdPictureStatus = oConverter.LoadFromFile("input.png", GdPicture14.DocumentFormat.DocumentFormatPNG) If status = GdPictureStatus.OK Then MessageBox.Show("The file has been loaded successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information) 'Select the conformance of the resulting PDF document. status = oConverter.SaveAsPDF("output.pdf", PdfConformance.PDF_A_1b) If status = GdPictureStatus.OK Then MessageBox.Show("The file has been saved successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information) Else MessageBox.Show("The file has failed to save. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error) End If Else MessageBox.Show("The file has failed to load. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Using
Converting Office Files to PDF/A
The GdPictureDocumentConverter
class is a quick and easy one-step operation for converting Word ([DOCX][word-to-pdf] and [DOC][word-to-pdf]), Excel ([XLSX][excel-to-pdf] and [XLS][excel-to-pdf]), and PowerPoint ([PPTX][powerpoint-to-pdf] and [PPT][powerpoint-to-pdf]) files into any of the PDF/A conformance levels.
Here’s the code for conversion:
// We assume GdPicture has been correctly installed and unlocked. using (GdPictureDocumentConverter oConverter = new GdPictureDocumentConverter()) { // Select your source document and its document format (DOCX, DOC, XLSX, XLS, PPTX, PPT). GdPictureStatus status = oConverter.LoadFromFile("input.docx", GdPicture14.DocumentFormat.DocumentFormatDOCX); if (status == GdPictureStatus.OK) { MessageBox.Show("The file has been loaded successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information); // Select the conformance of the resulting PDF document. status = oConverter.SaveAsPDF("output.pdf", PdfConformance.PDF); if (status == GdPictureStatus.OK) { MessageBox.Show("The file has been saved successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("The file has failed to save. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("The file has failed to load. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
'We assume GdPicture has been correctly installed and unlocked. Using oConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter() 'Select your source document and its document format (DOCX, DOC, XLSX, XLS, PPTX, PPT). Dim status As GdPictureStatus = oConverter.LoadFromFile("input.docx", GdPicture14.DocumentFormat.DocumentFormatDOCX) If status = GdPictureStatus.OK Then MessageBox.Show("The file has been loaded successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information) 'Select the conformance of the resulting PDF document. status = oConverter.SaveAsPDF("output.pdf", PdfConformance.PDF) If status = GdPictureStatus.OK Then MessageBox.Show("The file has been saved successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information) Else MessageBox.Show("The file has failed to save. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error) End If Else MessageBox.Show("The file has failed to load. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Using