当前位置:网站首页>[C /vb.net] convert PDF to svg/image, svg/image to PDF
[C /vb.net] convert PDF to svg/image, svg/image to PDF
2022-07-03 06:29:00 【xuhss_ com】
High quality resource sharing
Learning route guidance ( Click unlock ) | Knowledge orientation | Crowd positioning |
---|---|---|
🧡 Python Actual wechat ordering applet 🧡 | Progressive class | This course is python flask+ Perfect combination of wechat applet , From the deployment of Tencent to the launch of the project , Create a full stack ordering system . |
Python Quantitative trading practice | beginner | Take you hand in hand to create an easy to expand 、 More secure 、 More efficient quantitative trading system |
SVG Is a graphics file format , Its full English name is Scalable Vector Graphics, It means scalable vector graphics . Its graphic quality will not be lost when it is enlarged or its size is changed , And with the JPG and GIF Image comparison , Smaller size , And more compressible . This article describes how to implement the PDF Documentation and SVG/Image The method of mutual conversion . After comprehensive comparison , Finally, this method was screened out . This method is easy to operate and has less code . Here are the detailed steps and C#/VB.NET Code for your reference .
** Class library introduction and code ideas :** In this function test , What we use is Free Spire.PDF for .NET.Spire.PDF.dll The introduction method of the document is as follows : Method 1: take Free Spire.PDF for .NET Download to local , decompression , install . After installation , Find the installation path BIN In folder Spire.PDF.dll. And then in Visual Studio Open in “ Solution explorer ”, Right click “ quote ”,“ Add reference ”, The local path BIN Under folder dll Add a reference to the program . Method 2: adopt NuGet install . This can be done by 2 Methods of installation :(1) Can be in Visual Studio Open in “ Solution explorer ”, Right click “ quote ”,“ management NuGet package ”, And then the search “Free Spire.PDF”, Click on “ install ”. Wait for the program installation to complete .(2) Copy the following to PM Console installation .Install-Package FreeSpire.PDF -Version 8.2.0
take PDF To SVG Format
Specific steps :
- establish PdfDocument Class object .
- call PdfDocument.LoadFromFile() Method loading PDF file .
- adopt PdfDocument.SaveToFile() Method as SVG Format .
Complete code :
【C#】
using System;
using Spire.Pdf;
namespace PdfToSVG
{
class Program
{
static void Main(string[] args)
{
// Create and load PDF file
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("Sample.pdf");
// Save as SVG Format
doc.SaveToFile("ToSVG-result.svg", FileFormat.SVG);
doc.Close();
}
}
}
【VB.NET】
Imports System
Imports Spire.Pdf
Namespace PdfToSVG
Class Program
Private Shared Sub Main(ByVal args() As String)
' Create and load PDF file
Dim doc As PdfDocument = New PdfDocument
doc.LoadFromFile("Sample.pdf")
' Save as SVG Format
doc.SaveToFile("ToSVG-result.svg", FileFormat.SVG)
doc.Close
End Sub
End Class
End Namespace
design sketch :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-RE7FnCwX-1655355097026)(https://img2022.cnblogs.com/blog/2859233/202206/2859233-20220616093937809-970468124.png)]
take SVG To PDF Format
Specific steps :
- Create a PdfDocument object .
- use PdfDocument.LoadFromSvg() Method loading SVG file
- use PdfDocument.SaveToFile() Method as PDF file
Complete code :
【C#】
using Spire.Pdf;
using System;
namespace SVGToPdf
{
class Program
{
static void Main(string[] args)
{
// Create a PdfDocument object .
PdfDocument doc = new PdfDocument();
// Load the document .
doc.LoadFromSvg("ToSVG-result.svg");
// Save the document .
String result = "SVgToPDF\_out.pdf";
doc.SaveToFile(result);
}
}
}
【VB.NET】
Imports Spire.Pdf
Imports System
Namespace SVGToPdf
Class Program
Private Shared Sub Main(ByVal args() As String)
' Create a PdfDocument object .
Dim doc As PdfDocument = New PdfDocument
' Load the document .
doc.LoadFromSvg("ToSVG-result.svg")
' Save the document
Dim result As String = "SVgToPDF\_out.pdf"
doc.SaveToFile(result)
End Sub
End Class
End Namespace
design sketch :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Zh3d1UUe-1655355097030)(https://img2022.cnblogs.com/blog/2859233/202206/2859233-20220616094234762-389225572.png)]
take PDF Convert to image
Specific steps :
- add to PDF file
- use PdfDocument.LoadFromFile() Method loading PDF file
- use Image.Save() Method to save as a picture
Complete code :
【C#】
using System;
using System.Drawing;
using Spire.Pdf;
namespace ToImage
{
class Program
{
static void Main(string[] args)
{
// Create and load PDF file
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("Sample1.pdf");
// Save as picture
for (int i = 0; i < doc.Pages.Count; i++)
{
String fileName = String.Format("ToImage-img-{0}.png", i);
using (Image image = doc.SaveAsImage(i, 300, 300))
{
image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
}
}
doc.Close();
}
}
}
【VB.NET】
Imports System
Imports System.Drawing
Imports Spire.Pdf
Namespace ToImage
Class Program
Private Shared Sub Main(ByVal args() As String)
' Create and load PDF file
Dim doc As PdfDocument = New PdfDocument
doc.LoadFromFile("Sample1.pdf")
' Save as picture
Dim i As Integer = 0
Do While (i < doc.Pages.Count)
Dim fileName As String = String.Format("ToImage-img-{0}.png", i)
Dim image As Image = doc.SaveAsImage(i, 300, 300)
image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png)
i = (i + 1)
Loop
doc.Close
End Sub
End Class
End Namespace
design sketch :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-8ZNDZRhQ-1655355097031)(https://img2022.cnblogs.com/blog/2859233/202206/2859233-20220616095013266-1072419986.png)]
Turn the image into PDF Format
Specific steps :
- Create one that adds section And page pdf file .
- use PdfImage.FromFile() Method load image
- stay PDF Set the display position and size of the image in
- adopt PdfImage.PhysicalDimension Property to get the picture size
- Use PdfPage.Canvas.DrawImage() Method on the first page (0, 30) Draw at PdfImage object
- Use PdfDocument.SaveToFile() Method to save the document as PDF file
Complete code :
【C#】
using System;
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Graphics;
namespace ImageToPdf
{
class Program
{
static void Main(string[] args)
{
// Create one that adds section And page pdf file .
PdfDocument pdf = new PdfDocument();
PdfSection section = pdf.Sections.Add();
PdfPageBase page = pdf.Pages.Add();
// Loading pictures
PdfImage image = PdfImage.FromFile("image5.png");
// stay PDF Set the display position and size of the image in
// Resize the picture to fit the page width
float widthFitRate = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
float fitRate = Math.Max(widthFitRate, heightFitRate);
// Get image size
float fitWidth = image.PhysicalDimension.Width / fitRate;
float fitHeight = image.PhysicalDimension.Height / fitRate;
// mapping
page.Canvas.DrawImage(image, 0, 30, fitWidth, fitHeight);
string output = "image.pdf";
pdf.SaveToFile(output);
}
}
}
【VB.NET】
Imports System
Imports System.Drawing
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Namespace ImageToPdf
Class Program
Private Shared Sub Main(ByVal args() As String)
' Create one that adds section And page pdf file .
Dim pdf As PdfDocument = New PdfDocument
Dim section As PdfSection = pdf.Sections.Add
Dim page As PdfPageBase = pdf.Pages.Add
' Loading pictures
Dim image As PdfImage = PdfImage.FromFile("image5.png")
' stay PDF Set the display position and size of the image in
' Resize the picture to fit the page width
Dim widthFitRate As Single = (image.PhysicalDimension.Width / page.Canvas.ClientSize.Width)
Dim heightFitRate As Single = (image.PhysicalDimension.Height / page.Canvas.ClientSize.Height)
Dim fitRate As Single = Math.Max(widthFitRate, heightFitRate)
' Get image size
Dim fitWidth As Single = (image.PhysicalDimension.Width / fitRate)
Dim fitHeight As Single = (image.PhysicalDimension.Height / fitRate)
' mapping
page.Canvas.DrawImage(image, 0, 30, fitWidth, fitHeight)
Dim output As String = "image.pdf"
pdf.SaveToFile(output)
End Sub
End Class
End Namespace
design sketch :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-8kVwhqf5-1655355097032)(https://img2022.cnblogs.com/blog/2859233/202206/2859233-20220616095305046-2077878358.png)]
** Be careful :** The file path in the test code is program Debug route , For reference only , File paths can be customized to other paths .
边栏推荐
- Mysql database
- Svn branch management
- Merge and migrate data from small data volume, sub database and sub table Mysql to tidb
- Project summary --2 (basic use of jsup)
- Cesium 点击获取模型表面经纬度高程坐标(三维坐标)
- Important knowledge points of redis
- Openresty best practices
- 认识弹性盒子flex
- [5g NR] UE registration process
- When PHP uses env to obtain file parameters, it gets strings
猜你喜欢
Oauth2.0 - explanation of simplified mode, password mode and client mode
Docker advanced learning (container data volume, MySQL installation, dockerfile)
Cesium 点击获取模型表面经纬度高程坐标(三维坐标)
Interesting research on mouse pointer interaction
剖析虚幻渲染体系(16)- 图形驱动的秘密
Oauth2.0 - using JWT to replace token and JWT content enhancement
Reinstalling the system displays "setup is applying system settings" stationary
Mysql
ThreadLocal的简单理解
Creating postgre enterprise database by ArcGIS
随机推荐
Kubesphere - set up redis cluster
Simple password lock
Simple understanding of ThreadLocal
ROS+Pytorch的联合使用示例(语义分割)
Use abp Zero builds a third-party login module (I): Principles
arcgis创建postgre企业级数据库
YOLOV2学习与总结
Kubesphere - build MySQL master-slave replication structure
Selenium - by changing the window size, the width, height and length of different models will be different
【无标题】8 简易版通讯录
Selenium ide installation recording and local project maintenance
Use selenium to climb the annual box office of Yien
IE browser flash back, automatically open edge browser
有意思的鼠标指针交互探究
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
SQL实现将多行记录合并成一行
Pdf files can only print out the first page
SSH link remote server and local display of remote graphical interface
数值法求解最优控制问题(一)——梯度法
【LeetCode】Day93-两个数组的交集 II