Hi
I have a WP tools document (v7.33.1) with pictures (embedded or through Insertpoints). These pictures are transparent (PNG). In the WPTools editor, this seems fine (I have a background image that sees through the image). But when I export my document to PDF using wPDF the images are not transparent anymore and get a white background covering my background, creating ugly white blocks.
Because I need further processing of the canvas after each page is drawn, I cannot use the TWPPdfExport component. So I use this code to draw the pages on the wPDF canvas:
Code
bodyText.Refresh;
C := BodyText.PageCount;
if C > 0 then
begin
result := true;
PDFCreator.StartDocument; // Create a default page on the engine canvas
try
for I := 0 to C-1 do
begin
// Render contents of current page of rich-edit control
// on the PDF engine canvas
BodyText.PaintPageOnCanvas(
i, // page number
0, // left margin (x-offset) on the canvas
0, // top margin (y-offset) on the canvase
0, // rectangle width on the canvas (0 for full width)
0, // rectangle height on the canvas (0 for full height)
PDFCreator.Canvas, // canvas of the PDF engine
[wppInPaintForwPDF, wppNoPageBackground, wppWhiteIsTransparent],
0, // horizontal resolution of canvas (0 for autodetection)
0, // vertical resolution of canvas (0 for autodetection)
-1, // top clipping (-1 for no clipping)
-1, // height of the rectangle (-1 for no clipping)
[wpUseProvidedWidthHeight, wpUseWorldScaling]);
// Create next page if required
if I < C -1 then begin
PDFCreator.NewPage;
end;
end;
finally
PDFCreator.EndDocument;
end;
end;
Alles anzeigen
The PDFCreator is a wrapper around the wPDF component. The code inside the PDFCreator component looks like this:
Code
type
TENKwPDFCreator = class(TInterfacedObject, IENKPDFCreator)
private
FPDFEngine: TWPPDFPrinter;
..
function GetCanvas: TCanvas;
procedure Startpage;
protected
public
procedure CreatePDFDocument(afilename: string; aDPI: integer);
procedure StartDocument;
procedure NewPage;
procedure EndDocument;
end;
Implementation
function TENKwPDFCreator.GetCanvas: TCanvas;
begin
result := FPDFEngine.Canvas;
end;
procedure TENKwPDFCreator.CreatePDFDocument(afilename: string; aDPI: integer);
begin
FFilename := aFilename;
FPDFEngine.Free; //Clean up possible old engine
FPDFEngine := TWPPDFPrinter.Create(nil);
WPDF_Start($$$$$$,$$$$$$$);
FPDFEngine.AutoLaunch := false;
FPDFEngine.FileName := afilename;
FPDFEngine.ConvertJPEGData := false; //or True makes no difference!!!!
FPDFEngine.Modes := [wpClipRectSupport, wpArabicAlwaysAsOutline, wpConvertColorsToCMYK, wpAllowTransparentBit];
FDPI := aDPI;
FPagenr := 0;
end;
procedure TENKwPDFCreator.Startpage;
begin
FPageWidth := round( 8.27 * FDPI); //for now Fixed A4 size
Fpageheight := round(11.69 * FDPI); //for now Fixed A4 size
FPDFEngine.StartPage(FPageWidth, FPageHeight , FDPI, FDPI, 0);
end;
procedure TENKwPDFCreator.StartDocument;
begin
FPagenr := 1;
FPDFEngine.BeginDoc;
StartPage;
end;
procedure TENKwPDFCreator.NewPage;
begin
Inc(FPagenr);
FPDFEngine.EndPage;
Startpage;
//My extra processing of the page
end;
procedure TENKwPDFCreator.EndDocument;
begin
FPDFEngine.EndPage;
FPDFEngine.EndDoc;
FreeAndNil(FPDFEngine);
end;
Alles anzeigen