html2pdf.js
html2pdf.js copied to clipboard
How to import this lib into react typescript?
I am trying to import this lib into react typescript project.
import html2pdf from 'html2pdf.js'
Then create a typing.d.ts
below
declare module 'html2pdf.js';
However, my project reports the below errors
fromRequireContextWithGlobalFallback.js:21 TypeError: _typeof is not a function
at html2pdf.js:16
at html2pdf.js:9
at Object../node_modules/html2pdf.js/dist/html2pdf.js (html2pdf.js:10)
I opened the source file in chrome
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/**
* html2pdf.js v0.9.1
* Copyright (c) 2018 Erik Koopmans
* Released under the MIT License.
*/
(function (global, factory) {
(typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('es6-promise/auto'), require('jspdf'), require('html2canvas')) : typeof define === 'function' && define.amd ? define(['es6-promise/auto', 'jspdf', 'html2canvas'], factory) : global.html2pdf = factory(null, global.jsPDF, global.html2canvas);
})(this, function (auto, jsPDF, html2canvas) {
'use strict';
jsPDF = jsPDF && jsPDF.hasOwnProperty('default') ? jsPDF['default'] : jsPDF;
html2canvas = html2canvas && html2canvas.hasOwnProperty('default') ? html2canvas['default'] : html2canvas;
var _typeof = typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol" ? function (obj) {
return _typeof(obj);
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj);
};
May I ask what's wrong with my config?
Thank you
@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