Class PdfBitmap
The PdfBitmap contains methods and properties to handle the Bitmap images
Implements
Inherited Members
Namespace: Syncfusion.Pdf.Graphics
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public class PdfBitmap : PdfImage, IPdfWrapper, IDisposable
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the disk.
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the image from the disk.
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Draw the image
graphics.DrawImage(image, 0, 0)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Constructors
PdfBitmap(Image)
Initializes a new instance of the PdfBitmap class from the specified existing image.
Declaration
public PdfBitmap(Image image)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Image | image | The System.Drawing.Image from which to create the new Bitmap. |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load image from file
Image picture = Image.FromFile("Autumn Leaves.jpg");
//Load the image from the Image object
PdfBitmap image = new PdfBitmap(picture);
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load image from file
Dim picture As Image = Image.FromFile("Autumn Leaves.jpg")
'Load the image from the Image object
Dim image As New PdfBitmap(picture)
'Draw the image
graphics.DrawImage(image, 0, 0)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
PdfBitmap(Stream)
Initializes a new instance of the PdfBitmap class from the specified data stream.
Declaration
public PdfBitmap(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | The data stream used to load the image. |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the stream
PdfBitmap image = new PdfBitmap(File.OpenRead("Autumn Leaves.jpg"));
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the image from the stream
Dim image As New PdfBitmap(File.OpenRead("Autumn Leaves.jpg"))
'Draw the image
graphics.DrawImage(image, 0, 0)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
PdfBitmap(Stream, Boolean)
Initializes a new instance of the PdfBitmap class from the specified file.
Declaration
public PdfBitmap(Stream stream, bool enableMetadata)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | The data stream used to load the image. |
System.Boolean | enableMetadata | Enable metadata extraction from image |
Remarks
The file name and path can be relative to the application or an absolute path.
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the disk with enable metadata extraction.
PdfBitmap image = new PdfBitmap(File.OpenRead("Autumn Leaves.jpg"), true);
//Get image metadata
XmpMetadata metadata = image.Metadata;
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the image from the disk with enable metadata extraction.
Dim image As New PdfBitmap(File.OpenRead("Autumn Leaves.jpg"), true)
'Get image metadata
Dim metadata As XmpMetadata = image.Metadata
'Draw the image
graphics.DrawImage(image, 0, 0)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
PdfBitmap(String)
Initializes a new instance of the PdfBitmap class from the specified file.
Declaration
public PdfBitmap(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The bitmap file name and path. |
Remarks
The file name and path can be relative to the application or an absolute path.
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the disk with enable metadata extraction.
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg", true);
//Get image metadata
XmpMetadata metadata = image.Metadata;
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the image from the disk with enable metadata extraction.
Dim image As New PdfBitmap("Autumn Leaves.jpg", true)
'Get image metadata
Dim metadata As XmpMetadata = image.Metadata
'Draw the image
graphics.DrawImage(image, 0, 0)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
PdfBitmap(String, Boolean)
Initializes a new instance of the PdfBitmap class from the specified file.
Declaration
public PdfBitmap(string path, bool enableMetadata)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The bitmap file name and path. |
System.Boolean | enableMetadata | Enable metadata extraction from image |
Remarks
The file name and path can be relative to the application or an absolute path.
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the disk.
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg", true);
//Get image metadata
XmpMetadata metadata = image.Metadata;
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the image from the disk.
Dim image As New PdfBitmap("Autumn Leaves.jpg", true)
'Get image metadata
Dim metadata As XmpMetadata = image.Metadata
'Draw the image
graphics.DrawImage(image, 0, 0)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Properties
ActiveFrame
Gets or sets the active frame of the image.
Declaration
public int ActiveFrame { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The index of the active frame. |
Examples
//Create a PDF document
PdfDocument pdfDocument = new PdfDocument();
//Add a section to the PDF document
PdfSection section = pdfDocument.Sections.Add();
//Declare the PDF page
PdfPage page;
//Declare PDF page graphics
PdfGraphics graphics;
//Load multi frame Tiff image
PdfBitmap tiffImage = new PdfBitmap("image.tiff");
//Get the frame count
int frameCount = tiffImage.FrameCount;
//Access each frame draw into the page
for (int i = 0; i!=frameCount-1; i++)
{
page = section.Pages.Add();
section.PageSettings.Margins.All = 0;
graphics = page.Graphics;
tiffImage.ActiveFrame = i;
graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);
}
//Save and close the document
pdfDocument.Save("Sample.pdf");
pdfDocument.Close(true);
'Create a PDF document///Dim pdfDocument As New PdfDocument()
'Add a section to the PDF document
Dim section As PdfSection = pdfDocument.Sections.Add()
'Declare the PDF page
Dim page As PdfPage
'Declare PDF page graphics
Dim graphics As PdfGraphics
'Load multi frame Tiff image
Dim tiffImage As New PdfBitmap("image.tiff")
'Get the frame count
Dim frameCount As Integer = tiffImage.FrameCount
'Access each frame draw into the page
For i As Integer = 0 To frameCount - 1
page = section.Pages.Add()
section.PageSettings.Margins.All = 0
graphics = page.Graphics
tiffImage.ActiveFrame = i
graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height)
Next
'Save and close the document
pdfDocument.Save("Sample.pdf")
pdfDocument.Close(True)
Encoding
Declaration
public EncodingType Encoding { get; set; }
Property Value
Type | Description |
---|---|
EncodingType |
FrameCount
Gets the number of frames in the bitmap (Read only).
Declaration
public int FrameCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The frame count of the image. |
Examples
//Create a PDF document
PdfDocument pdfDocument = new PdfDocument();
//Add a section to the PDF document
PdfSection section = pdfDocument.Sections.Add();
//Declare the PDF page
PdfPage page;
//Declare PDF page graphics
PdfGraphics graphics;
//Load multi frame Tiff image
PdfBitmap tiffImage = new PdfBitmap("image.tiff");
//Get the frame count
int frameCount = tiffImage.FrameCount;
//Access each frame draw into the page
for (int i = 0; i!=frameCount-1; i++)
{
page = section.Pages.Add();
section.PageSettings.Margins.All = 0;
graphics = page.Graphics;
tiffImage.ActiveFrame = i;
graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);
}
//Save and close the document
pdfDocument.Save("Sample.pdf");
pdfDocument.Close(true);
'Create a PDF document///Dim pdfDocument As New PdfDocument()
'Add a section to the PDF document
Dim section As PdfSection = pdfDocument.Sections.Add()
'Declare the PDF page
Dim page As PdfPage
'Declare PDF page graphics
Dim graphics As PdfGraphics
'Load multi frame Tiff image
Dim tiffImage As New PdfBitmap("image.tiff")
'Get the frame count
Dim frameCount As Integer = tiffImage.FrameCount
'Access each frame draw into the page
For i As Integer = 0 To frameCount - 1
page = section.Pages.Add()
section.PageSettings.Margins.All = 0
graphics = page.Graphics
tiffImage.ActiveFrame = i
graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height)
Next
'Save and close the document
pdfDocument.Save("Sample.pdf")
pdfDocument.Close(True)
Mask
Gets or sets the mask of bitmap.
Declaration
public PdfMask Mask { get; set; }
Property Value
Type | Description |
---|---|
PdfMask | New PdfMask represents the mask image. |
Examples
//Create a PDF document
PdfDocument doc = new PdfDocument();
//Add pages to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the Tiff image
PdfBitmap image = new PdfBitmap("image.tif");
//Create masking image
PdfImageMask mask = new PdfImageMask(new PdfBitmap("mask.bmp"));
image.Mask = mask;
//Draw the image
graphics.DrawImage(image, 0, 0);
//Saves the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);
'Create a PDF document
Dim doc As New PdfDocument()
'Add pages to the document
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the Tiff image
Dim image As New PdfBitmap("image.tif")
'Create masking image
Dim mask As New PdfImageMask(New PdfBitmap("mask.bmp"))
image.Mask = mask
'Draw the image
graphics.DrawImage(image, 0, 0)
'Saves the document
doc.Save("Output.pdf")
'Close the document
doc.Close(True)
Quality
Gets or sets the quality of the image.
Declaration
public long Quality { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 |
Remarks
When the image is stored into PDF not as a mask, you may reduce its quality, which saves the disk space.
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the disk.
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");
//Set image quality.
image.Quality = 50;
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the image from the disk.
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Set image quality.
image.Quality = 50
'Draw the image
graphics.DrawImage(image, 0, 0)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the disk.
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");
//Draw the image
graphics.DrawImage(image, 0, 0);
//Dispose the image object.
image.Dispose();
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the image from the disk.
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Draw the image
graphics.DrawImage(image, 0, 0)
'Dispose the image object.
image.Dispose()
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Finalize()
Releases unmanaged resources and performs other cleanup operations before the PdfBitmap is reclaimed by garbage collection.
Declaration
protected void Finalize()