WPCubed Product Support

Watermark position

Thanks for the reply Julian. Very quick as always.

I couldn't use the paint page and page watermark together approach because I am generating the PDF from a WPRichText. Perhaps I should have stated that.

The solution was that the resulution (LRes var) has to be set to
Source.Memo.RTFData.RTFProps.FFontXPixelsPerInch & FFontYPixelsPerInch, I assume because this is what is used WPRichText uses when it outputs to the PDF.

Arcobat reader did not like my original JPEG when drawn with DrawTGraphic, so I created a new JPEG which works fine.

Interestingly Canvas.StretchDraw does work, but there is no need now I can use DrawTGraphic.

#3 ♥ 0
6.6k Views 2 users read 3 min
support

Hi,

for watermarks dont use StretchDraw - you cannot reuse the image this way.

See watermark demo:

var
  i, w, h, image_id: Integer;
  conversion_factor : Real;
const
  colors: array[1..3] of TColor = (clRed, clLime, clYellow);
  // Utility function to use the wPDF JPEG export function directly
  function DrawJPEG(xx, yy, ww, hh: Integer; jpeg: TJPEGImage): Integer;
  var
    temp: TMemoryStream;
  begin
    temp := TMemoryStream.Create;
    Result := -1;
    try
      jpeg.SaveToStream(temp);
      Result := WPPDFPrinter1.DrawJPEG(xx, yy, ww, hh,
        jpeg.Width, jpeg.Height,
        temp.Memory, temp.Size);
    finally
      temp.Free;
    end;
  end;
begin
  // WPDF_START(LICNAME, LICKEY);
  image_id := -1;
  WPPDFPrinter1.BeginDoc;
  try
    for i := 1 to 3 do
    begin
      w := Image1.Picture.Graphic.Width;
      h := Image1.Picture.Graphic.Height;
      WPPDFPrinter1.StartPage(w, h, 72, 72, 0);
      conversion_factor := Screen.PixelsPerInch / 72; // ScreenCanvas : PDF Canvas !
      // We draw our image, but only one time and clone the other
      if image_id < 0 then
      begin
        if Image1.Picture.Graphic is TJPEGImage then
              image_id := DrawJPEG(0, 0, w, h, TJPEGImage(Image1.Picture.Graphic))
        else  image_id := WPPDFPrinter1.DrawBitmap(0, 0, w, h, Image1.Picture.Bitmap.Handle);
      end
      else
        WPPDFPrinter1.DrawBitmapClone(0, 0, w, h, image_id);
      // Now the "watermark"
      WPPDFPrinter1.Canvas.Pen.Color := colors[i];
      WPPDFPrinter1.Canvas.Pen.Width := 3;
      WPPDFPrinter1.Canvas.Ellipse(Round(360*conversion_factor), Round(170*conversion_factor),
          Round(410*conversion_factor), Round(220*conversion_factor));

      WPPDFPrinter1.EndPage;
    end;
  finally
    WPPDFPrinter1.EndDoc;
  end;
#2 ♥ 0

Julian I am trying to paint a watermark behind the print of a PDF. The watermark is a JPEG loaded into a TPicture. See comments in the code for the problem. Can you help me, please.

I am using the following code:

var
  Watermark: TPicture;
 
procedure TMyObject.WPPDFExportBeforePrintPage(Sender: TObject; Number,
  FromPos, Length: Integer);
{Print watermark on WPPDFExport.Canvas}
begin
  TWPPDFExport(Sender).UseWatermark('water');
end;

procedure TMyObject.WPPDFExportBeginDoc(Sender: TObject);
var
  LRes: integer;
  LRect: TRect;
begin
    with (TWPPDFExport(Sender)) do
    begin
      LRes := Screen.PixelsPerInch;

      LRect.Left := 0;
      LRect.Top := 0;
      LRect.Right := MulDiv(Source.Header.PageWidth, LRes, 1440);
      LRect.Bottom := MulDiv(Source.Header.PageHeight, LRes, 1440);

      StartWatermark('water', LRect.Right, LRect.Bottom, LRes, LRes);
      try
        {If I use this version no watermark shows}
        //DrawTGraphic(0,0,0,0, Merge.Watermark.Graphic);

        {If I use this version the watermark paints in the bottom left of 
        each page, about 3 cm square on an A4 sheet.  It should fill
        the page.}
        Canvas.StretchDraw(LRect, Watermark.Graphic);
      finally
        EndWatermark;
      end;
    end;
end;

[/code]

#1 ♥ 0