VintaSoft Imaging .NET SDK 14.1: Документация для .NET разработчика
Vintasoft.Imaging.Pdf Namespace / PdfDocument Class / ConvertDocument Methods / ConvertDocument(PdfDocumentConformance) Method
Синтаксис Exceptions Ремарки Example Требования Смотрите также
В этом разделе
    ConvertDocument(PdfDocumentConformance) Метод (PdfDocument)
    В этом разделе
    Преобразует PDF документ в соответствие с указанным форматом.
    Синтаксис
    'Declaration
    
    Public Overloads Sub ConvertDocument( _
    ByVal documentConformance
    Соответствие PDF документа.
    As PdfDocumentConformance _
    )
    public: void ConvertDocument(
    PdfDocumentConformance documentConformance
    )

    Parameters

    documentConformance
    Соответствие PDF документа.
    Исключения
    ИсключениеОписание
    Выбрасывается, если преобразование не удалось.
    Выбрасывается, если у PDF документа нет источника.
    Выбрасывается, если documentConformance равно Undefined.
    Выбрасывается, если преобразование в documentConformance сейчас не поддерживается.
    Ремарки

    Метод поддерживает только следующие форматы: 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 или PdfA3bConverter можно использовать, если PDF документ необходимо преобразовать с пользовательскими настройками (профили ICC, сжатие и т. д.).

    Пример

    Вот пример, показывающий, как преобразовать PDF документ в соответствии со спецификацией PDF/A-1b:

    
    ''' <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));
            }
        }
    }
    
    

    Требования

    Целевые платформы: .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также