cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

view pdf in pdf viewer control using base64

Hello!

I have 3 screens.

 

1st screen is the login screen where customer can login with dynamics quote id and email.

2nd screen is the quote detail screen with details about the quote as well as the 'File Name' of the attached pdf to the respective quote which is store in Notes on the timeline of the quote in dynamics.

3rd screen has the pdf viewer control.

 

In the document property of the pdf control I have used : Text("data:application/pdf; base64, base64text...…..")

when I copy-paste the base64 string the pdf is displayed...

But I will not be able to do this because I need to view different pdf's.

 

How do I get the base64 string to that spot?

 

Please help!

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

Hi @praneepradee ,

The code below gets a PDF file selected in a gallery (from a SharePoint Library) and displays in in the PDF viewer. As far as I am aware, this is the only way of selecting a file and viewing it.
Firstly at App OnStart, set a Variable to the base address of your site and folder path.

Set(
   stSite,
   "https://xxxxxx.sharepoint.com/sites/xxxxxx"
);
Set(
   stFolder,
   "xxxxxxx/"   //your folder path
)

Make a Flow (mine is PDFView) that does this PDFFlow.png

 

 

 

 

 

 

 

 

 

 

 

 

 

Then this code is launched from the gallery item

Set(
   stPDFName,
   ThisItem.DocName   //my field name
);
Set(
   ViewPDF,
   PDFView.Run(
      stSite,
      Concatenate(
         "/",
         stFolder,
         First(
            Split(
                stPDFName,
                "."
            )
         ).Result,
         ".pdf"
      )
   )
)

Finally the Document in your PDF viewer will be

ViewPDF.pdf

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

View solution in original post

7 REPLIES 7
Super User III
Super User III

Hi @praneepradee ,

The code below gets a PDF file selected in a gallery (from a SharePoint Library) and displays in in the PDF viewer. As far as I am aware, this is the only way of selecting a file and viewing it.
Firstly at App OnStart, set a Variable to the base address of your site and folder path.

Set(
   stSite,
   "https://xxxxxx.sharepoint.com/sites/xxxxxx"
);
Set(
   stFolder,
   "xxxxxxx/"   //your folder path
)

Make a Flow (mine is PDFView) that does this PDFFlow.png

 

 

 

 

 

 

 

 

 

 

 

 

 

Then this code is launched from the gallery item

Set(
   stPDFName,
   ThisItem.DocName   //my field name
);
Set(
   ViewPDF,
   PDFView.Run(
      stSite,
      Concatenate(
         "/",
         stFolder,
         First(
            Split(
                stPDFName,
                "."
            )
         ).Result,
         ".pdf"
      )
   )
)

Finally the Document in your PDF viewer will be

ViewPDF.pdf

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

View solution in original post

Thank you for the answer sir.

 

But when i'm able to display the pdf by pasting Base64 string. 

There might be a possible way to get the base 64 string in:

 

Text("data:application/pdf;base64, base64")

 

Sir, I was able to view the pdf.

 

This is the formula I've used:

 

Concatenate("data:application/pdf;base64,",Lookup(Notes, Regarding in LookUp(Quotes,'Quote ID'= quoteinput.Text).quoteid).Document)

Thanks @praneepradee ,

I did understand your question - the Flow actually does this by getting the File Content and returning it to PowerApps.

I can tell you that this method works well on PDF files in a SharePoint Library - you just have to send it the URL.

I am glad you got it working - I will make a note of this as I have not seen this before

Concatenate(
   "data:application/pdf;base64,",
   Lookup(
      Notes, 
      Regarding in LookUp(
         Quotes,
         'Quote ID'= quoteinput.Text
      ).quoteid
   ).Document
)

Where do you have this stored?

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

@WarrenBelz 

 

This application brings in a relationship between Dynamics 365 and PowerApps only. So I can't take help from SharePoint.

Quotes and Notes are stored in Dynamics.

I haven't used any flow as of such.

 

The 'Document' has base64 text 

Hello,

 

I tried to paste the base64 string as following :

 

"data&colon;application/pdf;base64," & <b64string>

 

But PowerApps says "Make sure that the pdf file is coming from an https link".......

 

How did you do ?

 

I also used flow but that's slow and it's not really a best practice, it can't work offline so...

 

Thanks in advance !! 😉

Hi @Romsteck ,

I was actually surprised that worked. The "prefix" of data&colon;application/pdf;base64," & <b64string> simply adds a "header" to "raw" Base64 text (which is a method of storing images as text), so it can be "resolved" and viewed in a Power Apps Image Control.

However the Power App PDF viewer is something else. I have never been able to get one to work without a Flow - a simple one as below - taking a PDF file from a SharePoint Library (SharePoint is not relevant, but it needs to be a file).

PDFFlow.png

Helpful resources

Announcements
secondImage

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

Top Solution Authors
Top Kudoed Authors
Users online (18,406)