1. Praveen Rajarao
  2. PowerBuilder
  3. Tuesday, 21 November 2017

I have a requirement to call an API to view an image or a pdf file. The API will return back a stream of bytes to my PB Application. 

Is there any tool or an ActiveX control I can use to render this stream of bytes as an image on the UI? 

Any help on this? 

Thanks

Praveen

Roland Smith Accepted Answer Pending Moderation
0
Votes
Undo

For the PDF, write it to a file and display it with the IE WebBrowser control. I have an example here:

http://www.topwizprogramming.com/freecode_webbrowser.html

For the image, I have a picture control that supports loading the image directly from a blob.

http://www.topwizprogramming.com/freecode_canvas.html

It supports bmp, gif, jpg, png, wmf, emf, and tif.

Comment
Thanks Roland. I will try what you and Marco have suggested and see what works best for me. Will update this thread on my findings. 

  1. Praveen Rajarao
  2. Tuesday, 21 November 2017
There are no comments made yet.
  1. Tuesday, 21 November 2017
  2. PowerBuilder
  3. # 1
Marco Meoni Accepted Answer Pending Moderation
0
Votes
Undo

Hello Praveen,

I would:

1) retrieve the byte stream and store it into a blob;
2) save the blob to a local file (image/pdf);
3) display the local file (use the PB Picture control if an image, or the MS Web Browser Ole control if a PDF)

In details:

1) convert byte stream to blob

    byte lbytes[]
    Blob lblb​
    // read the byte array from external API
    lBlobLen = UpperBound(lbytes) 
    lblb = Blob(Space(lBlobLen), EncodingAnsi!) 
    For lBytePos = 1 To lBlobLen 
        BlobEdit(lblb, lBytePos, lbytes[lBytePos], EncodingANSI!) 
    Next
    
2) save the blob to a file

    integer li_FileNum
    li_FileNum = FileOpen("myfile.jpg", StreamMode!, Write!, LockWrite!, Append!)  // same if PDF or other image formats
    FileWriteEx(li_FileNum, lblb)
    FileClose(li_FileNum)

3) display the file

    p_1.picturename = 'myfile.jpg'  // use Picture control
​  ----
    ole_1.object.navigate (sle_pdffile.text) // use MS Web Browser ActiveX

Cheers,
Marco

Comment
Thanks Marco - Let me try that out. I will update this thread. 

  1. Praveen Rajarao
  2. Tuesday, 21 November 2017
There are no comments made yet.
  1. Tuesday, 21 November 2017
  2. PowerBuilder
  3. # 2
Chris Pollach Accepted Answer Pending Moderation
0
Votes
Undo

Hi Praveen;

     For viewing images from a File directly in your PB App, have a look at the InkPicture control in PB to help you on this. If the Image were in a Blob column, have a look at the DataWindow's TableBlob feature.

     For PDF's, I would suggest using the HyperLinkToURL() method of the PB based iNET object to help you let the O/S's default Web Browser display this for you.

HTH

Regards ... Chris

Comment
Hi Chris - But I do not have the path to the image or the PDF file. I just have a stream of bytes to work with. 

  1. Praveen Rajarao
  2. Tuesday, 21 November 2017
Hi Praveen;



   The InkPicture will work great for your image as it can be loaded from the contents of a BLOB variable - hence your byte data stream. The PDF one is harder as PB does not have a native PDF viewer.



Regards ... Chris

  1. Chris Pollach
  2. Tuesday, 21 November 2017
There are no comments made yet.
  1. Tuesday, 21 November 2017
  2. PowerBuilder
  3. # 3
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.