Adding Images to PDFs

Using the TMS WEB Core variant of FNC Core's PDF-generation tools, I'm running into some issues when adding images to the PDF. I've managed to get a bitmap (originally a DataURI - a Base64-encoded PNG file) into the PDF using something like this.

    b := TTMSFNCUtils.CreateBitmapFromBase64(CurrentLabel);
    p.graphics.DrawImage(b, gcWhite, RectF(50,350,550,600), true, true, itOriginal, 1.0, true);

However, I end up with a small image rendered on the page (the image is actually quite high resolution) and it has a lot of "whitespace" around it, but sadly it isn't white....

  • I've had the most success using the Graphics.DrawImage variant with a RectF as a parameter. Which is the best variant to use?
  • The second parameter (gcWhite above) was suppose to be the backgound of the image, but it is always just all black, no matter what value I use. Just drawing rectangles, the colors all seem to work fine otherwise.
  • After the Rect, the parameters I think are for "stretch" and "aspect ratio", and I'd really like to use those, but they don't seem to work?
  • Looking through the source code, I got the impression that the WEB Core version of FNC Core doesn't seem to support SVG as well as it might - passing an SVG didn't work at all. Is that just a work-in-progress, or are there other issues here?

When creating the bitmap, it consistently fails the first time, and then works the second time. The error I get is the following.

Uncaught (in promise) DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.

It's almost as if there's some kind of async initialization happening, but I don't know where to look for that. As it works the second time, I'm reasonably certain that the data was correct all along, so is there perhaps another reason why atob might be failing?

Hi,

I detected an issue related to the background color. the default color was black and wasn't respecting the color provided by the drawing routine, this has now been fixed. (TMS FNC Core update will address this). SVG is supported out of the box in TMS WEB Core, so we didn't port the SVG parsing engine to TMS WEB Core and therefore it's not possible to draw SVGs in a PDF on TMS WEB Core. We might consider porting the parsing engine just for the purpose of embedding SVGs in PDF

Sounds good. Did you notice anything amiss with the stretch option? I only noticed the background issue because my PNG image was drawn (centered) with a giant black border around it for no readily apparent reason.

As far as SVG, more support would be better. I'd struggle to recall an instance where I used an SVG in a Delphi VCL app, like, ever, but currently, my use of SVG is about 10:1 over all other image formats combined when working with TMS WEB Core projects. And given my fondness for using D3.js (charts), its only a matter of time before I'll be wanting to embed them directly into PDFs.

No, didn't notice any issues with stretching here. I'll build a new version so you can retry and see if the white background comes through.