当前位置:网站首页>[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 .
边栏推荐
- Kubesphere - build MySQL master-slave replication structure
- Jackson: what if there is a lack of property- Jackson: What happens if a property is missing?
- YOLOV3学习笔记
- Cesium 点击获取模型表面经纬度高程坐标(三维坐标)
- How matlab modifies default settings
- Interface test weather API
- UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
- Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
- 【5G NR】UE注册流程
- Mysql database table export and import with binary
猜你喜欢

ruoyi接口权限校验

Zhiniu stock -- 03

Kubesphere - build MySQL master-slave replication structure
![[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle](/img/f8/0e3fbfd13bf06291a73200552ff17a.png)
[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle

After the Chrome browser is updated, lodop printing cannot be called

论文笔记 VSALM 文献综述《A Comprehensive Survey of Visual SLAM Algorithms》

Zhiniu stock project -- 04

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

Redis cluster creation, capacity expansion and capacity reduction

YOLOV2学习与总结
随机推荐
[leetcode] day93 - intersection of two arrays II
Kubernetes notes (10) kubernetes Monitoring & debugging
[set theory] equivalence relation (concept of equivalence relation | examples of equivalence relation | equivalence relation and closure)
Oracle database synonym creation
YOLOV3学习笔记
Kubesphere - set up redis cluster
Characteristics and isolation level of database
Luogu problem list: [mathematics 1] basic mathematics problems
Interface test weather API
简易密码锁
Project summary --2 (basic use of jsup)
Svn branch management
The mechanical hard disk is connected to the computer through USB and cannot be displayed
conda和pip的区别
Simple password lock
Redis cluster creation, capacity expansion and capacity reduction
. Net program configuration file operation (INI, CFG, config)
Jackson: what if there is a lack of property- Jackson: What happens if a property is missing?
Advanced technology management - do you know the whole picture of growth?
Une exploration intéressante de l'interaction souris - pointeur