当前位置:网站首页>[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 .
边栏推荐
- 輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
- Kubesphere - build Nacos cluster
- Use selenium to climb the annual box office of Yien
- Reinstalling the system displays "setup is applying system settings" stationary
- Mysql database binlog log enable record
- Oauth2.0 - Introduction and use and explanation of authorization code mode
- Cesium entity (entities) entity deletion method
- Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
- PMP notes
- Chapter 8. MapReduce production experience
猜你喜欢

Scripy learning

Kubesphere - build MySQL master-slave replication structure

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

Local rviz call and display of remote rostopic
![[system design] proximity service](/img/4a/2e68536cbe385af1d1a591e674fbf0.png)
[system design] proximity service

【5G NR】UE注册流程

Oauth2.0 - use database to store client information and authorization code

Use selenium to climb the annual box office of Yien

Yolov2 learning and summary

2022 CISP-PTE(三)命令执行
随机推荐
Kubesphere - build Nacos cluster
远端rostopic的本地rviz调用及显示
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
Method of converting GPS coordinates to Baidu map coordinates
Important knowledge points of redis
Common interview questions
In depth learning
ROS+Pytorch的联合使用示例(语义分割)
Leetcode problem solving summary, constantly updating!
Luogu problem list: [mathematics 1] basic mathematics problems
Scroll view specifies the starting position of the scrolling element
论文笔记 VSALM 文献综述《A Comprehensive Survey of Visual SLAM Algorithms》
Interesting research on mouse pointer interaction
【无标题】5 自用历程
数值法求解最优控制问题(一)——梯度法
Phpstudy setting items can be accessed by other computers on the LAN
Selenium - by changing the window size, the width, height and length of different models will be different
Migrate data from Mysql to tidb from a small amount of data
The most classic 100 sentences in the world famous works
Derivation of variance iteration formula