0
0

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# VB.NET:PDFをWordに変換する

Last updated at Posted at 2022-05-24

PDFドキュメントが最近非常に人気になっているという事実にもかかわらず、レイアウトとフォントスタイルを維持しながら、PDFファイルを正確にWordドキュメントに変換できるツールが依然として有益だと認められています。その原因は、Word文書が編集可能であり、複製にも使用できるからです。この記事では、Spire.PDF for .NETを使用してC#およびVB.NETでPDFをDocまたはDocxに変換する方法を示します。

PDFをDocに変換
PDFをDocxに変換する
PSモードを使用してPDFをDocxに変換する

Spire.PDF for .NETをインストールします

まず、Spire.PDF for .NETパッケージに含まれているDLLファイルを.NETプロジェクトの参照として追加する必要があります。DLLファイルは、このリンクからダウンロードするか、NuGetを介してインストールできます。

PM> Install-Package Spire.PDF

PDFをDocに変換

以下は、Spire.PDFfor.NETを使用してPDFをDocに変換する手順です。

PdfDocumentオブジェクトを作成します。
PdfDocument.LoadFromFile() メソッドを使用してサンプルPDFファイルをロードします。
PdfDocument.SaveToFile() メソッドを使用して、ドキュメントを.doc形式のファイルに変換します。

C#

using Spire.Pdf;

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

            //サンプルPDFドキュメントをロードする
            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

            //PDFをDocに変換し、指定したパスに保存する
            doc.SaveToFile("ToDoc.doc", FileFormat.DOC);
        }
    }
}

VB.NET

Imports Spire.Pdf
 
Namespace ConvertPdfToDoc
    Class Program
        Shared  Sub Main(ByVal args() As String)
            'PdfDocumentオブジェクトを作成する
            Dim doc As PdfDocument =  New PdfDocument() 
 
            'サンプルPDFドキュメントをロードする
            doc.LoadFromFile("C:\Users\Administrator\Desktop\sample.pdf")
 
            'PDFをDocに変換し、指定したパスに保存する
            doc.SaveToFile("ToDoc.doc", FileFormat.DOC)
        End Sub
    End Class
End Namespace
PDFをDocxに変換する

以下は、Spire.PDF for .NETを使用してPDFをDocxに変換する手順です。

PdfDocumentオブジェクトを作成します。
PdfDocument.LoadFromFile() メソッドを使用してサンプルPDFファイルをロードします。
PdfDocument.SaveToFile() メソッドを使用して、ドキュメントを.docx形式のファイルに変換します。

C#

using Spire.Pdf;

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

            //サンプルPDFドキュメントをロードする
            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

            //PDFをDocxに変換し、指定したパスに保存する
            doc.SaveToFile("ToDocx2.docx", FileFormat.DOCX);
        }
    }
}

VB.NET

Imports Spire.Pdf
 
Namespace ConvertPdfToDoc
    Class Program
        Shared  Sub Main(ByVal args() As String)
            'PdfDocumentオブジェクトを作成する
            Dim doc As PdfDocument =  New PdfDocument() 
 
            'サンプルPDFドキュメントをロードする
            doc.LoadFromFile("C:\Users\Administrator\Desktop\sample.pdf")
 
            'PDFをDocに変換し、指定したパスに保存する
            doc.SaveToFile("ToDoc.doc", FileFormat.DOC)
        End Sub
    End Class
End Namespace

PSモードを使用してPDFをDocxに変換する

デフォルトの変換エンジンに加えて、Spire.PDFには、変換に使用できるPSモードと呼ばれる別のエンジンが用意されています。以下は、PSモードを使用してPDFをDocxに変換する手順です。

PdfDocumentオブジェクトを作成します。
PdfDocument.LoadFromFile() メソッドを使用してサンプルPDFファイルをロードします。
変換エンジンをPSモードに設定し、PdfConvertOptions.SetPdfToDocOptions(bool usePsMode、bool useFlowRecognitionMode) メソッドを使用して認識モードをフローに設定します。
PdfDocument.SaveToFile() メソッドを使用して、ドキュメントを.docx形式のファイルに変換します。

C#

using Spire.Pdf;

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

            //サンプルPDFドキュメントをロードする
            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

            //PSモードを使用してPDFをWordに変換し、認識モードをフローに設定する
            doc.ConvertOptions.SetPdfToDocOptions(true, true);

            //PDFをDocxに変換し、指定したパスに保存する
            doc.SaveToFile("ToDocx.docx", FileFormat.DOCX);
        }
    }
}

VB.NET

Imports Spire.Pdf
 
Namespace ConvertPdfToDocxUsingPsMode
    Class Program
        Shared  Sub Main(ByVal args() As String)
            'PdfDocumentオブジェクトを作成する
            Dim doc As PdfDocument =  New PdfDocument() 
 
            'サンプルPDFドキュメントをロードする
            doc.LoadFromFile("C:\Users\Administrator\Desktop\sample.pdf")
 
            'PSモードを使用してPDFをWordに変換し、認識モードをフローに設定する
            doc.ConvertOptions.SetPdfToDocOptions(True, True)
 
            'PDFをDocxに変換し、指定したパスに保存する
            doc.SaveToFile("ToDocx.docx", FileFormat.DOCX)
        End Sub
    End Class
End Namespace

03.png

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除する場合、または機能制限を取り除く場合は、30日間有効な一時ライセンスについて営業担当者にお問い合わせください。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?