Salesforce Developer Tutorial (LWC): How to Generate a PDF from a Lightning Web Component

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ต.ค. 2024

ความคิดเห็น • 76

  • @CodingWithTheForce
    @CodingWithTheForce  3 ปีที่แล้ว +3

    I meant to do this in the video and forgot it. I want to give a HUGE shoutout to Moonvvell on the Salesforce StackExchange for finding and commenting the answer to the problem of leveraging jsPDF in LWC's. I had done this in Aura multiple times without problems but I was missing something with the LWC variety and thanks to his solution this was easy as can be to create for you! Thank you Moonvvell and to everyone else who constantly contributes to the SF StackExchange. You make all our lives 1000x easier! salesforce.stackexchange.com/questions/298638/jspdf-importing-but-not-working-in-lwc

  • @nickd7919
    @nickd7919 2 ปีที่แล้ว +2

    Thanks, this tutorial is excellent, what advantages do you see in making the pdf with LWC instead of a visualforce page ?

  • @Shams-ox5nl
    @Shams-ox5nl 5 หลายเดือนก่อน

    Very helpful video to generate PDF, Keep doing good work
    thanks.

  • @aradhikachawla6284
    @aradhikachawla6284 3 ปีที่แล้ว

    Very helpful article. Thanks for demonstrating so well. It is working like a charm. finally we can create pdf generator with Lwc. Jspdf is a very powerful library.

    • @aradhikachawla6284
      @aradhikachawla6284 3 ปีที่แล้ว

      We will need to setup the CORS setting in the Salesforce - usually it is there but in a new org this types of missing settings will block jspdf file to not load consistantly

  • @ekron8601
    @ekron8601 2 ปีที่แล้ว

    Awesome, I'm going to try it, beacuse I don't want to create a visual force and besides learning some new, thanks so much :D :D

  • @Lapio.
    @Lapio. 8 หลายเดือนก่อน

    Hi! @CodingWithTheForce Thanks for this video!
    I have a question, How can i use with fields related? Because I tried and doent's work.
    Thanks!

  • @Evildragonfirez
    @Evildragonfirez ปีที่แล้ว

    I love your content. QQ though, does this version of pdfJS come with the "Viewer"? I'm needing to render a pdf from a blob on a component as a "document preview". I tried uploading the traditional library with the viewer but the zip is over 5mb lol.

    • @milanoleo
      @milanoleo 11 หลายเดือนก่อน

      Hey, i have the same issue :D Did you find a solution for it?

  • @meric7010
    @meric7010 ปีที่แล้ว

    Hey Matt, is it possible to take a graph i created using ChartJS and feed it to jsPDF to get the output? My client needs this done, do you have any tips or words that could guide me? Currently Im using chatGPT to find a way to do this, could really use your input.

  • @dimitrigiannakos6247
    @dimitrigiannakos6247 2 ปีที่แล้ว +1

    hi
    I have a question, how can i do this for one Account?

  • @UnclutchedSprints
    @UnclutchedSprints 2 ปีที่แล้ว

    Hi,
    Can I take a PDF from Visualforce or ConentDocument and render using the JS library?? If possible please let me know.. will be very helpful.

  • @MAMADOUFALL-c6e
    @MAMADOUFALL-c6e ปีที่แล้ว

    Hey Matt when i fetch number fields from apex controller jspdf doesn't display them in generated pdf

  • @jaiaswani8039
    @jaiaswani8039 ปีที่แล้ว

    Can we use any library such as stripe js or any other library just like you used jsPDF library.

  • @durbachakraborty7131
    @durbachakraborty7131 8 หลายเดือนก่อน

    pdf is not generating if any of the dara from the list is missing the value mentioned in headers .. for example if header is x and y and in one of the data x value is not coming or blank pdf is not generating for any of the data in list

  • @aradhikachawla6284
    @aradhikachawla6284 3 ปีที่แล้ว

    I am having issues in getting data from Salesforce record. It is in a rich text field has HTML code. I don't want to loose its formatting , any idea how can I convert it to plain text with keeping formatting? I used stripHtmltags with replaceAll but still some time text is not aligning perfectly and also also all bullets are gone. any suggestion Matt ?

  • @thorreloadedgaming
    @thorreloadedgaming ปีที่แล้ว

    I tried the same approach shown in the video, but its not working for me. I have exactly same code. Still not working.

  • @santoshreddy003
    @santoshreddy003 3 ปีที่แล้ว +1

    Thank you Matt! I am getting the error Cannot read property of '0' of undefined when clicking on the button. I have used same class, LWC and resource which is present in the repo that u have shared for printing the contacts. Can you please let me know a way to fix.
    Edit : I was able to identify the cause for the issue. Salesforce is blocking jsPdf as it is not locker compliant.But strangely, the export works for the very first time. But after that Salesforce is blocking it. Hence, I had to switch to traditional VF render as PDF approach.
    Anyways, thanks for sharing the information Matt :)

    • @bobbypepetrueno3431
      @bobbypepetrueno3431 2 ปีที่แล้ว

      Hi Santosh, how did you solve the problem:
      Cannot read properties of undefined (reading '0')
      ?

  • @chinq6t
    @chinq6t ปีที่แล้ว

    Hi - is it possible to generate a PDF that is essentially a screenshot of an LWC? The objective is to target and capture an LWC's HTML instead of the whole page (e.g. window.print)

  • @tilottamadeore1541
    @tilottamadeore1541 ปีที่แล้ว

    I am not able to get data in the table only headers are populating in pdf. Any suggestions?

  • @aradhikachawla8467
    @aradhikachawla8467 3 ปีที่แล้ว +1

    Hi Matt, When I am doing doc.save() function downloads the pdf with correct image but doc.output() does not save the image its coming distorted? any suggestions ? Anyone else facing this problem , please suggest and solution. I have to send this pdf to salesforce where I can attach as attachment. File is getting there but the image is not displaying correctly.

    • @aradhikachawla6284
      @aradhikachawla6284 3 ปีที่แล้ว +1

      Got the solution - send the doc.output('datauristring') and capture in Salesforce with att.Body = Encodingutil.base64Decode(doc.substring(doc.indexOf(',') + 1));

  • @chrisburns1733
    @chrisburns1733 ปีที่แล้ว

    Is there a way to open the PDF in a new tab and allow users to download the PDF contents using the SFDC mobile app?

  • @worldofsandeep3958
    @worldofsandeep3958 2 ปีที่แล้ว

    hey matt, everything is working for me except the doc.table line, how to resolve it??

  • @stevenduong8126
    @stevenduong8126 3 ปีที่แล้ว +2

    Dear Sir,
    jspdf:187 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '0')
    at Object.t.cell (jspdf:187)
    at Object.t.table (jspdf:187)
    at u.generatePdf (warrantySoService.js:4)
    at eval (warrantySoService.js:4)
    I have this bugs when deploy to the Org. Please advise. I copied all your code the same but still have the error. Please asdvise. Thanks.

  • @gkcd83
    @gkcd83 3 ปีที่แล้ว

    great video MATT!!! i'm trying to do the same , but the whole page (where you set the button) rendered, but with queryselectorall() but its doesn't work, do you know how to do that? you are genius you explained everything !!

  • @rammohanreddykasu9667
    @rammohanreddykasu9667 2 ปีที่แล้ว

    Hi, I have a blob content from Apex class, can I pass it to Js file and can still generate PDF?

  • @dastanaibek7351
    @dastanaibek7351 2 ปีที่แล้ว

    Hello, thanks for your video. How to show field labels instead of API names in PDF?

  • @nitishyadav554
    @nitishyadav554 3 ปีที่แล้ว

    Hey ! I landed on this tutorial and downloaded the latest min js file from the repository. I run into an error when loading the latest min file in my LWC but using the min file from your download URL loads perfectly fine. What could be going wrong ?
    Edit : I was not loading the umd.min file. Using the umd file worked. What could be different between the two ?

  • @ekron8601
    @ekron8601 2 ปีที่แล้ว

    the property window.jspdf==undefined , Why? some help please

  • @karoo686
    @karoo686 3 ปีที่แล้ว

    Hey Matt, Thank you for this tutorial. I am running into the same issue as Seemesh Patel below. I get the error [Cannot destructure property 'jsPDF' of 'window.jspdf' as it is undefined.]. I've tried using the ES, node and UMD versions of jspdf and always get the same error. Any help would be greatly appreciated.

  • @accursiomaniscalco9865
    @accursiomaniscalco9865 3 ปีที่แล้ว

    Hi, I have followed your tutorial and I find it very interesting :) I would like to ask you if you can pass an argument to the query present in the PdfGenerator class in order to print a list of lines that satisfy that argument. How is the argument passed from the lwc component to the class? Thanks in advance :)

  • @KevinToftegaard
    @KevinToftegaard 3 ปีที่แล้ว

    This is way above my skill level but i like to watch your videos and learn. I have one basic question.
    You use a program to make the thing. Would I be able to make it only in Salesforce?

    • @CodingWithTheForce
      @CodingWithTheForce  3 ปีที่แล้ว

      I believe they have open sourced lightning web components. You could theoretically be the same thing on another platform using their open source library for sure. It would be a bit different from this video, but relatively similar. github.com/salesforce/lwc

  • @GAMINGIN-lo6eg
    @GAMINGIN-lo6eg 2 ปีที่แล้ว

    Everything is fine,The headers are showing but the values below the table is empty.Can someone find me a solution.

  • @grayst3499
    @grayst3499 3 ปีที่แล้ว

    You can't tell me, it's possible to take a screenshot of the lwc component and output it to pdf??

  • @josedejesusricardosantos2921
    @josedejesusricardosantos2921 6 หลายเดือนก่อน

    It's too good man ur great !!
    Do you know how to create PDF's from html content?

  • @seemeshpatel7840
    @seemeshpatel7840 3 ปีที่แล้ว

    Hi, I have tried same way but getting below error
    [Cannot destructure property 'jsPDF' of 'window.jspdf' as it is undefined.]

    • @ekron8601
      @ekron8601 2 ปีที่แล้ว

      I got the same problem, did yoy fix it??

  • @BCE_OXYEHHO
    @BCE_OXYEHHO 3 ปีที่แล้ว

    Hey Matt, any plans to take it to the next level and make it work with Email HTML templates? I see it has support for HTML, but having hard time getting the dependent library imported and getting it to work. Error: Could not load dompurify

    • @Mantisentil00
      @Mantisentil00 8 หลายเดือนก่อน

      getting the same error when trying to build a pdf from HTML, 'Could not load dompurify'. Any known solutions to this?

  • @nickstoliker8707
    @nickstoliker8707 3 ปีที่แล้ว

    Can you CTRL + on the VSCode window, when on my phone I struggle to see your content. Also, great videos and topics!

    • @CodingWithTheForce
      @CodingWithTheForce  3 ปีที่แล้ว

      Hey man, yea I can do that for sure! I'll start zooming in a bit more in my future videos! Thanks for letting me know!

  • @rogmiksits290
    @rogmiksits290 3 ปีที่แล้ว +1

    I tried everything you said . I have this exact requirement to implement . When I see this video I felt like . god sent . But some what I am getting this error [Cannot read property '0' of undefined] , function- Object.t.cell, line-187, column-3246. Can you help me figure that out please?

    • @CodingWithTheForce
      @CodingWithTheForce  3 ปีที่แล้ว +1

      It happens when the ids of your table headers are not the same as the field api names of your table rows. It’s one of the errors I actually have run into a bunch of times and messed up in this video, lol. I think I briefly discuss it near the end.

    • @venkateshi3400
      @venkateshi3400 2 ปีที่แล้ว

      HI did u slove it ??

    • @bobbypepetrueno3431
      @bobbypepetrueno3431 2 ปีที่แล้ว +1

      @@CodingWithTheForce Thank u so much!

    • @Emergencymail-k1p
      @Emergencymail-k1p 11 หลายเดือนก่อน

      @@CodingWithTheForce Hi, what if I don't want the api names to be the table header rows and want the field labels to be the header rows. Ex: Api Name: SBQQ__NetPrice__c and Field Name: Net Unit Price. So how do I use the field names as the table header? Please do the needful any help would be much appreciated.

  • @accursiomaniscalco9865
    @accursiomaniscalco9865 3 ปีที่แล้ว

    It si possible to Generate a PDF from a Lightning Aura Component?

  • @sarveshreddy936
    @sarveshreddy936 2 ปีที่แล้ว

    hi iam getting this error can you please help me to solve it ?
    Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '0')
    at t.cell (jspdf:117:4427)
    at t.table (jspdf:117:6964)
    at f.generatePdf (generatePDF.js:1:813)
    at eval (generatePDF.js:1:953)

  • @alexiwalter4024
    @alexiwalter4024 2 ปีที่แล้ว

    Thank you for your videos. Is it possible to run this in an app on iOS ?
    Or do somebody know how to generate a pdf as attachment on iOS Salesforce app ?

  • @ramiroandresalvarez5632
    @ramiroandresalvarez5632 3 ปีที่แล้ว

    This is great! :)

  • @qwalinights6069
    @qwalinights6069 ปีที่แล้ว

    Is it possible to send this Pdf as an email attachment? Please do let me know if someone has done this...

  • @fredkampf
    @fredkampf 3 ปีที่แล้ว

    Thank you so much for this! Is there a guide that instructs how to add lines, different spacings, etc? thanks again!!

    • @CodingWithTheForce
      @CodingWithTheForce  3 ปีที่แล้ว

      Yea for sure! Hopefully these help! There's example implementations here: raw.githack.com/MrRio/jsPDF/master/
      The repo is here and it explains some stuff: github.com/MrRio/jsPDF
      The site dedicated to documentation is here: raw.githack.com/MrRio/jsPDF/master/docs/

    • @fredkampf
      @fredkampf 3 ปีที่แล้ว

      @@CodingWithTheForce Thank you! When trying to create a table, I am getting [Cannot read property '0' of undefined] error. thanks again for this, it great!!!

  • @pfe-rz7zw
    @pfe-rz7zw 2 ปีที่แล้ว +1

    what is the password ?

  • @anoopgalla7618
    @anoopgalla7618 3 ปีที่แล้ว

    It's too good man ur great 👍

  • @thescholarshub1116
    @thescholarshub1116 3 ปีที่แล้ว

    Bro need your help to generate proposal pdf from quote page please help

  • @jokerddlv
    @jokerddlv 3 ปีที่แล้ว

    Maybe you've already answered this before: Why not using VSCode?

    • @CodingWithTheForce
      @CodingWithTheForce  3 ปีที่แล้ว +1

      It’s primarily because the auto-complete feature is so much better in IntelliJ/IlluminatedCloud2. IlluminatedCloud2 also just has a ton more features that make development easier. I also prefer IntelliJ’s local Git comparison tool among a handful of other things. VSCode is great but IntelliJ and IlluminatedCloud2 are still way better.

  • @si6tynin
    @si6tynin 3 ปีที่แล้ว

    It would be great to start your videos with some kind of loud out mental diagram or designing the solution first.Thanks for these use cases.

    • @CodingWithTheForce
      @CodingWithTheForce  3 ปีที่แล้ว

      Hey Chetan, thanks for the idea, I might give that a shot soon. I have considered it in the past for sure.

  • @rumitrockstar4904
    @rumitrockstar4904 3 ปีที่แล้ว

    In video(s), if possible, zoom in the code editor a bit(make the fonts bigger).
    Overall, it is one of the best video I have found recently on LWC, thank you so much :)

    • @CodingWithTheForce
      @CodingWithTheForce  3 ปีที่แล้ว +1

      Yes absolutely! I'm trying to get into the habit of zooming in when coding. In my new video series that I'm going to be releasing soon I have tried hard to make sure I do that.

  • @StracheyWade-i4v
    @StracheyWade-i4v 17 วันที่ผ่านมา

    Williams Jennifer Walker Larry Harris Eric

  • @kevelopers
    @kevelopers ปีที่แล้ว

    Crack