PxPlus User Forum
Main Board => Discussions => Programming => Topic started by: David Reynolds on June 04, 2019, 02:30:39 PM
-
I am calling an external API and one of the returned JSON values is a customer signature encoded as
image/png;base64,iVBORw0KGg.......
How do I take that string and create an actual fileName.png (or gif, jpg, bmp, etc)?
Thanks,
David
-
Take the data following the comma after 'base64' and pass it through the CVS function. This will get you file contents which you can write to a png file.
Something like this should work for you:
(Assumes the "image/png;base64,iv..." is in the variable input$)
pngData$=CVS( input$(pos(","=input$)+1), "Base64:ASCII")
open purge (hfn,isz=-1) "somename.png"
write record (lfo) pngData$
close (lfo)
-
Worked like a charm.
Thanks Mike!
-
Next thing I need is to print the PNG to a PDF.
We're on PxPlus 2016 on CentOS so my understanding is that there is no direct support for 'PICTURE' with a PNG to PDF (and my tests confirm this).
I tried using the ImageMagick 'convert' utility to change my PNG to JPG but that still doesn't render in the PDF.
Do I have to pass some special options to 'convert' to get a specific type of JPG that's compatible with printing to PDF from Linux?
Thanks again,
David
-
David,
Make sure the 'HP' parameter is set to 1 in order to use the more advanced HARU PDF libraries.
PxPlus 2019 does support PNG output to PDF files so the simple solution would be to upgrade. Assuming you are on the maintenance plan (CCP not LAP) you should be able to do this upgrade at no charge.
-
Nailed it again.
Thanks!