Table of Contents

Class PdfUnitConvertor

Namespace
Syncfusion.Pdf.Graphics
Assembly
Syncfusion.Pdf.Portable.dll

Class allowing to convert different unit metrics. Converting is based on Graphics object DPI settings that is why for differ graphics settings must be created new instance. For example: printers often has 300 and greater dpi resolution, for compare default display screen dpi is 96.

[Obsolete("Please use PdfUnitConverter instead")]
public class PdfUnitConvertor
Inheritance
PdfUnitConvertor
Inherited Members

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF bitmap instance.
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");
//Create a PDF unit converter instance.
PdfUnitConvertor converter = new PdfUnitConvertor();
//Convert to point.
float width = converter.ConvertFromPixels(image.Width, PdfGraphicsUnit.Point);
float height = converter.ConvertFromPixels(image.Height, PdfGraphicsUnit.Point);
//Draw image to PDF page.
page.Graphics.DrawImage(image, new RectangleF(0, 0, width, height));
//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 bitmap instance.
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Create a PDF unit converter instance.
Dim converter As New PdfUnitConvertor()
'Convert to point.
Dim width As Single = converter.ConvertFromPixels(image.Width, PdfGraphicsUnit.Point)
Dim height As Single = converter.ConvertFromPixels(image.Height, PdfGraphicsUnit.Point)
'Draw image to PDF page.
page.Graphics.DrawImage(image, New RectangleF(0, 0, width, height))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

Constructors

PdfUnitConvertor()

Initializes a new instance of the PdfUnitConvertor class with default DPI value of 96.

public PdfUnitConvertor()

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF bitmap instance.
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");
//Create a PDF unit converter instance.
PdfUnitConvertor converter = new PdfUnitConvertor();
//Convert to point.
float width = converter.ConvertFromPixels(image.Width, PdfGraphicsUnit.Point);
float height = converter.ConvertFromPixels(image.Height, PdfGraphicsUnit.Point);
//Draw image to PDF page.
page.Graphics.DrawImage(image, new RectangleF(0, 0, width, height));
//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 bitmap instance.
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Create a PDF unit converter instance.
Dim converter As New PdfUnitConvertor()
'Convert to point.
Dim width As Single = converter.ConvertFromPixels(image.Width, PdfGraphicsUnit.Point)
Dim height As Single = converter.ConvertFromPixels(image.Height, PdfGraphicsUnit.Point)
'Draw image to PDF page.
page.Graphics.DrawImage(image, New RectangleF(0, 0, width, height))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

PdfUnitConvertor(float)

Initializes a new instance of the UnitConvertor class with DPI value

public PdfUnitConvertor(float dpi)

Parameters

dpi float

The dpi.

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF bitmap instance.
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");
//Create a PDF unit converter instance.
PdfUnitConvertor converter = new PdfUnitConvertor(360);
//Convert to point.
float width = converter.ConvertFromPixels(image.Width, PdfGraphicsUnit.Point);
float height = converter.ConvertFromPixels(image.Height, PdfGraphicsUnit.Point);
//Draw image to PDF page.
page.Graphics.DrawImage(image, new RectangleF(0, 0, width, height));
//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 bitmap instance.
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Create a PDF unit converter instance.
Dim converter As New PdfUnitConvertor(360)
'Convert to point.
Dim width As Single = converter.ConvertFromPixels(image.Width, PdfGraphicsUnit.Point)
Dim height As Single = converter.ConvertFromPixels(image.Height, PdfGraphicsUnit.Point)
'Draw image to PDF page.
page.Graphics.DrawImage(image, New RectangleF(0, 0, width, height))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

Methods

ConvertFromPixels(PointF, PdfGraphicsUnit)

Converts rectangle from pixels to specified units

public PointF ConvertFromPixels(PointF point, PdfGraphicsUnit to)

Parameters

point PointF

point in pixels units

to PdfGraphicsUnit

convert to units

Returns

PointF

output Point in specified units

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF bitmap instance.
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");
//Create a PDF unit converter instance.
PdfUnitConvertor converter = new PdfUnitConvertor();
//Convert to point.     
PointF location = converter.ConvertFromPixels(new PointF(100,100), PdfGraphicsUnit.Point);
//Draw image to PDF page.
page.Graphics.DrawImage(image, new RectangleF(location, image.GetBounds().Size));
//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 bitmap instance.
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Create a PDF unit converter instance.
Dim converter As New PdfUnitConvertor()
'Convert to point.       
Dim location As PointF = converter.ConvertFromPixels(New PointF(100,100), PdfGraphicsUnit.Point)
'Draw image to PDF page.
page.Graphics.DrawImage(image, New RectangleF(location, image.GetBounds().Size))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

ConvertFromPixels(RectangleF, PdfGraphicsUnit)

Converts rectangle in Pixels into rectangle with specified measure units

public RectangleF ConvertFromPixels(RectangleF rect, PdfGraphicsUnit to)

Parameters

rect RectangleF

source rectangle in pixels units

to PdfGraphicsUnit

convert to units

Returns

RectangleF

output Rectangle in specified units

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF bitmap instance.
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");
//Create a PDF unit converter instance.
PdfUnitConvertor converter = new PdfUnitConvertor();
//Convert to point.
RectangleF rect = converter.ConvertFromPixels(new RectangleF(100,100,500, 700), PdfGraphicsUnit.Point);  
//Draw image to PDF page.
page.Graphics.DrawImage(image, rect);
//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 bitmap instance.
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Create a PDF unit converter instance.
Dim converter As New PdfUnitConvertor()
'Convert to point.
Dim rect As RectangleF = converter.ConvertFromPixels(New RectangleF(100,100,500, 700), PdfGraphicsUnit.Point)  
'Draw image to PDF page.
page.Graphics.DrawImage(image, rect)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

ConvertFromPixels(SizeF, PdfGraphicsUnit)

Converts Size in pixels to size in specified measure units

public SizeF ConvertFromPixels(SizeF size, PdfGraphicsUnit to)

Parameters

size SizeF

source size

to PdfGraphicsUnit

convert to units

Returns

SizeF

output size in specified measure units

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF bitmap instance.
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");
//Create a PDF unit converter instance.
PdfUnitConvertor converter = new PdfUnitConvertor();
//Convert to point.
SizeF size = converter.ConvertFromPixels(image.GetBounds().Size, PdfGraphicsUnit.Point);
//Draw image to PDF page.
page.Graphics.DrawImage(image, new RectangleF( new PointF(0, 0), size));
//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 bitmap instance.
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Create a PDF unit converter instance.
Dim converter As New PdfUnitConvertor()
'Convert to point.
Dim size As SizeF = converter.ConvertFromPixels(image.GetBounds().Size, PdfGraphicsUnit.Point)       
'Draw image to PDF page.
page.Graphics.DrawImage(image, New RectangleF(New PointF(0, 0), size))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

ConvertFromPixels(float, PdfGraphicsUnit)

Converts value, to specified graphics unit from Pixel.

public float ConvertFromPixels(float value, PdfGraphicsUnit to)

Parameters

value float

Value to convert

to PdfGraphicsUnit

Indicates units to convert to

Returns

float

Value stored in "to" units

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF bitmap instance.
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");
//Create a PDF unit converter instance.
PdfUnitConvertor converter = new PdfUnitConvertor();
//Convert to point.
float width = converter.ConvertFromPixels(image.Width, PdfGraphicsUnit.Point);
float height = converter.ConvertFromPixels(image.Height, PdfGraphicsUnit.Point);
//Draw image to PDF page.
page.Graphics.DrawImage(image, new RectangleF(0, 0, width, height));
//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 bitmap instance.
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Create a PDF unit converter instance.
Dim converter As New PdfUnitConvertor()
'Convert to point.
Dim width As Single = converter.ConvertFromPixels(image.Width, PdfGraphicsUnit.Point)
Dim height As Single = converter.ConvertFromPixels(image.Height, PdfGraphicsUnit.Point)
'Draw image to PDF page.
page.Graphics.DrawImage(image, New RectangleF(0, 0, width, height))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

ConvertToPixels(PointF, PdfGraphicsUnit)

Converts point from specified graphics units to pixels

public PointF ConvertToPixels(PointF point, PdfGraphicsUnit from)

Parameters

point PointF

source point for convert

from PdfGraphicsUnit

measure units

Returns

PointF

point in pixels coordinates

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF unitconverter.
PdfUnitConvertor converter = new PdfUnitConvertor();
//Convert to pixels.
PointF location = converter.ConvertToPixels(new PointF(100, 100), PdfGraphicsUnit.Point);
page.Graphics.DrawRectangle(PdfPens.Red, new RectangleF(location, new SizeF(200, 50));
//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 new PDF unitconverter.
Dim converter As New PdfUnitConvertor()
'Convert to pixels.
Dim location As PointF = converter.ConvertToPixels(New PointF(100, 100), PdfGraphicsUnit.Point)
page.Graphics.DrawRectangle(PdfPens.Red, new RectangleF(location, new SizeF(200, 50))
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

ConvertToPixels(RectangleF, PdfGraphicsUnit)

Converts the rectangle location and size to Pixels from specified measure units

public RectangleF ConvertToPixels(RectangleF rect, PdfGraphicsUnit from)

Parameters

rect RectangleF

source rectangle

from PdfGraphicsUnit

source rectangle measure units

Returns

RectangleF

Rectangle with Pixels

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF unitconverter.
PdfUnitConvertor converter = new PdfUnitConvertor();
//Convert to pixels.
 RectangleF rect = converter.ConvertToPixels(new RectangleF(100, 100, 200, 100), PdfGraphicsUnit.Point);
 page.Graphics.DrawRectangle(PdfPens.Red, rect);
//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 new PDF unitconverter.
Dim converter As New PdfUnitConvertor()
'Convert to pixels.
Dim rect As RectangleF = converter.ConvertToPixels(New RectangleF(100, 100, 200, 100), PdfGraphicsUnit.Point)
page.Graphics.DrawRectangle(PdfPens.Red, rect)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

ConvertToPixels(SizeF, PdfGraphicsUnit)

Converts size from specified graphics units to pixels

public SizeF ConvertToPixels(SizeF size, PdfGraphicsUnit from)

Parameters

size SizeF

source size

from PdfGraphicsUnit

measure units

Returns

SizeF

size in pixels

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF unitconverter.
PdfUnitConvertor converter = new PdfUnitConvertor();
//Convert to pixels.
 SizeF pageSize = converter.ConvertToPixels(doc.PageSettings.Size, PdfGraphicsUnit.Point);
 page.Graphics.DrawString("PDF page size is " + pageSize + " pixel", new PdfStandardFont(PdfFontFamily.Helvetica,12),PdfBrushes.Red, PointF.Empty);
//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 new PDF unitconverter.
Dim converter As New PdfUnitConvertor()
'Convert to pixels.
Dim pageSize As SizeF = converter.ConvertToPixels(doc.PageSettings.Size, PdfGraphicsUnit.Point)
page.Graphics.DrawString("PDF page size is " + pageSize + " pixel", New PdfStandardFont(PdfFontFamily.Helvetica, 12), PdfBrushes.Red, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

ConvertToPixels(float, PdfGraphicsUnit)

Converts the value to pixel from specified graphics unit.

public float ConvertToPixels(float value, PdfGraphicsUnit from)

Parameters

value float

Value to convert

from PdfGraphicsUnit

Indicates units to convert from

Returns

float

Value stored in pixels

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF unitconverter.
PdfUnitConvertor converter = new PdfUnitConvertor();
//Convert to pixels.
float pageWidth = converter.ConvertToPixels(doc.PageSettings.Size.Width, PdfGraphicsUnit.Point);
page.Graphics.DrawString("PDF page width is " + pageWidth + " pixel", new PdfStandardFont(PdfFontFamily.Helvetica,12),PdfBrushes.Red, PointF.Empty);
//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 new PDF unitconverter.
Dim converter As New PdfUnitConvertor()
'Convert to pixels.
Dim pageWidth As Single = converter.ConvertToPixels(doc.PageSettings.Size.Width, PdfGraphicsUnit.Point)
page.Graphics.DrawString("PDF page width is " + pageWidth + " pixel", New PdfStandardFont(PdfFontFamily.Helvetica, 12), PdfBrushes.Red, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

ConvertUnits(float, PdfGraphicsUnit, PdfGraphicsUnit)

Converts the value, from one graphics unit to another graphics unit.

public float ConvertUnits(float value, PdfGraphicsUnit from, PdfGraphicsUnit to)

Parameters

value float

Value to convert

from PdfGraphicsUnit

Indicates units to convert from

to PdfGraphicsUnit

Indicates units to convert to

Returns

float

Value stored in "to" units