Problem with EMF
a library to create/modify PDF documents using HDC/TCanvas
Brought to you by:
mc-zyx
I have the following EMF file:
But the PDF output is different:
Code used to generate the PDF:
var
lpdf : TLitePDF;
canvas : TCanvas;
hdc : THandle;
begin
// create a TLitePDF instance
lpdf := TLitePDF.Create;
try
try
// create a new PDF document
lpdf.CreateMemDocument;
// create a canvas to draw to
canvas := TCanvas.Create;
if canvas = nil then
raise Exception.Create ( 'Low memory!' ) ;
try
// add a page, with large-enough pixel scale
hdc := lpdf.AddPage ( Trunc ( lpdf.MMToUnit ( 210 ) ) ,
Trunc ( lpdf.MMToUnit ( 297 ) ) ,
795 , 1124 , LongWord ( LitePDFDrawFlag_ResetGraphicsState ) ) ;
// initialize the canvas
canvas.Handle := hdc;
AMF := TMetafile.Create;
try
AMF.LoadFromFile ( 'teste.emf' );
canvas.Draw ( 0 , 0 , AMF ) ;
finally
AMF.Free;
end;
finally
canvas.Destroy;
end;
if hdc <> THandle ( 0 ) then
begin
// finish drawing
lpdf.FinishPage ( hdc ) ;
// save the document
lpdf.SaveToFile ( 'output.pdf' ) ;
end;
// close the document
lpdf.Close ( ) ;
except
// do something on TLitePDFException exception
on ex : TLitePDFException do raise;
end;
finally
// destroy the TLitePDF instance
lpdf.Destroy;
end;
end;
Is it possible to solve this or is it a limitation of litePDF?
Hi,
I'm afraid it's a limitation of the litePDF. I thought I mentioned it in the "Known issues" section at https://litepdf.sourceforge.io/download.html , but I see it's not there. The EMF uses world transformation matrices, which the litePDF doesn't work well with. They confuse the litePDF as much as it provides incorrect data. I do not see the horizontal texts in your screenshot (0° and 180°), are they also horizontally flipped in the output, as the vertical texts?
It was what I feared
0º and 180º texts are not displayed.
Oh, I see, I thought they are out of the screen.
Drawing directly to the HDC returned by the litePDF, not using the EMF, would work better (unless the world transformations are used).
It looks like an encoding problem to me.