1

I am struggling to convert a lit template into pdf. I am using jsPDF (although I can use another javascript library if needed)

I have the following lit template to export into pdf

import { LitElement, html } from 'lit';
import { jsPDF } from "jspdf";

export class TestPage extends LitElement {
static properties = {
    myHTML: { type: Object },
  };

constructor() {
super();
this.myHTML = html`<h1>My title</h1>
  <div>some text to export to pdf</div>`;
this.doc = new jsPDF();
this.doc.text(this.myHTML, 10, 10);
  }
}
customElements.define('test-page', TestPage);

jsPDF returns:

Uncaught Error: Type of text must be string or Array. "[object Object]" is not recognized.

I do not have the option to render the lit template first before exporting it. I need to use the variable as a HTML source.

Thanks for any hints.

MadeInLagny
  • 185
  • 1
  • 12
  • I'm not sure what "I do not have the option to render the lit template first" means as it looks like you should already be in a browser environment. Are you generating the pdf in node? Otherwise something like this example should work: https://lit.dev/playground/#gist=47dbc46d187c6bed97403a381b19bb20 This example renders some temporary html, and then passes it to jsDoc to create the pdf. – YouCodeThings Jul 26 '22 at 01:03

0 Answers0