Converting base64 string to PDF in memory

Doug Easterbrook doug at artsman.com
Wed Mar 30 18:42:49 UTC 2022


for what is worth.

obrowser will display PDF’s .. just give the example a path name like      file:///Users/deasterb/Desktop/MyPdf.pdf <file:///Users/deasterb/Desktop/MyPdf.pdf>

however, I understand that you are trying to get a javascript module to display a PDF and that desktop is not involved.

that means one of things — 

you do everything client side
- decode the binary (which has to come from someplace) 
- throw it out into another page so that the users browser can take care of it and display it. (if omnis allows you do add a page)

or you do it server side by
- getting the server to decode the binary
- saving it to a temp file
- returning the URL to the temp file to the browser (as a separate window, I suppose —  target=“_Blank”)


or something that displays sends  javascript with with some raw HTML as part of it that invokes the PDF display.     if you can display a picture or movie in a section of pure HTML, then you should be able to show a PDF.  eg

<embed src="files/Brochure.pdf" type="application/pdf" width="100%" height="600px" />



or….  if you can return hyperlinks in javascript, then return a hyperlink to the temp file and tell the user ‘click here to see the PDF'



I don’t use the JS client.   but I have to beleive that the web page you send out with the JS client has <html><head></head><body> … </body></html> in it.


and if it does, you should be able to alter that so that there is an <embed …> at the bottom or the ability to have  link that will open on a new page.


or.  per the documentation .. it seems to clearly indicate you can get a PDF to display in the users web browser.
https://www.omnis.net/developers/resources/onlinedocs/WebDev/02jsremoteforms.html#linking-to-pdfs


http://127.0.0.1:5912/jsclient?__OmnisCmd=getpdf,C:\myreport.pdf <http://127.0.0.1:5912/jsclient?__OmnisCmd=getpdf,C:%5Cmyreport.pdf>

which if it works .. then
1) get the server to process the data to make th PDF
2) send the URL back to the user as above.

Doug Easterbrook
Arts Management Systems Ltd.
mailto:doug at artsman.com
http://www.artsman.com
Phone (403) 650-1978

> On March 30, 2022, at 7:52 AM, malkishtini at gmail.com wrote:
> 
> Thank you again, Michael, for sharing your case.
> It helps me to know that I'm moving in the right direction.
> In my case I'm not calling the JS form from an Omnis studio desktop app, so
> I can not make use of oBrowser, but maybe it is an option if I start calling
> the JS Client from the studio desktop.
> 
> Thank you,
> Mayada
> 
> -----Original Message-----
> From: omnisdev-en <omnisdev-en-bounces at lists.omnis-dev.com> On Behalf Of
> Michael Mantkowski
> Sent: Wednesday, March 30, 2022 10:45 AM
> To: 'OmnisDev List - English' <omnisdev-en at lists.omnis-dev.com>
> Subject: RE: Converting base64 string to PDF in memory
> 
> Right, I understand your issue.  I saw that you were have difficulty with
> the Brainy Data function and just wanted to be sure you knew about the Omnis
> equivalent.
> 
> We have had similar issues with what you are doing as well.  We have a
> Medical Record page in our application where we want to sometimes download
> Lab Results in PDF format and display them to the user.  Since Omnis does
> not have a direct way to show PDF files we always save it to disk first then
> use a conversion program to convert it to a JPEG for display in Omnis.  We
> use a graphics program called irfanview to do this and have a rather
> involved process for multipage PDFs.
> 
> I need to check to see if Studio 10.2 has a PDF display field and see if I
> can skip all that.  Or maybe the oBrowser will display PDFs?  I did try a
> PDF activex control once, but it made Omnis unstable and prone to crash.
> 
> Anyway, not part of your question...
> 
> *********************************************************************
> Michael Mantkowski
> ClienTrax Software
> 1-614-875-2245
> *********************************************************************
> 
> 
> -----Original Message-----
> From: omnisdev-en On Behalf Of malkishtini at gmail.com
> Sent: Wednesday, March 30, 2022 10:25 AM
> To: 'OmnisDev List - English' <omnisdev-en at lists.omnis-dev.com>
> Subject: RE: Converting base64 string to PDF in memory
> 
> Hi Michael,
> I have not started testing any conversion from Omnis yet, I'm just trying to
> collect details and set a spec to myself.
> I have OXML.$base64decode in mind to test in Omnis, but I think in this case
> I need to save the binary to a file (which we want to avoid) and then
> display it in the HTML field, unless there is another way to use lvData
> directly which I'm not aware of yet.
> I can test it and see what I get.
> 
> Thank you,
> Mayada
> -----Original Message-----
> From: omnisdev-en <omnisdev-en-bounces at lists.omnis-dev.com> On Behalf Of
> Michael Mantkowski
> Sent: Wednesday, March 30, 2022 10:04 AM
> To: 'OmnisDev List - English' <omnisdev-en at lists.omnis-dev.com>
> Subject: RE: Converting base64 string to PDF in memory
> 
> Hi Mayada,
> 
> I may have missed it in the replies, but did you try the Omnis function for
> base 64 decoding?
> 
> Do OXML.$base64decode(pvData) Returns lvData
> 
> *********************************************************************
> Michael Mantkowski
> ClienTrax Software
> 1-614-875-2245
> *********************************************************************
> 
> 
> -----Original Message-----
> From: omnisdev-en On Behalf Of malkishtini at gmail.com
> Sent: Wednesday, March 30, 2022 9:45 AM
> To: 'OmnisDev List - English' <omnisdev-en at lists.omnis-dev.com>
> Subject: RE: Converting base64 string to PDF in memory
> 
> Hi Phil,
> 
> I appreciate your follow up.
> I did a test yesterday from outside Omnis, just to see if the atob()
> function in JavaScript will work with me and it didn't. 
> For some reason, the conversion from base64 to pdf failed when I used the
> base64 string that was generated using the Brainy data pdf driver (while the
> same base64 can be converted with no issue when I user the online convertor
> tool).
> To be clear, the JavaScript function did work with me when using the sample
> base64 that I found on the web, but it failed with my base64.
> So, I still have a lot to research until I can decide on the path to go : ).
> 
> Thank you,
> Mayada
> 
> -----Original Message-----
> From: omnisdev-en <omnisdev-en-bounces at lists.omnis-dev.com> On Behalf Of
> Phil (OmnisList)
> Sent: Wednesday, March 30, 2022 9:04 AM
> To: omnisdev-en at lists.omnis-dev.com
> Subject: Re: Converting base64 string to PDF in memory
> 
> Hi Mayada,
> 
> So, if you managed to revert the base64 encoded file back into a binary pdf,
> do you then have a way to load that into the object?
> 
> Presuming so, which means all you need is a javascript function to decode
> base64 back to the raw pdf file.
> 
> Maybe atob() a javascript function is all you need?
> 
> regards
> Phil Potter
> Based in Chester in the UK.
> 
> On 30/03/2022 13:15, malkishtini at gmail.com wrote:
>> Hi Phil,
>> 
>> Thank you very much for your email and for the options you shared.
>> You got my requirements correctly.
>> Right now, I have a JS client with an HTML control that is currently 
>> displaying a pdf doc which I download as a file stream from S3. So no 
>> conversion was need with this solution.
>> The design should change now to support receiving an encoded 
>> base64string (instead of a file stream) and displaying the response as 
>> a PDF in the HTML control.
>> 
>> I'll investigate both options that you shared below to see if they can 
>> fulfill my need.
>> 
>> Thank you and best regards,
>> Mayada
>> 
>> -----Original Message-----
>> From: omnisdev-en<omnisdev-en-bounces at lists.omnis-dev.com>  On Behalf 
>> Of Phil (OmnisList)
>> Sent: Wednesday, March 30, 2022 6:18 AM 
>> To:omnisdev-en at lists.omnis-dev.com
>> Subject: Re: Converting base64 string to PDF in memory
>> 
>> Hi Mayada,
>> 
>> Following this link, I was trying to understand your requirements...
>> 
>> Do you have, what Omnis calls a HTML control, to display a PDF?
>> 
>> and your query is how to get a base 64 rest API reply into that HTML 
>> control?
>> 
>> If you had such a HTML control, then it would have some method call to 
>> set the contents, which if its under your control, you could make it 
>> accept
>> base64 data.
>> 
>> I'm thinking your meaning something like signature:
>> https://github.com/OmnisStudio/Omnis-Signature
>> 
>> Which I modified and added methods to for my needs...
>> 
>> indeed there is a PDF object there also, which maybe of help?
>> https://github.com/OmnisStudio/Omnis-JSPDFDevice
>> 
>> Or, are you talking about some other html control thing?
>> 
>> regards
>> Phil Potter
>> Based in Chester in the UK.
>> 
>> On 30/03/2022 03:23,malkishtini at gmail.com  wrote:
>>> Hi Scotte,
>>> 
>>> Thank you for sharing your idea.
>>> It is a good one to experiment when using oBrowser in a desktop app.
>>> 
>>> For now, I need to do the conversion in a JS client (that runs 
>>> directly in a
>>> browser) and render the pdf into an Html control.
>>> But I'll keep your approach in mind in case I can get it to work with 
>>> the Html control.
>>> 
>>> Thank you,
>>> Mayada
>>> 
>>> -----Original Message-----
>>> From: omnisdev-en<omnisdev-en-bounces at lists.omnis-dev.com>   On Behalf
>>> Of Scotte Meredith
>>> Sent: Tuesday, March 29, 2022 5:22 PM
>>> To: OmnisDev List - English<omnisdev-en at lists.omnis-dev.com>
>>> Subject: Re: Converting base64 string to PDF in memory
>>> 
>>> Hi, Miyada --
>>> 
>>> I've only played with this a little, but here is an area to explore.
>>> 
>>> You can force HTML directly into the oBrowser component using
> $setdataurl.
>>> 
>>> Create the html as a string or binary and for the images or PDF you 
>>> should be able to uuencode it as an in-line image or embedding as you 
>>> would for a webpage.
>>> 
>>> Here is an example with simple html, using both the character and 
>>> binary options.
>>> 
>>> On a window with an oBrowser component named xBrowser:
>>> 
>>> Calculate ibnURL as chartoutf8('<html><body><p>Something
>>> here</p></body></html>') Do
>>> $cinst.$objs.xBrowser.$setdataurl(ibnURL,'text/html')
>>> ## or
>>> Calculate icURL as '<html><body><p>Something here</p></body></html>'
>>> Do $cinst.$objs.xBrowser.$setdataurl(icURL,'text/html')
>>> 
>>> 
>>>> On Mar 29, 2022, at 10:52 AM,malkishtini at gmail.com   wrote:
>>>> 
>>>> Hi Andrew,
>>>> Thank you for your feedback.
>>>> I'm afraid that we might end up doing the same thing if we cannot 
>>>> find another solution in Omnis.
>>>> 
>>>> I was wondering if Brainy data has a plug in to help with this 
>>>> conversion, as we do use their driver to create the pdf in memory.
>>>> 
>>>> We found a way to do the conversion in Javascript, 
>>>> https://base64.guru/developers/javascript/examples/decode-pdf, but 
>>>> not sure yet how to make this work with the JS client and the html
>> object.
>>>> Need to do more digging.
>>>> 
>>>> Thank you & best regards,
>>>> Mayada
>>>> 
>>>> -----Original Message-----
>>>> From: omnisdev-en<omnisdev-en-bounces at lists.omnis-dev.com>   On Behalf
>>>> Of Andrew Stolarz
>>>> Sent: Tuesday, March 29, 2022 12:41 PM
>>>> To: OmnisDev List - English<omnisdev-en at lists.omnis-dev.com>
>>>> Subject: Re: Converting base64 string to PDF in memory
>>>> 
>>>> Mayada,
>>>> 
>>>> I was looking to do something similar a number of years ago. It's my 
>>>> understanding that with the JS client, you need to save the PDF to 
>>>> disk before being able to display it in a JS form.
>>>> 
>>>> We ended up placing the PDF's into a temp location and cleared them 
>>>> out after.
>>>> 
>>>> 
>>>> Andrew
>>>> 
>>>> 
>>>> On Tue, Mar 29, 2022 at 11:24 AM<malkishtini at gmail.com>   wrote:
>>>> 
>>>>> Hello $list,
>>>>> 
>>>>> I have a project to convert a base64 string (which I get from an 
>>>>> external REST API) to a PDF and display in a JS form without saving 
>>>>> any file to a disk (i.e., convert it to a PDF in memory and display 
>>>>> it in an HTML object in the JS form (Studio 8.1.7)).
>>>>> I have not done this before, so the first thing I thought about was 
>>>>> to post a question to the list to see if anyone has done something 
>>>>> similar before and could kindly share some ideas with me.
>>>>> 
>>>>> Thank you in advance for any hints/thoughts.
>>>>> 
>>>>> Best regards,
>>>>> Mayada
>>>>> 
>>>>> 
>>>>> 
>>>>> _____________________________________________________________
>>>>> Manage your list subscriptions athttps://lists.omnis-dev.com  Start 
>>>>> a new message ->mailto:omnisdev-en at lists.omnis-dev.com
>>>>> 
>>>> _____________________________________________________________
>>>> Manage your list subscriptions athttps://lists.omnis-dev.com  Start 
>>>> a new message ->mailto:omnisdev-en at lists.omnis-dev.com
>>>> 
>>>> _____________________________________________________________
>>>> Manage your list subscriptions athttps://lists.omnis-dev.com  Start 
>>>> a new message ->mailto:omnisdev-en at lists.omnis-dev.com
>>> 
>>> Scotte Meredith
>>> spomacguy at gmail.com
>>> 509/998-0991
>>> 
>>> 
>>> 
>>> 
>>> _____________________________________________________________
>>> Manage your list subscriptions athttps://lists.omnis-dev.com  Start a 
>>> new message ->mailto:omnisdev-en at lists.omnis-dev.com
>>> 
>>> _____________________________________________________________
>>> Manage your list subscriptions athttps://lists.omnis-dev.com Start a 
>>> new message ->mailto:omnisdev-en at lists.omnis-dev.com
>> _____________________________________________________________
>> Manage your list subscriptions athttps://lists.omnis-dev.com  Start a 
>> new message ->mailto:omnisdev-en at lists.omnis-dev.com
>> 
>> _____________________________________________________________
>> Manage your list subscriptions athttps://lists.omnis-dev.com Start a 
>> new message ->mailto:omnisdev-en at lists.omnis-dev.com
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com Start a new
> message -> mailto:omnisdev-en at lists.omnis-dev.com 
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com Start a new
> message -> mailto:omnisdev-en at lists.omnis-dev.com 
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com Start a new
> message -> mailto:omnisdev-en at lists.omnis-dev.com 
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com Start a new
> message -> mailto:omnisdev-en at lists.omnis-dev.com 
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com Start a new
> message -> mailto:omnisdev-en at lists.omnis-dev.com 
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 



More information about the omnisdev-en mailing list