1. Praveen Rajarao
  2. PowerBuilder
  3. Tuesday, 21 November 2017 15:54 PM UTC

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

Bruce Armstrong Accepted Answer Pending Moderation
  1. Tuesday, 31 October 2023 03:36 AM UTC
  2. PowerBuilder
  3. # 1

Save it as a temp file and then load it into a WebBrowser control.

Comment
There are no comments made yet.
Mike Vieane Accepted Answer Pending Moderation
  1. Tuesday, 31 October 2023 02:35 AM UTC
  2. PowerBuilder
  3. # 2

Hi Roland,

Experimenting with the free code in canvas.zip. I'm trying to do a silent print to a PDF filename with 'MicroSoft print to PDF' from the 'Print' button in the example. Using lpszOutput member of DOCINFO to specify filename; however, it is defined as a uLong in the example although internet document states this should be of type string.  Is there a way to do a silent print to filename using the StartDoc WinApi that uses the DOCINFO structure.? Or maybe some other way?

Thanks,

Mike

Comment
  1. Mike Vieane
  2. Tuesday, 31 October 2023 20:33 PM UTC
My requirement is not to view like in this thread unless I misunderstood the reply. No view. I need to load in a TIFF, JPG, BMP, etc. and silent print it to a PDF file. Example prompts print dialog which I'm trying to eliminate.



Thanks,

--Mike
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 21 November 2017 19:10 PM UTC
  2. PowerBuilder
  3. # 3

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
  1. Praveen Rajarao
  2. Tuesday, 21 November 2017 19:48 PM UTC
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. Helpful
There are no comments made yet.
Marco Meoni Accepted Answer Pending Moderation
  1. Tuesday, 21 November 2017 18:56 PM UTC
  2. PowerBuilder
  3. # 4

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
  1. Praveen Rajarao
  2. Tuesday, 21 November 2017 19:47 PM UTC
Thanks Marco - Let me try that out. I will update this thread. 

  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 21 November 2017 16:06 PM UTC
  2. PowerBuilder
  3. # 5

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
  1. Praveen Rajarao
  2. Tuesday, 21 November 2017 16:27 PM UTC
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. Helpful
  1. Chris Pollach @Appeon
  2. Tuesday, 21 November 2017 21:28 PM UTC
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. Helpful
There are no comments made yet.
  • Page :
  • 1


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