没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:胡涛|2023-06-26 13:42:06.977|阅读 90 次
概述:在本文中,您将了解如何使用Spire.PDF for .NET在 C# 和 VB.NET 中将图像转换为 PDF,,欢迎查阅~
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
Spire.Doc 是一款专门对 Word 文档进行操作的 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。
E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式
Spire.PDF for.net下载 Spire.PDF for java下载
图像是一种设备友好的文件格式,可以在各种设备之间轻松共享。然而,在某些情况下,需要更专业的格式(例如PDF)来代替图像。在本文中,您将了解如何使用Spire.PDF for .NET在 C# 和 VB.NET 中将图像转换为 PDF。
Spire.PDF 没有提供将图像转换为 PDF 的简单方法。但您可以创建一个新的 PDF 文档并在特定页面的指定位置绘制图像。根据是否生成与图像页面大小相同的 PDF,本主题可以分为以下两个子主题。
首先,您需要将包含在 Spire.PDF for.NET 包中的 DLL 文件添加为您的 .NET 项目中的引用。DLL 文件可以从此链接下载或通过NuGet安装。
PM> Install-Package Spire.PDF
以下是使用 Spire.PDF for .NET 添加图像作为新 PDF 文档的一部分的步骤。
【C#】
using System.Drawing; using Spire.Pdf; using Spire.Pdf.Graphics; namespace AddImageToPdf { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Set the margins doc.PageSettings.SetMargins(20); //Add a page PdfPageBase page = doc.Pages.Add(); //Load an image Image image = Image.FromFile(@"C:\Users\Administrator\Desktop\announcement.jpg"); //Get the image width and height float width = image.PhysicalDimension.Width; float height = image.PhysicalDimension.Height; //Declare a PdfImage variable PdfImage pdfImage; //If the image width is larger than page width if (width > page.Canvas.ClientSize.Width) { //Resize the image to make it to fit to the page width float widthFitRate = width / page.Canvas.ClientSize.Width; Size size = new Size((int)(width / widthFitRate), (int)(height / widthFitRate)); Bitmap scaledImage = new Bitmap(image, size); //Load the scaled image to the PdfImage object pdfImage = PdfImage.FromImage(scaledImage); } else { //Load the original image to the PdfImage object pdfImage = PdfImage.FromImage(image); } //Draw image at (0, 0) page.Canvas.DrawImage(pdfImage, 0, 0, pdfImage.Width, pdfImage.Height); //Save to file doc.SaveToFile("AddImage.pdf"); } } }
【VB.NET】
Imports System.Drawing Imports Spire.Pdf Imports Spire.Pdf.Graphics Namespace AddImageToPdf Class Program Shared Sub Main(ByVal args() As String) 'Create a PdfDocument object Dim doc As PdfDocument = New PdfDocument() 'Set the margins doc.PageSettings.SetMargins(20) 'Add a page Dim page As PdfPageBase = doc.Pages.Add() 'Load an image Dim image As Image = Image.FromFile("C:\Users\Administrator\Desktop\announcement.jpg") 'Get the image width and height Dim width As single = image.PhysicalDimension.Width Dim height As single = image.PhysicalDimension.Height 'Declare a PdfImage variable Dim pdfImage As PdfImage 'If the image width is larger than page width If width > page.Canvas.ClientSize.Width Then 'Resize the image to make it to fit to the page width Dim widthFitRate As single = width / page.Canvas.ClientSize.Width Dim size As Size = New Size(CType((width / widthFitRate),(Integer)(height / widthFitRate), Integer)) Dim scaledImage As Bitmap = New Bitmap(image,size) 'Load the scaled image to the PdfImage object pdfImage = PdfImage.FromImage(scaledImage) Else 'Load the original image to the PdfImage object pdfImage = PdfImage.FromImage(image) End If 'Draw image at (0, 0) page.Canvas.DrawImage(pdfImage, 0, 0, pdfImage.Width, pdfImage.Height) 'Save to file doc.SaveToFile("AddImage.pdf") End Sub End Class End Namespace
以下是使用 Spire.PDF for .NET 将图像转换为与图像具有相同页面宽度和高度的 PDF 的步骤。
【C#】
using System.Drawing; using Spire.Pdf; using Spire.Pdf.Graphics; namespace ConvertImageToPdfWithSameSize { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Set the margins to 0 doc.PageSettings.SetMargins(0); //Load an image Image image = Image.FromFile(@"C:\Users\Administrator\Desktop\announcement.jpg"); //Get the image width and height float width = image.PhysicalDimension.Width; float height = image.PhysicalDimension.Height; //Add a page of the same size as the image PdfPageBase page = doc.Pages.Add(new SizeF(width, height)); //Create a PdfImage object based on the image PdfImage pdfImage = PdfImage.FromImage(image); //Draw image at (0, 0) of the page page.Canvas.DrawImage(pdfImage, 0, 0, pdfImage.Width, pdfImage.Height); //Save to file doc.SaveToFile("ConvertPdfWithSameSize.pdf"); } } }
【VB.NET】
Imports System.Drawing Imports Spire.Pdf Imports Spire.Pdf.Graphics Namespace ConvertImageToPdfWithSameSize Class Program Shared Sub Main(ByVal args() As String) 'Create a PdfDocument object Dim doc As PdfDocument = New PdfDocument() 'Set the margins to 0 doc.PageSettings.SetMargins(0) 'Load an image Dim image As Image = Image.FromFile("C:\Users\Administrator\Desktop\announcement.jpg") 'Get the image width and height Dim width As single = image.PhysicalDimension.Width Dim height As single = image.PhysicalDimension.Height 'Add a page of the same size as the image Dim page As PdfPageBase = doc.Pages.Add(New SizeF(width,height)) 'Create a PdfImage object based on the image Dim pdfImage As PdfImage = PdfImage.FromImage(image) 'Draw image at (0, 0) of the page page.Canvas.DrawImage(pdfImage, 0, 0, pdfImage.Width, pdfImage.Height) 'Save to file doc.SaveToFile("ConvertPdfWithSameSize.pdf") End Sub End Class End Namespace
以上便是如何将图像转换为 PDF,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。
欢迎下载|体验更多E-iceblue产品
获取更多信息请咨询慧都在线客服 ;技术交流Q群(767755948)
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com
PDF 的页面大小决定了其内容的显示、打印或处理方式。在准备打印、转换格式或标准化布局时,我们通常需要更改PDF文档的纸张大小。在本教程中,您将学习如何使用 Java 编辑任何 PDF 文件的页面大小。我们将通过完整的代码示例,逐步指导您完成操作。
本文主要介绍如何使用DevExpress WPF Grid控件中的节点(Nodes)概述,欢迎下载最新版组件体验!
本教程提供DevExpress WinFormsWinExplorer视图的基本信息,欢迎下载最新版组件体验!
无论是用于 Web 开发、图形设计还是数据可视化,调整SVG图像大小的能力都至关重要。Aspose.Imaging for Java库允许开发人员构建 SVG 图像调整器并轻松执行其他图像处理,为各行各业提供了灵活、易于集成的图像处理解决方案。
Spire.PDF for .NET是独立的PDF控件,用于.NET程序中创建、编辑和操作PDF文档
Spire.Doc for .NETSpire.Doc for .NET 是一款专门对 Word 文档进行操作的 .NET 类库。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@evget.com
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
慧都科技 版权所有 Copyright 2003-
2025 渝ICP备12000582号-13 渝公网安备
50010702500608号