Class ImageToPdfConverter
The ImageToPdfConveter class can be used to create PDF documents from images. It accepts both image files and System.Drawing.Image 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 ToBitmap(Int32) and RasterizeToImageFiles(String, ImageType, Int32)
Inheritance
Namespace: IronPdf
Assembly: IronPdf.dll
Syntax
public static class ImageToPdfConverter : Object
Properties
PaperSize
Declaration
public static PdfPaperSize PaperSize { get; set; }
Property Value
Type | Description |
---|---|
PdfPaperSize |
Methods
ImageToPdf(IEnumerable<Image>, ImageBehavior)
Converts multiple System.Drawing.Image 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<Image> images, ImageBehavior behavior)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Drawing.Image> | images | The image objects. Requires a project reference to the System.Drawing Assembly. |
ImageBehavior | behavior | Describes how image should be placed on the PDF page |
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)
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)
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 |
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(Image, ImageBehavior)
Converts a single System.Drawing.Image 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(Image image, ImageBehavior behavior)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Image | image | The image object. Requires a project reference to the System.Drawing Assembly. |
ImageBehavior | behavior | Describes how image should be placed on the PDF page |
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)
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)
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 |
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 |