I believe due to locker service these libraries are no longer working in Lightning component.
Verified in : https://developer.salesforce.com/docs/component-library/tools/locker-service-console
Is there any way to generate pdf out of image base64 data in lightning component.
Update:
How can I pass id dynamically while creating pdf using renderAs
from Apex:
<apex:page id="testPage" applyBodyTag="false" renderAs="pdf"
standardStylesheets="false"
applyHtmlTag="false" showHeader="false" controller="TestCtrl">
<img src="/servlet/servlet.FileDownload?file={!MyFileId}" width="100%" height="100%"/>
</apex:page>
I tried this, but I think as its a bing variable it did not work.
Attachment attachment = new Attachment();
attachment.ContentType = 'image/png';
attachment.Name = 'Test123.png';
attachment.ParentId = 'CaseId';
attachment.Body = EncodingUtil.base64Decode(fetchBase64Image());
insert attachment;
attachmentId = attachment.Id;
Page.ImageToPDF_ACE.getParameters().put('MyFileId', attachmentId);
So that I can make a fucture callout with that Id and use page.getContents
to generate PDF.
Best Answer
Here is the way to convert image to PDF and send it from Lightning, or Visualforce or LWC:
fetchBase64Image2
, this method can be invoked from Lightning, here you can pass the base64 version of image file, or base64 version of any file.Inside that method I just created an attachment on Case. And added the attachmentId to the Param of the new page reference. In the new page have a
renderAs
tag as PDF. Which will render the image as PDF.Next we are going to fire a future callout to fetch the page contents of the page reference we just created.
fetchContentDataFromPage(pageReference2.getUrl());
and finally send the image as pdf from future.
Here is the VF Page: