DynaPDF Manual - Page 552

Previous Page 551   Index   Next Page 553

Function Reference
Page 552 of 839
LBOOL pdfInsertMetafileEx(
const PPDF* IPDF,
// Instance pointer
const void* Buffer, // Metafile buffer
UI32 BufSize,
// Buffer length
double PosX,
// X-Coordinate of output rectangle
double PosY,
// Y-Coordinate of output rectangle
double Width,
// Width of output rectangle
double Height)
// Height of output rectangle
The function converts an Enhanced Meta File (EMF) or Windows Meta File (WMF) to a native PDF
vector graphic in the same way as InsertMetafile(). However, this function requires a file buffer that
was returned by the API function GetEnhMetaFileBits(), GetWinMetaFileBits() or
GetMetaFileBitsEx(). Buffer can also be a file buffer of an EMF or WMF file.
This function is mostly used to convert EMF files which were already loaded into memory or
displayed on screen. Those memory based EMF or WMF files can directly be converted to PDF as
In this example we have already a handle of an enhanced metafile. This handle can be used to get
the file buffer of the EMF file:
Example 1 (C++):
// First, we need the size of the file buffer
SI32 bufSize = GetEnhMetaFileBits(emf, 0, NULL);
BYTE* buffer = (BYTE*)malloc(bufSize); // Allocate memory
if (!buffer) return -1; // Out of memory?
// Now we can get the file buffer
bufSize = GetEnhMetaFileBits(emf, bufSize, buffer);
// We convert the buffer directly to PDF
pdfSetPageCoords(pdf, pcTopDown);
pdfInsertMetafileEx(pdf, buffer, bufSize, 0, 0, pdfGetPageWidth(pdf), 0);
// Free the buffer
Example 2 (Delphi):
// emf is a TMetafile; we store the buffer in a TMemoryStream
Return values:
If the function succeeds the return value is 1. If the function fails the return value is 0.

Previous topic: How to convert spool EMF files?, Compatibility Note:

Next topic: InsertMetafileExt, InsertMetafileExtEx