What is the suggested Graphic class I should use with TMS WEB Core for an Electron app? Is the TGraphic.LoadFromFile() also asynchronous? If so, what is a possible pattern to wait for finish loading?
Var
PDFLib : TTMSFNCPDFLib;
g : TGraphic;
rect : TRectF:
begin
PDFLib:= TTMSFNCPDFLib.Create();
PDFLib.BeginDocument();
g:= TGraphic.Create;
g.OnChange:= OnGraphicChange;
g.LoadFromFile('Image.png');
rect.Left:= 40;
rect.Top:= 100;
rect.Right:= 40 + g.Width;
rect.Bottom:= 100 + g.Height;
PDFLib.Graphics.DrawImage(g , rect);
PDFLib.EndDocument().SaveToFile(FileName);
end;
When setting a breakpoint after the LoadFromFile() and inspect the TGraphic object, it seems the image data is not loaded
Assuming the LoadFromFile() method is working asychronous, I assigned an event handler to the TGraphic.OnChange event. The event handler is never called.
My next thought was, that the TGraphic.LoadFromFile() is not working because of restrictions for a Electron app to access local data. So I used a TElectronBinaryDataStream
There seems to be some image data loaded into the TGraphic object, but nothing what I could paint on the PDF canvas. Also the TGraphic.OnChange event is not called when assigning the image data from the stream to the TGraphic object.
Yes, you should use TElectronBinaryDataStream to access local files. Try TGraphic.LoadFromResource instead of TGraphic.LoadFromURL. Implement the TGraphic.OnChange event, and in that implementation you can create your PDF. You can access the needed TGraphic object with Sender as TGraphic.
When the object g is no longer existing, the event handler never will be called .....
Ok, this part is working, but to save back the image by a TElectronBinaryDataStream creates an empty file, you noticed the issue with the TGraphic.GetBase64Image already.