0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C#でPDFを固定レイアウトのWord文書に変換する

Posted at

PDFをWordに変換することは、ユーザーがPDF文書を編集、修正、再利用するための実用的な作業です。PDFは比較的安定した固定フォーマットであり、直接編集や修正が困難な一方、Word文書はより柔軟で編集や組版が可能です。PDFをWordに変換することで、文書のテキスト、画像、書式を簡単に変更、調整することができます。本チュートリアルでは、C#プログラムでFree Spire.PDF for .NET を使用して、PDFを固定レイアウトのWord文書に変換する方法を紹介します。

プログラム環境

DLLファイルのインポート

  • Visual Studioを開いて新しいプロジェクトを作成します。
  • 「Solution Explorer」で「References」を右クリックします。
  • 「NuGet Manage Packages」を選択します。
  • Free Spire.PDF for .NETを検索してインストールします。

または、このリンクから直接ダウンロードすることもできます。

  • Visual Studioを開いて新しいプロジェクトを作成します。
  • 「Solution Explorer」で「References」を右クリックします。
  • 「Add Reference」を選択します。
  • 「Browse」をクリックします。
  • DLLを検索してインストールしてプロジェクトにインポートします。

コード

using Spire.Pdf;

namespace ConvertPdfToDoc
{
    class Program
    {
        static void Main(string[] args)
        {
            //PdfDocumentオブジェクトを作成する
            PdfDocument doc = new PdfDocument();

            //サンプルPDFファイルを読み込む
            doc.LoadFromFile(@"sample.pdf");

            //PDFをDocに変換して保存する
            doc.SaveToFile("ToDoc.doc", FileFormat.DOC);

            // PDFをDocxに変換して保存する
            //doc.SaveToFile("ToDocx.docx", FileFormat.DOCX);
        }
    }
}

image.png
このコードは、PDFファイルをDOCおよびDOCXファイルに変換することができます。最初に、PdfDocumentオブジェクトを作成し、LoadFromFileメソッドを使用してPDFファイルを読み込みます。次に、SaveToFileメソッドを使用して、PdfDocumentオブジェクトをDOC形式のWord文書に変換し、「ToDoc.doc」という名前のファイルに保存するか、またはPdfDocumentをDOCX形式のWord文書に変換し、「ToDocx.docx」という名前のファイルに保存します。最後に、プログラムは終了します。
上記の方法を参考にして、PDFをExcelに変換したり、PDFを画像に変換したりすることもできます。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?