0

I am trying to display a PDF stored in static resource and passing the blob as a string to VF page and late rendering as PDF

<apex:page controller="DataDisplayController" renderAs="pdf">
  {!PDFData}
<!--<iframe src="data:application/pdf;base64,{!PDFData}" ></iframe>--> 
<!--iframe doesn't display the data  --> 
</apex:page>

Displays only the Blob value in VF Page but I need the data from the blob

JVBERi0xLjUNJeLjz9MNCjk2IDAgb2JqIDw8L0xpbmVhcml6ZWQgMS9MIDQzNzQyNC9PIDEwNy9FID ------- Blob recieved in VF page

The string is valid UTF-8 stirng --> EncodingUtil.base64Encode(csvBlob);

How Am i supposed to display the blob data in VF page

3
  • 1
    You can't render a PDF in a PDF. The underlying rendering engine (Flying Saucer) does not support this sort of functionality. I'm not sure what you're trying to do, but this path is a dead end.
    – sfdcfox
    Apr 26, 2019 at 13:37
  • oh Okay, but Can I display the Blob data in VF page. Can you suggest a workaround for that?
    – SFDC
    Apr 27, 2019 at 4:51
  • You can only display certain types of Blob files, such as a PNG or JPG. You can't put in any arbitrary type.
    – sfdcfox
    Apr 27, 2019 at 14:37

1 Answer 1

-1
    <html>
    <head>
      <meta charset="UTF-8">
      <title>'Hello, world!' base64 example</title>
    </head>
    <body>
    <h1>'Hello, world!' example</h1>
    <canvas id="the-canvas" style="border:1px  solid black"></canvas>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.0.487/pdf.min.js"></script>
    <script id="script">
      var pdfData = atob(
        'JVBERi0xLjQKJeLjz9MKNCAwIG9iago8PC9MZW5ndGggMTc5Mi9GaWx0ZXIvRmxhdGVEZWNvZGU+\nPnN0cmVhbQp4nL2az2tcVRTHXwUVZiP6D+RttC3S5N2f855BRFEDVadJZqqETmsbm0YlaWuToEXx\nB7VQCaNd2MSNhS7EhbuuxIXQv8CFGze6kYI7XUURpN4fM+/dibn33HNbZGhz29w333s+c++558cU\nOckPkbzIRSXU36+ttt5qPdNrMZkLUeW9063neq25Fs0P6//V84p8NLu32pp6nuSkyHtnWgcO9t7U\nc5sp5s2ch1ghJ0U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BuIAow\nMDAwMDAyODQ2IDAwMDAwIG4gCjAwMDAwMDI4NzkgMDAwMDAgbiAKMDAwMDAwMjk4NCAwMDAwMCBu\nIAp0cmFpbGVyCjw8L1Jvb3QgMTEgMCBSL0lEIFs8NzM3YjNiYTEyZTQ3ZjE4MDdlYjE1NDA1NjMw\nMDQyYWI+PDRiMzVlN2ZlOWU0YTM4YWU3ZDJiY2E1MTgzNmQ2NWZmPl0vSW5mbyAxMiAwIFIvU2l6\nZSAxMz4+CnN0YXJ0eHJlZgozMTUyCiUlRU9GCg=='
      );
      pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.0.487/pdf.worker.min.js';
      pdfjsLib.getDocument({data: pdfData}).then(function getPdfHelloWorld(pdf) {
        // Fetch the first page.
        pdf.getPage(1).then(function getPageHelloWorld(page) {
          var scale = 1.5;
          var viewport = page.getViewport(scale);
          var canvas = document.getElementById('the-canvas');
          var context = canvas.getContext('2d');
          canvas.height = viewport.height;
          canvas.width = viewport.width;
          var renderContext = {
            canvasContext: context,
            viewport: viewport
          };
          page.render(renderContext);
        });
      });
    </script>
    <hr>
    <h2>JavaScript code:</h2>
    <pre id="code"></pre>
    <script>
      document.getElementById('code').textContent =
      document.getElementById('script').text;
    </script>
    </body>
    </html>
1
  • Code dumps make for poor answers. The explanation is as important as the solution. What was the problem OP was running into? What makes this approach different? Why would this work?
    – Derek F
    Feb 21, 2023 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .