5

Hi I have base64 encoded blob data on my page. It is pdf blob data. How can I convert this data to display as PDF.

I have tried iFrame, Embed object everything.. It is not working. The blob data is huge. Is there any viewer which would get this working? Also, I should be able to select texts in the displayed PDF data.

NoNicknameSFDC
  • 221
  • 1
  • 5
  • 10

2 Answers2

1

try it

<object data="data:application/pdf;base64,<?php echo base64_encode($content) ?>" type="application/pdf" style="height:200px;width:60%"></object>
0

In Java and Vaadin I tried the answer of Ayra successfully. I have got the bytes[] from a file. They could be got from any other source.

public class View extends Div {

  public View() {

    String myHTML_1="<object data=\"data:application/pdf;base64,$CONTENT$\" type=\"application/pdf\" style=\"height:200px;width:60%\"></object>";
    Base64.Encoder enc = Base64.getEncoder();
    String base64=""; //Get the content form a file.
    try {
        base64 = new String(enc.encode(Files.readAllBytes(Paths.get("/home/ximo/test.pdf"))));
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    String myHTML_1X=myHTML_1.replace("$CONTENT$",base64);
    add(new Html(myHTML_1X));  // and works in Chrome!
}
Ximo Dante
  • 67
  • 9