Class ImageToPdfConverter
The ImageToPdfConverter class can be used to create PDF documents from images. It accepts both image files and Bitmap objects as input.
The ImageToPdf static methods create simple PDF documents containing each image as one page of the created PDF.
To rasterize PDF documents as
images (the reverse operation), see
Inheritance
Namespace: IronPdf
Assembly: IronPdf.dll
Syntax
public static class ImageToPdfConverter : Object
Methods
ImageToPdf(AnyBitmap, ImageBehavior, ChromePdfRenderOptions)
Converts a single IronSoftware.Drawing.AnyBitmap object or Bitmap to a PDF document of matching dimensions. The default PaperSize is A4. You can set it via ImageToPdfConverter.PaperSize. Note: Imaging.ImageBehavior.CropPage will set PaperSize equal to ImageSize.
Declaration
public static PdfDocument ImageToPdf(AnyBitmap image, ImageBehavior behavior, ChromePdfRenderOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
IronSoftware.Drawing.AnyBitmap | image | The image object. Requires a project reference to the IronSoftware.System.Drawing Assembly. |
ImageBehavior | behavior | Describes how image should be placed on the PDF page |
ChromePdfRenderOptions | options | Rendering options |
Returns
Type | Description |
---|---|
PdfDocument | Returns a PdfDocument document which can then be edited, saved or served over the web. |
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | The file does not have a supported image format. Supported files: .apng, .avif, .bmp, .cur, .dib, .gif, .ico, .jfif, .jif, .jpe, .jpeg, .jpg, .pjp, .pjpeg, .png, .svg, .tif, .tiff, .webp |
System.IO.FileNotFoundException |
ImageToPdf(IEnumerable<AnyBitmap>, ImageBehavior, ChromePdfRenderOptions)
Converts multiple IronSoftware.Drawing.AnyBitmap objects or Bitmaps into a PDF document. Each image creates 1 page which matches the image dimensions. The default PaperSize is A4. You can set it via ImageToPdfConverter.PaperSize. Note: Imaging.ImageBehavior.CropPage will set PaperSize equal to ImageSize.
Declaration
public static PdfDocument ImageToPdf(IEnumerable<AnyBitmap> images, ImageBehavior behavior, ChromePdfRenderOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<IronSoftware.Drawing.AnyBitmap> | images | The image objects. Requires a project reference to the IronSoftware.System.Drawing Assembly. |
ImageBehavior | behavior | Describes how image should be placed on the PDF page |
ChromePdfRenderOptions | options | Rendering options |
Returns
Type | Description |
---|---|
PdfDocument | Returns a PdfDocument document which can then be edited, saved or served over the web. |
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | The file does not have a supported image format. Supported files: .apng, .avif, .bmp, .cur, .dib, .gif, .ico, .jfif, .jif, .jpe, .jpeg, .jpg, .pjp, .pjpeg, .png, .svg, .tif, .tiff, .webp |
System.IO.FileNotFoundException |
ImageToPdf(IEnumerable<String>, ImageBehavior, ChromePdfRenderOptions)
Converts multiple image files to a PDF document. Each image creates 1 page which matches the image dimensions. The default PaperSize is A4. You can set it via ImageToPdfConverter.PaperSize. Note: Imaging.ImageBehavior.CropPage will set PaperSize equal to ImageSize.
Declaration
public static PdfDocument ImageToPdf(IEnumerable<string> imageFileNames, ImageBehavior behavior, ChromePdfRenderOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.String> | imageFileNames | The image file path names. |
ImageBehavior | behavior | Describes how image should be placed on the PDF page |
ChromePdfRenderOptions | options | Rendering options |
Returns
Type | Description |
---|---|
PdfDocument | Returns a PdfDocument document which can then be edited, saved or served over the web. |
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | The file does not have a supported image format. Supported files: .apng, .avif, .bmp, .cur, .dib, .gif, .ico, .jfif, .jif, .jpe, .jpeg, .jpg, .pjp, .pjpeg, .png, .svg, .tif, .tiff, .webp |
System.IO.FileNotFoundException |
ImageToPdf(String, ImageBehavior, ChromePdfRenderOptions)
Converts a single image file to an identical PDF document of matching dimensions. The default PaperSize is A4. You can set it via ImageToPdfConverter.PaperSize. Note: Imaging.ImageBehavior.CropPage will set PaperSize equal to ImageSize.
Declaration
public static PdfDocument ImageToPdf(string imageFileName, ImageBehavior behavior, ChromePdfRenderOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | imageFileName | File path of the image file. |
ImageBehavior | behavior | Describes how image should be placed on the PDF page |
ChromePdfRenderOptions | options | Rendering options |
Returns
Type | Description |
---|---|
PdfDocument | Returns a PdfDocument document which can then be edited, saved or served over the web. |
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | The file does not have a supported image format. Supported files: .apng, .avif, .bmp, .cur, .dib, .gif, .ico, .jfif, .jif, .jpe, .jpeg, .jpg, .pjp, .pjpeg, .png, .svg, .tif, .tiff, .webp |
System.IO.FileNotFoundException |