翻譯|行業(yè)資訊|編輯:胡濤|2023-11-28 10:31:29.113|閱讀 116 次
概述:在本教程中,我們將向您展示如何將SVG 轉(zhuǎn)換為 PDF,以及如何使用Spire.PDF for .NET在 C# 和 VB.NET 中將SVG 圖像添加到 PDF。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
SVG 是一種矢量圖形文件格式,用于創(chuàng)建可縮放且不損失質(zhì)量的圖像。然而,PDF由于支持高質(zhì)量打印、加密、數(shù)字簽名等功能,更適合共享和打印。將SVG轉(zhuǎn)換為PDF可以保證圖像在不同設(shè)備和環(huán)境下都有良好的顯示效果,并更好地保護(hù)知識(shí)產(chǎn)權(quán)。在本教程中,我們將向您展示如何將SVG 轉(zhuǎn)換為 PDF,以及如何使用Spire.PDF for .NET在 C# 和 VB.NET 中將SVG 圖像添加到 PDF。
Spire.Doc 是一款專門對(duì) Word 文檔進(jìn)行操作的 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗(yàn)Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國(guó)本土團(tuán)隊(duì)研發(fā),不依賴第三方軟件,不受其他國(guó)家的技術(shù)或法律法規(guī)限制,同時(shí)適配國(guó)產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國(guó)產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
Spire.PDF for.net下載 Spire.PDF for java下載
首先,您需要將 Spire.PDF for .NET 包中包含的 DLL 文件添加為 .NET 項(xiàng)目中的引用。DLL 文件可以從此鏈接下載或通過NuGet安裝。
PM> Install-Package Spire.PDF
Spire.PDF for .NET 提供了PdfDocument.SaveToFile(String, FileFormat)方法,允許用戶將 SVG 文件另存為 PDF。詳細(xì)步驟如下。
[C#]
using Spire.Pdf; namespace SVGtoPDF { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Load a sample SVG file doc.LoadFromSvg("Sample.svg"); //Save result document doc.SaveToFile("Result.pdf", FileFormat.PDF); doc.Dispose(); } } }
[VB.NET]
Imports Spire.Pdf Namespace SVGtoPDF Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Create a PdfDocument object Dim doc As PdfDocument = New PdfDocument() 'Load a sample SVG file doc.LoadFromSvg("Sample.svg") 'Save result document doc.SaveToFile("Result.pdf", FileFormat.PDF) doc.Dispose(); End Sub End Class End Namespace
除了直接將SVG轉(zhuǎn)換為PDF外,它還支持將SVG圖像文件添加到PDF中的指定位置。請(qǐng)檢查以下步驟:
[C#]
using Spire.Pdf; using Spire.Pdf.Graphics; using System.Drawing; namespace AddSVGImagetoPDF { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument doc1 = new PdfDocument(); //Load an SVG file doc1.LoadFromSvg("C:\\Users\\Administrator\\Desktop\\sample.svg"); //Create a template based on the content of the SVG file PdfTemplate template = doc1.Pages[0].CreateTemplate(); //Get the width and height of the template float width = template.Width; float height = template.Height; //Create another PdfDocument object PdfDocument doc2 = new PdfDocument(); //Load a PDF file doc2.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf"); //Draw the template with a custom size at a specified location doc2.Pages[0].Canvas.DrawTemplate(template, new PointF(0, 0), new SizeF(width * 0.8f, height * 0.8f)); //Save to PDF file doc2.SaveToFile("AddSvgToPdf.pdf", FileFormat.PDF); doc2.Dispose(); } } }
[VB.NET]
Imports Spire.Pdf Imports Spire.Pdf.Graphics Imports System.Drawing Namespace AddSVGImagetoPDF Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Create a PdfDocument object Dim doc1 As PdfDocument = New PdfDocument() 'Load an SVG file doc1.LoadFromSvg("C:\Users\Administrator\Desktop\sample.svg") 'Create a template based on the content of the SVG file Dim template As PdfTemplate = doc1.Pages(0).CreateTemplate() 'Get the width and height of the template Dim width As Single = template.Width Dim height As Single = template.Height 'Create another PdfDocument object Dim doc2 As PdfDocument = New PdfDocument() 'Load a PDF file doc2.LoadFromFile("C:\Users\Administrator\Desktop\sample.pdf") 'Draw the template with a custom size at a specified location doc2.Pages(0).Canvas.DrawTemplate(template, New PointF(0, 0), New SizeF(width * 0.8F, height * 0.8F)) 'Save to PDF file doc2.SaveToFile("AddSvgToPdf.pdf", FileFormat.PDF) doc2.Dispose() End Sub End Class End Namespace
以上便是如何在C#/VB.NET:將SVG 轉(zhuǎn)換為 PDF,如果您有其他問題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
獲取更多信息請(qǐng)咨詢 ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@ke049m.cn