Jump to content

Bas van der Linden

Members
  • Content Count

    1
  • Joined

  • Last visited

Everything posted by Bas van der Linden

  1. Bas van der Linden

    Get pdf from form/controls using skia

    I'm trying to generate a pdf from a form/controls with Skia. I'm able to do something like this procedure TForm1.SaveControlAsPDF(AControl: TControl; const AFileName: string); var LBitmap: TBitmap; LDocumentStream: TFileStream; LDocument: ISkDocument; LCanvas: ISkCanvas; LSize: TSizeF; LImage: ISkImage; begin LBitmap := AControl.MakeScreenshot; try LSize := TSizeF.Create(LBitmap.Width, LBitmap.Height); LDocumentStream := TFileStream.Create(AFileName, fmCreate); try LDocument := TSkDocument.MakePDF(LDocumentStream); try LCanvas := LDocument.BeginPage(LSize.Width, LSize.Height); try LImage := LBitmap.ToSkImage; if Assigned(LImage) then LCanvas.DrawImage(LImage, 0, 0); finally LDocument.EndPage; end; finally LDocument.Close; end; finally LDocumentStream.Free; end; finally LBitmap.Free; end; end; But since we use DrawImage text and other stuff won't be properly selectable. What I'd like to be able to do is take the LCanvas and do something like this: AControl.PaintTo(LCanvas, AControl.LocalRect); So it paints the control to the canvas and after LDocument.EndPage we have pdf with properly painted control, but this doesn't work because it expects TCanvas so you get: Incompatible Types: 'TCanvas' and 'ISkCanvas'. Found solution, will update later
×