Convertir un documento PDF a un documento DOCX en C#
Categoría del blog: PDF ; Office ; .NET
12.04.2024
/// <summary>
/// Converts PDF document to a DOCX document.
/// </summary>
public static void ConvertPdfToDocx(string pdfFileName, string docxFileName)
{
    // create an image collection
    using (Vintasoft.Imaging.ImageCollection imageCollection = new Vintasoft.Imaging.ImageCollection())
    {
        // add PDF document to the image collection
        imageCollection.Add(pdfFileName);
        // save images of image collection (PDF pages) to a DOCX file
        imageCollection.SaveSync(docxFileName);
        // dispose images
        imageCollection.ClearAndDisposeItems();
    }
}
				
/// <summary>
/// Converts DOCX document to a PDF document.
/// </summary>
public static void ConvertDocxToPdf(string docxFileName, string pdfFileName)
{
    // create an image collection
    using (Vintasoft.Imaging.ImageCollection imageCollection = new Vintasoft.Imaging.ImageCollection())
    {
        // add DOCX document to the image collection
        imageCollection.Add(docxFileName);
        // create PdfEncoder
        using (Vintasoft.Imaging.Codecs.Encoders.PdfEncoder pdfEncoder = 
            new Vintasoft.Imaging.Codecs.Encoders.PdfEncoder(true))
        {
            // set compression for image resources in PDF document
            pdfEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.Jpeg;
            // save images of image collection (DOCX pages) to a PDF document
            imageCollection.SaveSync(pdfFileName, pdfEncoder);
        }
        // dispose images
        imageCollection.ClearAndDisposeItems();
    }
}