#1 2025-12-17 13:16:33

Georgi
Member
Registered: 2025-12-17
Posts: 2

Clipping of a large metafile when outputing to a PDF

Hi,

I'm trying to save a large tree into a PDF file. The way it has worked so far is to have the tree moved around with only a portion overlapping the page and clipping rectangle making sure the page has margins and headers and stuff. This whole thing is then printed to a PDF printer and has worked well.

I'm now trying to reuse this code and print to a TPdfDocumentGDI using VCLCanvas.Draw(x,y, metafile). The issue I'm writing here about is that the tree is not getting clipped as I'm expecting (or hoping) to. It is getting outside.

I tried checking the EnumEMFFunc to see if some of the records in my metafile are not getting handled and got this list:
Unknown EMR: R^.iType=20 (EmfSetROP2)
Unknown EMR: R^.iType=115 (EmfSetLayout)
Unknown EMR: R^.iType=13 (EmfSetBrushOrgEx)

With the iType=20 (EmfSetROP2) showing up a bunch of times.

I really have no reason to single out the enumeration of the metafile record, no to focus on EmfSetROP2, it is just where I'm starting diagnosing this.

Can you suggest where I should look or what should I look for? Or any suggestion where to start picking at the issue?

I'm attaching, via OneDrive, the metafile, how it looks when saved to PDF via source code, and how it looks when printed via PDF printer(i.e. how I want it to look).

Metafile: 13.emf
via SynPDF code:SynPDF.RenderMetaFile.13.pdf
via PDF Printer: 13.PrintToPDF.pdf

Thanks!

Offline

#2 2025-12-17 13:18:04

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,346
Website

Re: Clipping of a large metafile when outputing to a PDF

Clipping is just not fully supported.

You may try to write some white rectangles to make the margins.

Offline

#3 2025-12-17 14:43:18

rvk
Member
Registered: 2022-04-14
Posts: 146

Re: Clipping of a large metafile when outputing to a PDF

If I use EMFexplorer I also see the run-off (so no clipping).
If I disable "Use GDI+" there (via Document, uncheck "Use GDI+"), the clipping does occur correctly.

In mormot.ui.pdf there is a RenderMetaFile() function (with EnumEnhMetaFile and a clipping parameter).
Did you try that?

What is the code to print after aMeta.LoadFromFile because I couldn't get the dimensions correct?
With factor scaling 0.1 the result I got here is this: https://i.imgur.com/afa83Iy.png
Which seems to be correct regarding the clipping.

Did you use the latest mormot2 (and not the old SynPdf source) ?

Offline

#4 2025-12-18 06:05:17

Georgi
Member
Registered: 2025-12-17
Posts: 2

Re: Clipping of a large metafile when outputing to a PDF

rvk wrote:

If I use EMFexplorer I also see the run-off (so no clipping).
If I disable "Use GDI+" there (via Document, uncheck "Use GDI+"), the clipping does occur correctly.

In mormot.ui.pdf there is a RenderMetaFile() function (with EnumEnhMetaFile and a clipping parameter).
Did you try that?

What is the code to print after aMeta.LoadFromFile because I couldn't get the dimensions correct?
With factor scaling 0.1 the result I got here is this: https://i.imgur.com/afa83Iy.png
Which seems to be correct regarding the clipping.

Did you use the latest mormot2 (and not the old SynPdf source) ?

Hi,

I'm using the latest SynPDF (downloaded from here https://github.com/synopse/SynPDF), source code bellow.
I'm going to try the mormot.ui.pdf and get back to you.

Thanks!


Metafile := TMetafile.Create;
Metafile.LoadFromFile('D:\Temp\EMF\SynPDF.RenderMetaFile\13.emf');
Metafile.Enhanced := false;

lPdf := TPdfDocumentGDI.Create;
lPdf.ScreenLogPixels:=600;
lPage := lPDF.AddPage;
lpdf.VCLCanvas.Draw(0,0, metafile);
lPdf.SaveToFile('D:\Temp\EMF\SynPDF.RenderMetaFile.13.NoText.pdf');

Last edited by Georgi (2025-12-18 06:05:37)

Offline

#5 2025-12-18 09:21:26

rvk
Member
Registered: 2022-04-14
Posts: 146

Re: Clipping of a large metafile when outputing to a PDF

Georgi wrote:

I'm using the latest SynPDF (downloaded from here https://github.com/synopse/SynPDF), source code bellow.

Yeah, that could be the reason.

I now tried it with the ScreenLogPixels and the result here is this (and you see that clipping is done correctly):
https://i.imgur.com/BWCFI5q.png

In your PrintToPDF there seems to be a missing footer?
It's printed slightly larger, so the footer is cut off.

Also... in the PrintToPDF, the line above the boxes at the right and the line above the lower right box seem to run against the overall border-line. But this isn't the case in the original EMF, is it? In the PDF from mORMot2, this is done correctly.

But... in mORMot2, the line of the boxes seem to be dotted instead of solid.
And the CH3 aren't placed correctly at the end of the lines.
https://i.imgur.com/8cAzoxg.png

Those last misplacements could be some small bugs in the GDI+ positioning in the mORMot2 code (which can be fixed if needed).

Offline

Board footer

Powered by FluxBB