ImportEMFFromStream
Vector graphics, Image handling
Description
Adds a WMF or EMF image from a TStream to the selected document
Once an image has been added to the document it can be drawn on any page multiple times without further increasing the size of the PDF file
Vector import starts with the default black pen and white brush unless the metafile selects other objects. Polylines remain open and use the selected pen; inside a path bracket each polyline starts an independent figure and is painted only when the path is drawn
On Windows, vector import preserves excluded and offset clips, all five region-combination modes, empty clips, clipping paths, and meta regions across saved device contexts. PaintRgn uses the selected brush. Clipping paths are converted from the native playback region to vector PDF clipping rectangles, with bounded region and path sizes
Shapes within path brackets are deferred until a path painting or clipping operation uses them. The lower-level TPDFMetafile converter exposes LastRecordError and raises an error identifying the record type and cause. Stream and file import return failure when conversion cannot complete; GetLastMetafileDiagnostics exposes record-level warnings and failures on the selected document
Text justification follows native GDI advance measurements for ANSI and Unicode text. Extra spacing also applies to explicit advance arrays, survives saved device contexts, and updates the current text position. Invalid text offsets, advance arrays, and break counts fail import; failure releases newly created fonts
On Windows, vector color management supports calibrated RGB, sRGB, the Windows default RGB space, embedded RGB source ICC data, and local-file RGB source profiles. Output and proof profiles are distinct from the input color space; RGB and CMYK output are converted to display RGB for PDF paints and decoded RGB bitmap data. Color state follows saved device contexts, including deferred source changes during proofing
ICM starts disabled. Query records retain the current mode, and externally managed colors bypass conversion. Unicode file names are supported; remote profile paths fail import. Limits are 16 MiB per profile, 64 MiB of unique retained profile data, and 4096 color spaces or state snapshots. DIB and hatch patterns retain their colors, background opacity, device origin, and saved color state; specialized color-managed alpha, masking, parallelogram, and transparent bitmap operations produce explicit qualification warnings
Use GetLastMetafileDiagnostics to distinguish complete, partial, failed, and rasterized imports, inspect unsupported records, and retain the cause of a failed conversion. Text inside path brackets contributes glyph outlines to the path without immediate painting
Syntax
Delphi
Function TPDFlib.ImportEMFFromStream(InStream: TStream; FontOptions, GeneralOptions: Integer): Integer;
Parameters
| InStream | The TStream object containing the EMF/WMF data |
|---|---|
| FontOptions | If GeneralOptions is 1 this parameter is ignored, otherwise the following values take effect: 0 = Use the first font added to the PDF 1 = Automatically add fonts as non-embedded TrueType fonts |
| GeneralOptions | 0 = Import as a vector image 1 = Import as a bitmap image |
Return values
Returns the image ID of the imported metafile, which also becomes the selected image. Returns 0 when the stream cannot be converted; GetLastMetafileDiagnostics exposes the record-level cause.