cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
praneepradee
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
WarrenBelz
Super User
Super User

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
WarrenBelz
Super User
Super User

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,801)