当前位置:网站首页>[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 .
边栏推荐
- Support vector machine for machine learning
- Characteristics and isolation level of database
- GPS坐标转百度地图坐标的方法
- A letter to graduating college students
- conda和pip的区别
- Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
- 23 design models
- 有意思的鼠标指针交互探究
- Request weather interface format, automation
- Oracle database synonym creation
猜你喜欢

Yolov2 learning and summary

Oauth2.0 - Introduction and use and explanation of authorization code mode

远端rostopic的本地rviz调用及显示

ruoyi接口权限校验

The list of "I'm crazy about open source" was released in the first week, with 160 developers on the list

有意思的鼠標指針交互探究

Project summary --04

Oauth2.0 - user defined mode authorization - SMS verification code login

Simple understanding of ThreadLocal

Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
随机推荐
After the Chrome browser is updated, lodop printing cannot be called
opencv
Jackson: what if there is a lack of property- Jackson: What happens if a property is missing?
Cesium entity(entities) 实体删除方法
Selenium - 改变窗口大小,不同机型呈现的宽高长度会不一样
Oauth2.0 - user defined mode authorization - SMS verification code login
[untitled] 5 self use history
opencv
Various usages of MySQL backup database to create table select and how many days are left
【5G NR】UE注册流程
技术管理进阶——你了解成长的全貌吗?
Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
Difference between shortest path and minimum spanning tree
The most classic 100 sentences in the world famous works
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
The difference between CONDA and pip
Svn branch management
A letter to graduating college students
Important knowledge points of redis
“我为开源打榜狂”第一周榜单公布,160位开发者上榜