Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How can I generate base64 to pdf?

Asked by David Edwards May 27, 2024 2.8K views 2 answers
Share

About this question

 I want to create a LWC to download a simple PDF file with a random string. Here is my code: Apex class:


public with sharing class PdfLwcController {
    @AuraEnabled
    public static String getBase64String() {
        String s = 'Hello World!';
        
        return EncodingUtil.base64Encode(Blob.toPdf(s));
    }
}
Client-side controller:
import { LightningElement } from 'lwc';
import getBase64String from '@salesforce/apex/PdfLwcController.getBase64String';
export default class PdfButton extends LightningElement {
    handleClick() {
        getBase64String({})
            .then(response =>{
                // I don't know how to generate and download a pdf file.
            })
    }
}
HTML:

The Server-side controller can return a Base64 String, but I don't know how to generate the PDF file and download it immediately (don't save it to the attachment or file). Do you have any ideas? Thank you so much.

Your answer

2 Answers

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.