1
2

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 3 years have passed since last update.

C# PDFをWord、Image、XPSで保存

Posted at

今日はCシャープについての話です。Spire.PDFを通じてPDFをWord、Image、XPSで保存する方法を紹介します。

下準備

1.E-iceblueの公式サイトからFree Spire.PDF無料版をダウンロードしてください。

f:id:lendoris:20210209121045p:plain

2.Visual Studioを起動して新規プロジェクトを作成してから、インストールされたファイルにあった相応しいSpire. PDF.dllを参照に追加してください。

(Net 4.0を例としたら、デフォルトパスは“Bin→NET4.0→PDF.dll”というようです。)

f:id:lendoris:20210209121059p:plain

元のファイル

f:id:lendoris:20210209121124p:plain

PDFをWordで保存

```JAVA using Spire.Pdf;

namespace ConsoleApplication30
{
class Program
{
static void Main(string[] args)
{
//PdfDocument objectを作成します。
PdfDocument doc = new PdfDocument();

        //PDFをロードします
        doc.LoadFromFile("sample.pdf");

        //Docで保存します。
        doc.SaveToFile("toWord.doc", FileFormat.DOC);

    }
}

}



<h4><strong>実行結果</strong></h4>
<p><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/l/lendoris/20210209/20210209121208.png" alt="f:id:lendoris:20210209121208p:plain" title="" class="hatena-fotolife" itemprop="image" /></p>
<h4><strong>PDFをイメージで保存</strong></h4>

```JAVA
using Spire.Pdf;

namespace ConsoleApplication30
{
    class Program
    {
        static void Main(string[] args)
        {
            // PdfDocument objectを作成します。
            PdfDocument doc = new PdfDocument();

            // PDFをロードします
            doc.LoadFromFile("sample.pdf");

            //PDFのページをループします。
            for (int i = 0; i < doc.Pages.Count; i++)
            {
                //PDFをbitmapで保存します。
                System.Drawing.Image bmp = doc.SaveAsImage(i);

                //bitmapを pngで保存します
                string fileName = string.Format("Page-{0}.png", i + 1);
                bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);

            }
        }
    }
}

 

f:id:lendoris:20210209121238p:plain

PDFをXPSで保存

```JAVA using Spire.Pdf;

namespace ConsoleApplication30
{
class Program
{
static void Main(string[] args)
{
// PdfDocument objectを作成します。
PdfDocument doc = new PdfDocument();

        // PDFをロードします
        doc.LoadFromFile("sample.pdf");

        //XPSで保存します。
        doc.SaveToFile("toXPS.xps", FileFormat.XPS);

    }
}
<p> </p>
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?