ConvertDocument(PdfDocumentConformance) Method (PdfDocument)
In This Topic
Converts a PDF document to the conformance with the specified format.
Syntax
Parameters
- documentConformance
- The PDF document conformance.
Exceptions
Remarks
The method supports only the following formats: PDF/A-1b, PDF/A-2b, PDF/A-3b, PDF/A-1a, PDF/A-2a, PDF/A-3a, PDF/A-2u, PDF/A-3u, PDF/A-4, PDF/A-4e, PDF/A-4f.
PdfA1bConverter, PdfA2bConverter or PdfA3bConverter classes can be used if PDF document must be converted with custom settings (ICC profiles, compressions, etc).
Example
Here is an example that shows how to convert a PDF document to conformance with PDF/A-1b specification:
''' <summary>
''' Converts a PDF document to conformance with PDF/A-1b specification.
''' </summary>
''' <param name="pdfFilename">The filename of source PDF document.</param>
''' <param name="outputPdfFilename">The filename of output PDF document.</param>
Public Shared Sub ConvertDocumentToPdfA1b(pdfFilename As String, outputPdfFilename As String)
' determine that file must converted to the PDF/A-1b and saved back to the source file
Dim sameFile As Boolean = pdfFilename.ToUpperInvariant() = outputPdfFilename.ToUpperInvariant()
' if converted PDF document must NOT be saved to the source file
If Not sameFile Then
' copy the source file to the output file
System.IO.File.Copy(pdfFilename, outputPdfFilename, True)
End If
System.Console.WriteLine("Conversion...")
' open the output PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument(outputPdfFilename)
' convert the PDF document to conformance with the PDF/A-1b format
Try
document.ConvertDocument(Vintasoft.Imaging.Pdf.PdfDocumentConformance.PdfA_1b)
System.Console.WriteLine("Document converted to PDF/A-1b.")
Catch ex As System.Exception
If Not sameFile Then
System.IO.File.Delete(outputPdfFilename)
End If
System.Console.WriteLine(String.Format("Cannot convert document to PDF/A-1b: {0}", ex.Message))
End Try
End Using
End Sub
/// <summary>
/// Converts a PDF document to conformance with PDF/A-1b specification.
/// </summary>
/// <param name="pdfFilename">The filename of source PDF document.</param>
/// <param name="outputPdfFilename">The filename of output PDF document.</param>
public static void ConvertDocumentToPdfA1b(string pdfFilename, string outputPdfFilename)
{
// determine that file must converted to the PDF/A-1b and saved back to the source file
bool sameFile = pdfFilename.ToUpperInvariant() == outputPdfFilename.ToUpperInvariant();
// if converted PDF document must NOT be saved to the source file
if (!sameFile)
// copy the source file to the output file
System.IO.File.Copy(pdfFilename, outputPdfFilename, true);
System.Console.WriteLine("Conversion...");
// open the output PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(outputPdfFilename))
{
// convert the PDF document to conformance with the PDF/A-1b format
try
{
document.ConvertDocument(Vintasoft.Imaging.Pdf.PdfDocumentConformance.PdfA_1b);
System.Console.WriteLine("Document converted to PDF/A-1b.");
}
catch (System.Exception ex)
{
if (!sameFile)
System.IO.File.Delete(outputPdfFilename);
System.Console.WriteLine(string.Format("Cannot convert document to PDF/A-1b: {0}", ex.Message));
}
}
}
Requirements
Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
See Also