C# 將PDF轉為SVG的3種情況

來源:互聯網
上載者:User

標籤:項目   sha   put   PDF檔案   filename   使用   ons   oid   ini   

PDF格式的文檔廣泛用於各種辦公場所,在工作中難免會有將PDF文檔轉換為其他文檔格式的需要。在本篇文檔中,將介紹PDF轉為SVG的方法。根據不同的轉換需求,這裡分三種情況進行講述,即轉PDF所有頁為SVG、轉PDF指定頁為SVG和轉PDF到指定高度、寬度的SVG。以上三種情況,下面將作詳細介紹。
使用工具:Spire.PDF for .NET
提示:使用該組件需要先下載安裝,在項目程式中注意須添加引用Spire.PDF.dll檔案(如下所示)

原PDF文檔:

1.將PDF所有頁轉為SVG
using Spire.Pdf;namespace PDFtoSVG_PDF{    class Program    {        static void Main(string[] args)        {            //建立一個PdfDocument類對象,載入sample,儲存為SVG格式的檔案            PdfDocument document = new PdfDocument();            document.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");            document.SaveToFile("output.svg", FileFormat.SVG);        }    }}

調試運行該項目,產生文檔:

2.將指定PDF頁轉為SVG
using Spire.Pdf;namespace ConvertPDFPagetoSVG_PDF{    class Program    {        static void Main(string[] args)        {            //執行個體化一個PdfDocument類對象            PdfDocument doc = new PdfDocument();            //載入PDF檔案            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");            //調用方法SaveToFile(string filename, int startIndex, int endIndex, FileFormat )將PDF指定頁儲存為SVG格式            doc.SaveToFile("Result.svg", 1, 2, FileFormat.SVG);        }    }}

調試運行程式後,可查看成功轉換的SVG文檔
轉換後的文檔:

3.PDF轉指定寬度、高度的SVG
using Spire.Pdf;namespace PDFtoSVG1_PDF{    class Program    {        static void Main(string[] args)        {            //建立一個PdfDocument類對象,並載入PDF檔案            PdfDocument document = new PdfDocument();            document.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");            //調用方法SetPdfToSvgOptions()指定轉換SVG的寬度和高度            document.ConvertOptions.SetPdfToSvgOptions(700f, 1000f);            //儲存到檔案,命名文檔,並設定儲存格式            document.SaveToFile("result.svg", FileFormat.SVG);        }    }}


以上內容為PDF轉為SVG的三種情況的方法介紹,可根據不同的辦公需求選擇相應的轉換方法。

如果喜歡,歡迎轉載(轉載請註明出處)

C# 將PDF轉為SVG的3種情況

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.