#1 2013-01-17 16:25:12

RyanC
Member
From: Kettering, United Kingdom
Registered: 2013-01-17
Posts: 7

Metafile comes out black and white or blank.

Hi All,

I've come across this library and it is doing everything I'm asking of it so far. I've hit a small snag though. This metafile http://www.lmp.co.uk/files/schedule.emf is causing me some headaches. I create a small test program for this metafile and I'm confused with the output.

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

  PdfDoc := TPdfDocumentGDI.Create;
  PdfDoc.CompressionMethod := cmFlateDecode;
  PdfDoc.DefaultPaperSize := psA4;
  PdfDoc.DefaultPageLandscape := True;
  PdfPage := PdfDoc.AddPage();
  //PdfDoc.VCLCanvas.Draw(0, 0, Emf);         // This gives black and white output only
  //PdfDoc.Canvas.RenderMetaFile(Emf, 1);    // This gives a blank PDF

  PdfDoc.SaveToFile(OutputFileName);
  PdfDoc.Free();

  FreeAndNil(Emf);
end.

When run with PdfDoc.VCLCanvas.Draw uncommented I get a black and white output. Some lines are also missing. When PdfDoc.Canvas.RenderMetaFile is uncommented I get a blank PDF. Am I missing something obvious?

Looking though the forum somebody recommended looking at EMFExplorer to see if the meta file had some odd coding in it. I've done this and as long as I switch off GDI+ rendering then is shows OK. Look through the EMF data it appears all calls are supported in the PDF engine except EMR_SETROP2. I'm just trying to work out what this does and implement it if necessary .... although this isn't my area of expertise and might take some time smile

Many thanks for any help.
Ryan

Offline

#2 2013-01-17 16:32:47

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

Re: Metafile comes out black and white or blank.

I'm not able to load your metafile.

Is the link broken, or did I do something wrong?

Offline

#3 2013-01-17 16:44:42

RyanC
Member
From: Kettering, United Kingdom
Registered: 2013-01-17
Posts: 7

Re: Metafile comes out black and white or blank.

Apologies for that it looks like our server won't accept EMF files. I've zipped it up and it can be downloaded from:

http://www.lmp.co.uk/files/sample.zip

Offline

#4 2013-01-18 08:40:24

RyanC
Member
From: Kettering, United Kingdom
Registered: 2013-01-17
Posts: 7

Re: Metafile comes out black and white or blank.

Hi All,

Just following up on my post from yesterday. I've been able to render the metafile to PDF using the following code:

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

  Gdip := TGDIPlusFull.Create;

  PdfDoc := TPdfDocumentGDI.Create;
  PdfDoc.CompressionMethod := cmFlateDecode;
  PdfDoc.DefaultPaperSize := psA4;
  PdfDoc.DefaultPageLandscape := True;
  PdfPage := PdfDoc.AddPage();

  R.Left := 0;
  R.Top := 0;
  R.Bottom := Emf.Height;
  R.Width := Emf.Width;
  Gdip.DrawAntiAliased(Emf, PdfDoc.VCLCanvas.Handle, R, smAntiAlias, trhClearTypeGridFit);

  PdfDoc.SaveToFile(OutputFileName);
  PdfDoc.Free();

  FreeAndNil(Emf);
end.

This produces a complete colour copy of the PDF document. The metafile has come from the DevExpress printing system. I'll post some code in another thread showing how to get the output from this into your PDF document.

Take care,
Ryan

Offline

Board footer

Powered by FluxBB