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 begins with the default black pen and white brush unless the metafile selects other objects itself. Polylines stay open and draw with the selected pen; within a path bracket each polyline opens its own figure and is only painted once the path is drawn
On Windows, vector import keeps excluded and offset clips, all five region-combination modes, empty clips, clipping paths and meta regions across saved device contexts. PaintRgn draws with the selected brush. Clipping paths are converted from the native playback region into vector PDF clipping rectangles, with region and path sizes kept within bounds
Shapes inside path brackets are held back until a path painting or clipping operation makes use of them. The lower-level TPDFMetafile converter exposes LastRecordError and raises an error naming the record type and cause. Stream and file import report failure when the conversion cannot be completed; GetLastMetafileDiagnostics reveals record-level warnings and failures on the selected document
Text justification follows the native GDI advance measurements for ANSI and Unicode text. Extra spacing likewise applies to explicit advance arrays, survives saved device contexts and updates the current text position. Invalid text offsets, advance arrays or break counts make the import fail; on failure the newly created fonts are released
On Windows, vector colour 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 separate from the input colour space; RGB and CMYK output is converted to display RGB for PDF paints and for decoded RGB bitmap data. Colour state follows saved device contexts, including source changes deferred whilst proofing
ICM starts disabled. Query records keep the current mode, and externally managed colours bypass conversion. Unicode file names are supported; remote profile paths make the import fail. The limits are 16 MiB per profile, 64 MiB of unique retained profile data, and 4096 colour spaces or state snapshots. DIB and hatch patterns keep their colours, background opacity, device origin and saved colour state; specialised colour-managed alpha, masking, parallelogram and transparent bitmap operations produce explicit qualification warnings
Use GetLastMetafileDiagnostics to tell complete, partial, failed and rasterised imports apart, examine unsupported records and keep hold of the cause of a failed conversion. Text inside path brackets contributes glyph outlines to the path without being painted immediately
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.