#1 2013-01-15 14:53:40

cedo
Member
Registered: 2012-11-21
Posts: 15

Problem with drawing metafile

Hello

We have the following code:

const
  OutputFileName = 'test.pdf';
  InputFileName = 'test.emf';
var
  PdfDoc: TPDFDocumentGDI;
  PdfPage: TPdfpage;
  Emf: TMetafile;
begin
  Emf := TMetafile.Create();
  Emf.LoadFromFile(InputFileName);

  PdfDoc := TPdfDocumentGDI.Create;
  PdfDoc.CompressionMethod := cmFlateDecode;
  PdfDoc.DefaultPaperSize := psUserDefined;
  PdfPage := PdfDoc.AddPage();
  PdfPage.PageWidth := Round(72 * Emf.MMWidth / 2540);
  PdfPage.PageHeight := Round(72 * Emf.MMHeight / 2540);
  PdfDoc.VCLCanvas.StretchDraw(Rect(0, 0, Round(Screen.PixelsPerInch * Emf.MMWidth / 2540), Round(Screen.PixelsPerInch * Emf.MMHeight / 2540)), Emf);
  PdfDoc.SaveToFile(OutputFileName);
  PdfDoc.Free();

  FreeAndNil(Emf);
end;

You can download my metafile from here:
https://docs.google.com/file/d/0B5Z5axE … dCN00/edit

The ouput file ha some artefacts (unnecessary frames):
https://docs.google.com/file/d/0B5Z5axE … dnMnc/edit

Offline

#2 2013-01-15 15:23:41

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: Problem with drawing metafile

How are your low brackets drawn?

Using a font?

Offline

#3 2013-01-15 15:35:32

cedo
Member
Registered: 2012-11-21
Posts: 15

Re: Problem with drawing metafile

I don't know what you mean.

Offline

#4 2013-01-15 15:40:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: Problem with drawing metafile

The problem seems to be related to the drawing of the "free fields" in the form.

They are made with some "boxes", one per character.

How are they drawn?
Using a font?
Using a line?

Offline

#5 2013-01-15 16:04:38

cedo
Member
Registered: 2012-11-21
Posts: 15

Re: Problem with drawing metafile

I don't know how it is drawn. I got the metafile from ministry of treasures and I have to use it as background in my report.

Offline

#6 2013-01-15 16:09:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: Problem with drawing metafile

I tried to use a tool like EmfExplorer to guess what is wrong here.
http://frazmitic.free.fr/emfexplorer/

It was crashing when running it...
And EmfExplorer is known to be very efficient.

So I guess the emf content is just somewhat non standard and difficult to work with.

What about just rendering the page as bitmap in the target pdf, then draw your text over it?

Offline

#7 2013-01-16 08:02:27

cedo
Member
Registered: 2012-11-21
Posts: 15

Re: Problem with drawing metafile

In my opinion EmfExplorer works fine, but you have to switch off "GDI+" option:
https://docs.google.com/file/d/0B5Z5axE … 1XNkE/edit

As you can see there aren't any boxes in the attached screenshoot.

Offline

#8 2013-01-16 08:05:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: Problem with drawing metafile

For SynPDF, we use a similar technique than the one used with "GDI+" option, i.e. reading the metafile records, and rendering them.
If EMFExplorer is not able to render the metafile (this is the first time I see it), I guess this is of bad taste...

For you, the easiest is to render the page as bitmap (black/white) using default GDI command, then print the bitmap on the PDF canvas, and add your text.

Offline

Board footer

Powered by FluxBB