You are not logged in.
Pages: 1
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
Something is wrong. The output file is bad:
https://docs.google.com/open?id=0B5Z5ax … VBaa1ZCU1E
Offline
I used the last stable version (1.15). I try it again with the newer version from repository.
Offline
Now I used the last version from repository (1.18). Actually the printout looks much better.
Offline
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
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
Pages: 1