Class PDFDC
<p>
PDFDC is a utility class used to represent a PDF Device Context (DC). Windows developers can use standard GDI or GDI+ API-s to write on PDFDC and to generate PDF documents based on their existing drawing functions. PDFDC can also be used to implement file conversion from any printable file format to PDF.
PDFDC class can be used in many ways to translate from GDI to PDF:- To translate a single GDI drawing into a single page PDF document.
- To translate a single GDI drawing into an object which can be reused many times throughout a PDF document (i.e. as a Form XObject).
- To translate many GDI drawings into single page or multipage PDF document. ...
// Start with a PDFDoc to put the picture into, and a PDFDC to translate GDI to PDF
PDFDoc pdfdoc;
PDFDC pdfDc;
// Create a page to put the GDI content onto
Page page = pdfdoc.PageCreate();
// Begin the translation from GDI to PDF.
// Provide the page to place the picture onto, and the bounding box for the content.
// We're going to scale the GDI content to fill the page while preserving the aspect
// ratio.
// Get back a GDI Device Context
HDC hDC = pdfDc.Begin( page, page.GetCropBox() );
// ... perform GDI drawing ...
// Complete the translation
pdfDc.End();
// Add the page to the document
pdfdoc.PagePushBack(page);
// Save the PDF document
pdfdoc.Save("PDFDC_is_cool.pdf", SDF.SDFDoc.SaveOptions.e_remove_unused, NULL);
Implements
Inherited Members
Namespace: pdftron.PDF
Assembly: PDFNet.dll
Syntax
public class PDFDC : IDisposable
Constructors
PDFDC()
Default constructor. Creates an empty new GDI to PDF translator.
Declaration
public PDFDC()
Methods
Begin(Page, Rect)
Begin the process of translating GDI drawing into a PDF, starting with the creation of a GDI Device Context.
Declaration
public Graphics Begin(Page in_page, Rect in_bbox)
Parameters
Type | Name | Description |
---|---|---|
Page | in_page | the page which will hold the converted GDI drawing. |
Rect | in_bbox | the location where the PDF objects will be placed on in_page |
Returns
Type | Description |
---|---|
Graphics | a GDI Handle to Display Context. |
Begin(Page, Rect, bool)
Begin the process of translating GDI drawing into a PDF, starting with the creation of a GDI Device Context.
Declaration
public Graphics Begin(Page in_page, Rect in_bbox, bool in_preserveAspectRatio)
Parameters
Type | Name | Description |
---|---|---|
Page | in_page | the page which will hold the converted GDI drawing. |
Rect | in_bbox | the location where the PDF objects will be placed on in_page |
bool | in_preserveAspectRatio | if true the aspect ratio of the GDI primitives will be preserved and the PDF objects will be centered within in_box. |
Returns
Type | Description |
---|---|
Graphics | a GDI Handle to Display Context. |
Remarks
If you wish to create a reusable FormX Object from the transformed page, create the page with the aspect ratio of the GDI drawing.
BeginHDC(Page, Rect)
Begin the process of translating GDI drawing into a PDF, starting with the creation of a GDI Device Context.
Declaration
public IntPtr BeginHDC(Page in_page, Rect in_bbox)
Parameters
Type | Name | Description |
---|---|---|
Page | in_page | the page which will hold the converted GDI drawing. |
Rect | in_bbox | the location where the PDF objects will be placed on in_page |
Returns
Type | Description |
---|---|
IntPtr | a GDI Handle to Display Context. |
Remarks
If you wish to create a reusable FormX Object from the transformed page, create the page with the aspect ratio of the GDI drawing.
BeginHDC(Page, Rect, bool)
Begin the process of translating GDI drawing into a PDF, starting with the creation of a GDI Device Context.
Declaration
public IntPtr BeginHDC(Page in_page, Rect in_bbox, bool in_preserveAspectRatio)
Parameters
Type | Name | Description |
---|---|---|
Page | in_page | the page which will hold the converted GDI drawing. |
Rect | in_bbox | the location where the PDF objects will be placed on in_page |
bool | in_preserveAspectRatio | if true the aspect ratio of the GDI primitives will be preserved and the PDF objects will be centered within in_box. |
Returns
Type | Description |
---|---|
IntPtr | a GDI Handle to Display Context. |
Remarks
If you wish to create a reusable FormX Object from the transformed page, create the page with the aspect ratio of the GDI drawing.
Dispose()
Releases all resources used by the PDFDC
Declaration
public override sealed void Dispose()
Dispose(bool)
Declaration
[HandleProcessCorruptedStateExceptions]
protected virtual void Dispose(bool A_0)
Parameters
Type | Name | Description |
---|---|---|
bool | A_0 |
End()
Closes the GDI Device Context, translating the GDI instruction to PDF, and adds the PDF objects to the page in the location specified by PDFDC::Begin( page, box, ...).
Declaration
public void End()
~PDFDC()
Declaration
protected ~PDFDC()
SetDPI(int)
Sets the conversion scale for translating between GDI drawing and PDF objects. DPI stands for Dots Per Inch. This parameter is used to specify the output image size and quality. A typical screen resolution for monitors these days is 92 DPI, but printers could use 200 DPI or more. In the case of GDI to PDF translation, this method fixes the scale or allows it to adjust to each GDI drawing between a Begin/End pair. Set the conversion DPI
Declaration
public void SetDPI(int in_dpi)
Parameters
Type | Name | Description |
---|---|---|
int | in_dpi |
Please note that this parameter does not affect the size the PDF nor does it affect the resolution of embedded images. |
Remarks
The size of resulting image is a function of DPI and the dimensions of the source PDF page. For example, if DPI is 92 and page is 8 inches tall, then a GDI graphic object of 92 Device Units will be one inch tall on the PDF page. If you would like to auto-scale the GDI drawing to fill the PDFDC bounding box, then use SetDPI(0).