Menu

#48 Problem with EMF

2.0
open
nobody
2023-04-03
2023-04-03
No

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?

1 Attachments

Discussion

  • zyx

    zyx - 2023-04-03

    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?

     
    • Giovani Erthal

      Giovani Erthal - 2023-04-03

      It was what I feared

      0º and 180º texts are not displayed.

       
  • zyx

    zyx - 2023-04-03

    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).

     
    • Giovani Erthal

      Giovani Erthal - 2023-04-03

       
      • zyx

        zyx - 2023-04-03

        It looks like an encoding problem to me.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.