Tips

Top  Previous  Next

Our PDF Engine takes several efforts to produce the best looking PDF files you can get from your graphic output/files. For example text output is optimized to meet the width calculated by windows but also uses the character positioni9ng calculated by PDF. This results in a much better presentation. Internally rounding errors are avoided to avoid problems with difficult drawing objects, such as bar codes.

 

Some tips will help you to optimize the graphic output even more:

 

A) If you need output such as

 

clip0002

 

Please position each character using a separate text output command. Do not use TextOutEx command. You could also activate the ExactCharacterPosition mode in the property 'Modes' but that results is a lower quality of the other printed text.

 

B) When you export JPEG graphics you can do so by using the function DrawJPEG. This will export the JPEG data as it is without any decompression and compression and so is absolutely lossless.

 

C) Better Text Output - in the 'Modes' you can switch on the flag 'wpDontAdjustTextSpacing'. This will switch off the adaptation of the PDF output text to the length calculated by windows. If you don't use right aligned or justified text and don't print several text blocks in one line the output will look even better then. The reason is that the PDF reader controls the spacing to use the best quality for a certain font.

 

D) Our PDF engine now supports clipping regions. But you will get a better performance if you avoid regions and create clipping paths instead. Clipping paths are very easy to use. The following example produce a random polygon and then fills it. The output will look like:

 

clip0003

var

 res,i : Integer;

 pt : array[0..100] of TPoint;

begin

 WPPDFPrinter1.Filename := 'c:\test.pdf';

 res := Screen.PixelsPerInch;

 wpPDFPrinter1.BeginDoc;

 wpPDFPrinter1.StartPage(Round((21.0 / 2.54) * res),

     Round((29.7 / 2.54) * res), res, res, 0);

 

 // Create the points for a polygon

for i:=0 to 99 do

begin

   pt[i].x := res + Random(res*4);

   pt[i].y := res + Random(res*4);

end;

 pt[100] := pt[0];

 

 // Paint the path

 SaveDC(wpPDFPrinter1.Canvas.Handle);

BeginPath(wpPDFPrinter1.Canvas.Handle);

 wpPDFPrinter1.Canvas.Polygon(pt);

EndPath(wpPDFPrinter1.Canvas.Handle);

 

// and select it as clipping path

 SelectClipPath(wpPDFPrinter1.Canvas.Handle,RGN_AND);

 

// Draw the "background"

 for i:=0 to Res do

begin

    if wpPDFPrinter1.Canvas.Brush.Color = clRed then

          wpPDFPrinter1.Canvas.Brush.Color := clBlue

    else wpPDFPrinter1.Canvas.Brush.Color := clRed;

    wpPDFPrinter1.Canvas.FillRect(Rect(Res,Res+i*4,Res*5,Res+(i+1)*4));

end;

 RestoreDC(wpPDFPrinter1.Canvas.Handle,-1);

 

 wpPDFPrinter1.EndPage;

 wpPDFPrinter1.EndDoc;

 

 

E) In seldom cases it is better to create a bitmap and export it to PDF. You can use this code as a template for a powerful solution which adapts itself to the size of a metafile.

 

procedure wPDFExportAsBitmap( Metafile : TMetafile; PDFPrinter : TWPCustomPDFExport; StartPage : Boolean );

var

   bit : TBitmap;

   w,h : Integer;

   multa, multb : Extended;

const

   resolution = 96;

begin

 bit := TBitmap.Create;

try

   w := Round(Metafile.MMWidth/2540*resolution);

   h := Round(Metafile.MMHeight/2540*resolution);

   multa := w/1000; // maximum Size

   multb := h/1000;

  if multa>multb then multb := multa;

 

   bit.Width := Round(w/multb);

   bit.Height:= Round(h/multb);

  if StartPage then

      PDFPrinter.StartPage(Round(Metafile.MMWidth/2540*72),

 Round(Metafile.MMWidth/2540*72),72,72,0);

  try

    bit.Canvas.StretchDraw(Rect(0,0,bit.Width,bit.Height),Metafile);

     PDFPrinter.DrawBitmap(0,0,

 Round(Metafile.MMWidth/2540*PDFPrinter.XPixelsPerInch),

 Round(Metafile.MMWidth/2540*PDFPrinter.YPixelsPerInch),

 bit.Handle);

  finally

    if StartPage then  PDFPrinter.EndPage;

  end;

finally

   bit.Free;

end;

end;

 

procedure TForm1.ExportAsBitmapClick(Sender: TObject);

begin

 WPPDFPrinter1.Filename := 'c:\test.pdf';

 wpPDFPrinter1.BeginDoc;

wPDFExportAsBitmap( Image1.Picture.Metafile, wpPDFPrinter1, true );

 wpPDFPrinter1.EndDoc;

end;