C# で PDF ドキュメントを DOCX ドキュメントに変換します

ブログ カテゴリ: PDFOffice.NET

2024/04/12

PDF ドキュメントは、テキスト、フォント、グラフィック、ドキュメントを表示するために必要なその他の情報など、平面上のドキュメント要素の固定レイアウトの完全な記述を含むドキュメントです。PDF ドキュメントの利点は、デバイスに関係なく、常に同じ外観になることです。PDF ドキュメントのもう 1 つの利点は、各ページの内容が個別に保存されるため、たとえば、1000 ページの PDF ドキュメントの最後のページをレンダリングして表示するときに、このドキュメントの他のすべてのページをレンダリングする必要がないことです。PDF ドキュメントの欠点は、その内容を編集するのが難しいことです。

DOCX ドキュメントは、テキスト、画像、グラフィックなどを含む Microsoft Word Open XML 形式のドキュメントです。DOCX ドキュメントの利点は、その内容をシンプルで直感的に編集できることです。DOCX ドキュメントの欠点は、ドキュメントの内容をページに分割するためにレイアウトする必要があることです。言い換えると、1000 ページの DOCX ドキュメントの場合、最後のページだけを表示する必要がある場合でも、ドキュメントのすべてのページをレンダリングする必要があります。

上記の利点と欠点に基づくと、PDF ファイルはドキュメントの表示と保存に便利であり、DOCX ファイルはドキュメントの作成と編集に便利であることがわかります。

VintaSoft Imaging .NET SDK を使用すると、PDF ドキュメントのコンテンツを編集できます。詳細については、こちら を参照してください。

また、VintaSoft Imaging .NET SDK を使用すると、PDF ドキュメントを DOCX ドキュメントに変換し、MicrosoftOffice Word や OpenOffice Writer などの適切なテキスト エディター プログラムで DOCX ドキュメントをさらに編集することができます。

VintaSoft Imaging .NET SDK では、DOCX ドキュメントを PDF ドキュメントに戻すこともできます。

PDF ドキュメントを DOCX ドキュメントに変換する C# コードは次のとおりです。
/// <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();
    }
}

DOCX ドキュメントを PDF ドキュメントに変換する C# コードは次のとおりです。
/// <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();
    }
}