0

I want to create LWC component in which I have one file selector which is uploading '.pdf', '.png','.jpg','.jpeg','.docx','.doc' types of file in salesforce. but on button click I want that file to get converted into PDF and gets download immediately. Is it possible to convert file using js in LWC?.

I got this code but it is only working on string containing HTML element. I want it to work on whole file.

window.jsPDF = window.jspdf.jsPDF;
var doc = new jsPDF();
    
// Source HTMLElement or a string containing HTML.
var elementHTML = document.querySelector("#content");

doc.html(elementHTML, {
    callback: function(doc) {
        // Save the PDF
        doc.save('sample-document.pdf');
    },
    margin: [10, 10, 10, 10],
    autoPaging: 'text',
    x: 0,
    y: 0,
    width: 190, //target width in the PDF document
    windowWidth: 675 //window width in CSS pixels
});
2
  • thanks, please suggest some js libraries for conversion Commented Feb 16, 2023 at 11:23
  • If you do not wish to include a JS library with your component, one way to do this is through using an externally hosted Cloud Service to perform the conversion. The LEADTOOLS Hosted Cloud Services has the Convert API which can be used to convert DOCX to PDF. If you are interested, you can find a demo for this here. (Disclaimer: I am an employee of the vendor) Commented Feb 23, 2023 at 14:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.