#1 2013-01-18 09:05:24

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

DevExpress Printing System to SynPDF

Hi All,

I have had the need to combine several jobs to produce a document pack from our application. This application takes data from both HTMLView and the DevExpress ExpressQuantumGrid Suite / DevExpress Printing system. I've been looking for a long time to find the best way to do this and I have now found it. Html2Pdf covers getting the data from HTML View. I hope to demonstrate one way of getting the data from the DevExpress printing system.

First the print code for DevExpress. The key here is to use the function EnumPagesAsImages. The first parameter is an array of integers indicating the pages you want to convert to an image. To keep things simple I do one page at a time. The second parameter determines the image type to use. As the SynPDF system works with well metafiles that is the graphic type I have used. The third determines if the background should be painted. The forth parameter is a call back function to receive the rendered image. Parameters 5, 6 & 7 are data pointers which I don't use.

var
   PageCount: Integer;
begin
  // Other printing preparation code goes here

  // Force the printout to regenerate
  Self.dxGridLink.RebuildReport;
  // Copy each page to the PDF document
  for PageCount := 0 To dxComponentPrinter1.GetPageCount - 1 do begin
    dxComponentPrinter1.EnumPagesAsImages([PageCount], TMetaFile, False, PDFPrinter.AppendDevExpressGrid, nil, nil, nil);
  end;

Now the PDF document class. This just simple code so far. I hope to improve it to scale the metafile so I can add my own borders and additional headers and footers.

type
  TDevExpress2SynPDF = class(TPdfDocumentGDI)
  private
  public
    constructor Create(AUseOutlines: Boolean=false; ACodePage: integer=0; APDFA1: boolean=false);
    destructor Destroy; override;
    procedure AppendDevExpressGrid(AComponentPrinter: TCustomdxComponentPrinter; AReportLink: TBasedxReportLink; 
                                   AIndex, APageIndex: Integer; const AGraphic: TGraphic; 
                                   AData: Pointer; var AContinue: Boolean);
  end;

implementation

uses SynGdiPlus;

procedure TDevExpress2SynPDF.AppendDevExpressGrid(
  AComponentPrinter: TCustomdxComponentPrinter; AReportLink: TBasedxReportLink;
  AIndex, APageIndex: Integer; const AGraphic: TGraphic; AData: Pointer;
  var AContinue: Boolean);
var
  Emf     : TMetafile;
  R       : TRect;
  PdfPage : TPdfpage;
begin
  if AGraphic is TMetaFile then begin
    Emf := AGraphic as TMetaFile;

    // Make this page landscape
    PdfPage := Self.AddPage;
    PdfPage.PageWidth := Self.DefaultPageHeight;
    PdfPage.PageHeight := Self.DefaultPageWidth;

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

constructor TDevExpress2SynPDF.Create(AUseOutlines: Boolean; ACodePage: integer;
  APDFA1: boolean);
begin
  inherited Create(AUseOutlines, ACodePage, APDFA1);

  Gdip := TGDIPlusFull.Create;
end;

destructor TDevExpress2SynPDF.Destroy;
begin
  FreeAndNil(Gdip);
  inherited;
end;

I use the Gdip.DrawAntiAliased as the normal metafile SynPDF functions produce either a black and white image with some backgrounds and lines missing or the PDF file is blank.

I hope this code helps somebody out but please post comments, suggestions or improvements to my code.

Take care,
Ryan

Offline

#2 2013-01-18 13:32:19

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

Re: DevExpress Printing System to SynPDF

Is it not possible to create a vectorial picture, instead of a bitmap one?

Having a bitmap inside a PDF makes the file bigger and less accurate.

Offline

Board footer

Powered by FluxBB