Open gamesover opened 5 years ago
@gamesover Have you fixed it?
No Luck, I used html2canvas and jsPDF in the end. html2pdf.js
seems quite inactive now.
Anyone?
@gamesover Thx dood I was able to follow your trail eons later. To those who come after me : https://stackoverflow.com/questions/26481645/how-to-use-html2canvas-and-jspdf-to-export-to-pdf-in-a-proper-and-simple-way
For me it works in TypeScript:
import * as html2pdf from 'html2pdf.js';
...
const element = document.querySelector( '.my-element' );
const opt = {
margin: 1,
filename: 'myfile.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
html2pdf.default( element, opt );
I can import and print, but the content is blank
I can import and print, but the content is blank
It solved in #517
Has anyone fixed it?
html2canvas
NO
using CDN,
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js" integrity="sha512-GsLlZN/3F2ErC5ifS5QtgpiJtWd43JWSuIgh7mbzZ8zBps+dvLusV+eNQATqgA/HdeKFVgA5v3S/cIrLF7QnIg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
then
const newWindowObject = window as any
const html2pdf = newWindowObject.html2pdf
Note this declaration module does not contain all the options, add the ones you need if they aren't enough!!!
Steps to create the declaration file: Create a file called html2pdf.d.ts in your project, preferably inside a folder like src/types or @types. Example file structure:
src/
types/
html2pdf.d.ts
Add the following code to the html2pdf.d.ts file to declare the module:
declare module 'html2pdf.js' {
interface Html2PdfOptions {
margin?: number | [number, number, number, number];
filename?: string;
image?: { type: string; quality: number };
html2canvas?: { scale: number };
jsPDF?: { unit: string; format: string; orientation: string };
}
export default function html2pdf(
element: HTMLElement | string,
options?: Html2PdfOptions
): Promise<void>;
}
This file defines basic types for the html2pdf.js module and declares the module itself so TypeScript no longer complains about the missing type definitions.
{ "compilerOptions": { "typeRoots": ["./src/types", "node_modules/@types"] } }
This should resolve the issue, allowing you to use html2pdf.js in your TypeScript project without errors.
I am trying to import this lib into react typescript project.
Then create a
typing.d.ts
belowHowever, my project reports the below errors
I opened the source file in chrome
May I ask what's wrong with my config?
Thank you