在ImageToPdf静态方法将图像转换为PDF文档。 此方法只需提供图像的文件路径,并将其转换为具有默认图像位置和行为的 PDF 文档。 支持的图像格式包括.bmp、.jpeg、.jpg、.gif、.png、.svg、.tif、.tiff、.webp、.apng、.avif、.cur、.dib、.ico、.jfif、.jif、.jpe、.pjp和.pjpeg。
using IronPdf;string imagePath = "meetOurTeam.jpg";// Convert an image to a PDFPdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath);// Export the PDFpdf.SaveAs("imageToPdf.pdf");
using IronPdf;
string imagePath = "meetOurTeam.jpg";
// Convert an image to a PDF
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath);
// Export the PDF
pdf.SaveAs("imageToPdf.pdf");
ImportsIronPdfPrivate imagePath AsString = "meetOurTeam.jpg"' Convert an image to a PDFPrivate pdf AsPdfDocument = ImageToPdfConverter.ImageToPdf(imagePath)' Export the PDFpdf.SaveAs("imageToPdf.pdf")
Imports IronPdf
Private imagePath As String = "meetOurTeam.jpg"
' Convert an image to a PDF
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePath)
' Export the PDF
pdf.SaveAs("imageToPdf.pdf")
using IronPdf;using System;using System.Collections.Generic;using System.IO;using System.Linq;// Retrieve all JPG and JPEG image paths in the 'images' folder.IEnumerable<String> imagePaths = Directory.EnumerateFiles("images").Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));// Convert images to a PDFPdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePaths);// Export the PDFpdf.SaveAs("imagesToPdf.pdf");
using IronPdf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
// Retrieve all JPG and JPEG image paths in the 'images' folder.
IEnumerable<String> imagePaths = Directory.EnumerateFiles("images").Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));
// Convert images to a PDF
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePaths);
// Export the PDF
pdf.SaveAs("imagesToPdf.pdf");
ImportsIronPdfImportsSystemImportsSystem.Collections.GenericImportsSystem.IOImportsSystem.Linq' Retrieve all JPG and JPEG image paths in the 'images' folder.Private imagePaths AsIEnumerable(OfString) = Directory.EnumerateFiles("images").Where(Function(f) f.EndsWith(".jpg") OrElse f.EndsWith(".jpeg"))' Convert images to a PDFPrivate pdf AsPdfDocument = ImageToPdfConverter.ImageToPdf(imagePaths)' Export the PDFpdf.SaveAs("imagesToPdf.pdf")
Imports IronPdf
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
' Retrieve all JPG and JPEG image paths in the 'images' folder.
Private imagePaths As IEnumerable(Of String) = Directory.EnumerateFiles("images").Where(Function(f) f.EndsWith(".jpg") OrElse f.EndsWith(".jpeg"))
' Convert images to a PDF
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePaths)
' Export the PDF
pdf.SaveAs("imagesToPdf.pdf")
多图像 PDF 看起来像什么?
我最喜欢的这种库是 IronPDF。它允许快速高效地操作 PDF 文件。它还具有许多有价值的功能,比如导出为 PDF/A 格式和数字签名 PDF 文档。
using IronPdf;using IronPdf.Imaging;string imagePath = "meetOurTeam.jpg";// Convert an image to a PDF with image behavior of centered on pagePdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath, ImageBehavior.CenteredOnPage);// Export the PDFpdf.SaveAs("imageToPdf.pdf");
using IronPdf;
using IronPdf.Imaging;
string imagePath = "meetOurTeam.jpg";
// Convert an image to a PDF with image behavior of centered on page
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath, ImageBehavior.CenteredOnPage);
// Export the PDF
pdf.SaveAs("imageToPdf.pdf");
ImportsIronPdfImportsIronPdf.ImagingPrivate imagePath AsString = "meetOurTeam.jpg"' Convert an image to a PDF with image behavior of centered on pagePrivate pdf AsPdfDocument = ImageToPdfConverter.ImageToPdf(imagePath, ImageBehavior.CenteredOnPage)' Export the PDFpdf.SaveAs("imageToPdf.pdf")
Imports IronPdf
Imports IronPdf.Imaging
Private imagePath As String = "meetOurTeam.jpg"
' Convert an image to a PDF with image behavior of centered on page
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePath, ImageBehavior.CenteredOnPage)
' Export the PDF
pdf.SaveAs("imageToPdf.pdf")
using IronPdf;string imagePath = "meetOurTeam.jpg";ChromePdfRenderOptions options = new ChromePdfRenderOptions(){HtmlHeader = new HtmlHeaderFooter() {HtmlFragment = "<h1 style='color: #2a95d5;'>Content Header</h1>",DrawDividerLine = true, },};// Convert an image to a PDF with custom headerPdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath, options: options);// Export the PDFpdf.SaveAs("imageToPdfWithHeader.pdf");
using IronPdf;
string imagePath = "meetOurTeam.jpg";
ChromePdfRenderOptions options = new ChromePdfRenderOptions()
{
HtmlHeader = new HtmlHeaderFooter()
{
HtmlFragment = "<h1 style='color: #2a95d5;'>Content Header</h1>",
DrawDividerLine = true,
},
};
// Convert an image to a PDF with custom header
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath, options: options);
// Export the PDF
pdf.SaveAs("imageToPdfWithHeader.pdf");
ImportsIronPdfPrivate imagePath AsString = "meetOurTeam.jpg"Private options As New ChromePdfRenderOptions() With { .HtmlHeader = New HtmlHeaderFooter() With { .HtmlFragment = "<h1 style='color: #2a95d5;'>Content Header</h1>", .DrawDividerLine = True }}' Convert an image to a PDF with custom headerPrivate pdf AsPdfDocument = ImageToPdfConverter.ImageToPdf(imagePath, options:= options)' Export the PDFpdf.SaveAs("imageToPdfWithHeader.pdf")
Imports IronPdf
Private imagePath As String = "meetOurTeam.jpg"
Private options As New ChromePdfRenderOptions() With {
.HtmlHeader = New HtmlHeaderFooter() With {
.HtmlFragment = "<h1 style='color: #2a95d5;'>Content Header</h1>",
.DrawDividerLine = True
}
}
' Convert an image to a PDF with custom header
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePath, options:= options)
' Export the PDF
pdf.SaveAs("imageToPdfWithHeader.pdf")
如需了解更复杂的页眉和页脚要求,请参阅我们的HTML页眉和页脚综合指南。 您还可以在基于图像的 PDF 中添加 页码,以便更好地组织。
要使用 IronPDF 将单张图片转换为 PDF,请使用 ImageToPdfConverter 类中的 ImageToPdf 静态方法。只需提供图片的文件路径即可:IronPdf.ImageToPdfConverter.ImageToPdf("path/to/image.png").SaveAs("imageToPdf.pdf").这种单行解决方案可将图片转换为 PDF 文档,并采用默认的位置和行为。
能否将多个图像转换成一个 PDF 文档?
是的,IronPDF 可让您使用 ImageToPdfConverter.ImageToPdf 方法将多张图片(JPG、PNG、TIFF)转换为单个 PDF 文档。这非常适合用于创建数字作品集、演示文稿或报告,您需要将多个图像文件合并为一个有组织、普遍可读的 PDF 格式。
将图像转换为 PDF 时有哪些自定义选项?
IronPDF 提供广泛的自定义选项,包括独特的图像位置和行为(贴合页面、居中、裁剪)、添加文本和 HTML 页眉和页脚、应用水印、设置自定义页面大小,以及包括背景和前景叠加。有了这些功能,您就可以利用图像创建专业的 PDF 文档。
图像到 PDF 的转换功能支持哪些平台?
IronPDF 的图像到 PDF 转换功能可在 Windows、macOS 和 Linux 平台上无缝运行,使其成为适用于各种开发环境的通用工具。您可以通过 NuGet 安装,或下载 Windows 安装程序,在自己喜欢的平台上开始使用。
转换为 PDF 时如何控制图像位置?
IronPDF 提供独特的图像放置和行为,包括贴合页面、页面居中和裁剪页面。这些导出图像行为可让您精确控制图像在最终 PDF 文档中的显示效果,确保视觉内容的专业呈现。
What are the rendering customization options available in IronPDF?
IronPDF allows you to use the `ChromePdfRenderOptions` object to customize the rendering process. This includes options like JavaScript execution, CSS media types, and custom headers. You can also incorporate web fonts and icons for a more polished document.
Is it possible to convert a PDF back to an image using IronPDF?
Yes, IronPDF supports converting or rasterizing PDF documents back into images. This can be useful for various applications that require different formats for distribution or presentation.
Can IronPDF work on different operating systems?
IronPDF is versatile and can operate across Windows, macOS, and Linux environments, making it an excellent choice for various development platforms.
How do I optimize PDF size when combining multiple images using IronPDF?
IronPDF offers PDF compression options to optimize the file size when merging multiple images. It's especially useful when creating large digital portfolios or photo albums, ensuring quality is maintained without large file sizes.