#1 2012-11-21 13:42:04

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/open?id=0B5Z5ax … HRVQVVLcWM

The ouput file is blank. The question is: what am I doing wrong?

Offline

#2 2012-11-21 14:19:51

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

Re: Problem with drawing metafile

set the page size before adding a page.

Offline

#3 2012-11-21 14:41:21

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

Re: Problem with drawing metafile

Something is wrong. The output file is bad:
https://docs.google.com/open?id=0B5Z5ax … VBaa1ZCU1E

Offline

#4 2012-11-21 14:55:27

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

Re: Problem with drawing metafile

I tried by myself, using latest version of the SynPdf code, and it worked mostly as expected.

Some colors and characters are missing.

Offline

#5 2012-11-21 15:06:08

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

Re: Problem with drawing metafile

I used the last stable version (1.15). I try it again with the newer version from repository.

Offline

#6 2012-11-21 15:15:19

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

Re: Problem with drawing metafile

Now I used the last version from repository (1.18). Actually the printout looks much better.

Offline

#7 2012-11-22 13:03:18

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

Re: Problem with drawing metafile

I have one more question. Which approach is better?

1)
  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);

2)

  PdfPage.PageWidth := (72 * Emf.MMWidth) div 2540;
  PdfPage.PageHeight := (72 * Emf.MMHeight) div 2540;
  PdfDoc.VCLCanvas.StretchDraw(Rect(0, 0, (Screen.PixelsPerInch * Emf.MMWidth) div 2540, (Screen.PixelsPerInch * Emf.MMHeight) div 2540), Emf);

It seems that the second. What is your opinion ?

Offline

#8 2012-11-22 15:42:55

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

Re: Problem with drawing metafile

Both solutions sound OK to me.

Only difference is that using integer arithmetic here will make a Trunc() instead of a Round(), I suspect.

So 1st one could make sense to be used.
Unless you use one of the standard page sizes (like Letter, A4, A3....) instead of such custom sizes, depending on the metafile.

Offline

Board footer

Powered by FluxBB