VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
В этом разделе
    PDF: Конвертирование PDF документа
    В этом разделе
    VintaSoft Imaging .NET SDK позволяет конвертировать PDF документ в соответствии со следующими PDF-стандартами:
    Вот C#/VB.NET код, который демонстрирует, как сконвертировать 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 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();
        
        // create the PDF/A-1b converter
        Vintasoft.Imaging.Pdf.Processing.PdfA.PdfA1bConverter converter = 
            new Vintasoft.Imaging.Pdf.Processing.PdfA.PdfA1bConverter();
        converter.LzwFixupCompression = Vintasoft.Imaging.Pdf.PdfCompression.Zip;
        // converter.OutputIntentDestIccProfile = ...
        
        // execute the conversion
        System.Console.WriteLine("Conversion...");
        Vintasoft.Imaging.Processing.ConversionProfileResult result = 
            converter.Convert(pdfFilename, outputPdfFilename, new Vintasoft.Imaging.Processing.ProcessingState());
    
        // if PDF document is converted successfully
        if (result.IsSuccessful)
        {
            System.Console.WriteLine("Document converted to PDF/A-1b.");
        }
        // if PDF document is NOT converted
        else
        {
            if (!sameFile)
                System.IO.File.Delete(outputPdfFilename);
    
            throw result.CreateConversionException();
        }
    }
    
    ''' <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()
    
        ' create the PDF/A-1b converter
        Dim converter As New Vintasoft.Imaging.Pdf.Processing.PdfA.PdfA1bConverter()
        converter.LzwFixupCompression = Vintasoft.Imaging.Pdf.PdfCompression.Zip
        ' converter.OutputIntentDestIccProfile = ...
    
        ' execute the conversion
        System.Console.WriteLine("Conversion...")
        Dim result As Vintasoft.Imaging.Processing.ConversionProfileResult = converter.Convert(pdfFilename, outputPdfFilename, New Vintasoft.Imaging.Processing.ProcessingState())
    
        ' if PDF document is converted successfully
        If result.IsSuccessful Then
            System.Console.WriteLine("Document converted to PDF/A-1b.")
        Else
            ' if PDF document is NOT converted
            If Not sameFile Then
                System.IO.File.Delete(outputPdfFilename)
            End If
    
            Throw result.CreateConversionException()
        End If
    End Sub
    


    Вот C#/VB.NET код, который демонстрирует, как сконвертировать PDF документ в соответствие со стандартом PDF/A-1b, и показать подробный отчет о конвертации:
    /// <summary>
    /// Converts a PDF document to conformance with PDF/A-1b specification and
    /// shows the detailed result of conversion.
    /// </summary>
    /// <param name="pdfFilename">The filename of source PDF document.</param>
    /// <param name="outputPdfFilename">The filename of output PDF document.</param>
    public static void ConvertDocumentToPdfA1bDetalied(
        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();
    
        // create the PDF/A-1b converter
        Vintasoft.Imaging.Pdf.Processing.PdfA.PdfA1bConverter converter = 
            new Vintasoft.Imaging.Pdf.Processing.PdfA.PdfA1bConverter();
        converter.LzwFixupCompression = Vintasoft.Imaging.Pdf.PdfCompression.Zip;
        // converter.OutputIntentDestIccProfile = ...
    
        using (Vintasoft.Imaging.Processing.ProcessingState processingState = 
            new Vintasoft.Imaging.Processing.ProcessingState())
        {
            // subscribe to the events for monitoring the progress
            processingState.Progress += new System.EventHandler<Vintasoft.Imaging.ProgressEventArgs>(
                convertProcessingState_Progress);
    
            // execute the conversion
            Vintasoft.Imaging.Processing.ConversionProfileResult result = 
                converter.Convert(pdfFilename, outputPdfFilename, processingState);
            System.Console.WriteLine("finished.");
    
            // if PDF document is converted successfully
            if (result.IsSuccessful)
            {
                System.Console.WriteLine("Document converted to PDF/A-1b.");
            }
            // if PDF document is NOT converted
            else
            {
                if (!sameFile)
                    System.IO.File.Delete(outputPdfFilename);
    
                System.Console.WriteLine("Cannot convert document to PDF/A-1b, unsolved problems:");
                // for each activated trigger
                foreach (Vintasoft.Imaging.Processing.IProcessingCommandInfo 
                    command in result.ActivatedTriggers.Keys)
                {
                    // output information about activated trigger
                    System.Console.WriteLine(string.Format("  {0} ({1} matches)",
                        command,
                        result.ActivatedTriggers[command].Count));
                }
            }
        }
    }
    
    /// <summary>
    /// Handles the Progress event of the ProcessingState.
    /// </summary>
    static void convertProcessingState_Progress(object sender, Vintasoft.Imaging.ProgressEventArgs e)
    {
        System.Console.CursorLeft = 0;
        System.Console.Write(string.Format("Conversion {0}%...", e.Progress));
    }
    
    ''' <summary>
    ''' Converts a PDF document to conformance with PDF/A-1b specification and
    ''' shows the detailed result of conversion.
    ''' </summary>
    ''' <param name="pdfFilename">The filename of source PDF document.</param>
    ''' <param name="outputPdfFilename">The filename of output PDF document.</param>
    Public Shared Sub ConvertDocumentToPdfA1bDetalied(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()
    
        ' create the PDF/A-1b converter
        Dim converter As New Vintasoft.Imaging.Pdf.Processing.PdfA.PdfA1bConverter()
        converter.LzwFixupCompression = Vintasoft.Imaging.Pdf.PdfCompression.Zip
        ' converter.OutputIntentDestIccProfile = ...
    
        Using processingState As New Vintasoft.Imaging.Processing.ProcessingState()
            ' subscribe to the events for monitoring the progress
            AddHandler processingState.Progress, New System.EventHandler(Of Vintasoft.Imaging.ProgressEventArgs)(AddressOf convertProcessingState_Progress)
    
            ' execute the conversion
            Dim result As Vintasoft.Imaging.Processing.ConversionProfileResult = converter.Convert(pdfFilename, outputPdfFilename, processingState)
            System.Console.WriteLine("finished.")
    
            ' if PDF document is converted successfully
            If result.IsSuccessful Then
                System.Console.WriteLine("Document converted to PDF/A-1b.")
            Else
                ' if PDF document is NOT converted
                If Not sameFile Then
                    System.IO.File.Delete(outputPdfFilename)
                End If
    
                System.Console.WriteLine("Cannot convert document to PDF/A-1b, unsolved problems:")
                ' for each activated trigger
                For Each command As Vintasoft.Imaging.Processing.IProcessingCommandInfo In result.ActivatedTriggers.Keys
                    ' output information about activated trigger
                    System.Console.WriteLine(String.Format("  {0} ({1} matches)", command, result.ActivatedTriggers(command).Count))
                Next
            End If
        End Using
    End Sub
    
    ''' <summary>
    ''' Handles the Progress event of the ProcessingState.
    ''' </summary>
    Private Shared Sub convertProcessingState_Progress(sender As Object, e As Vintasoft.Imaging.ProgressEventArgs)
        System.Console.CursorLeft = 0
        System.Console.Write(String.Format("Conversion {0}%...", e.Progress))
    End Sub