Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate PDF from SVG #14

Open
jhkst opened this issue Apr 18, 2021 · 3 comments
Open

Generate PDF from SVG #14

jhkst opened this issue Apr 18, 2021 · 3 comments

Comments

@jhkst
Copy link
Owner

jhkst commented Apr 18, 2021

There is a js library to generate PDF from SVG (https://github.com/yWorks/svg2pdf.js/ ) that can generate PDF from SVG (so it is not necessary to include redundant PDF in sources).
Let's try it and if it works, remove the PDF (or make possible both - generate from SVG or use attached PDF)

@jhkst
Copy link
Owner Author

jhkst commented Apr 25, 2021

Tried this code:

form-ular.html:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.3.1/jspdf.umd.min.js"></script>
<script src="lib/svg2pdf.umd.js"></script>

fu-svg.js:

async toPdf() {
        const svgE = $(this.svgElement).get(0);
        svgE.getBoundingClientRect();
        const width = svgE.width.baseVal.value;
        const height = svgE.height.baseVal.value;
        const pdf = new jspdf.jsPDF(width > height ? 'l' : 'p', 'pt', [width, height]);
        const font = await fetch('forms/jsd_14312/fonts/LiberationSans-Regular.ttf').then(res => res.text());
        pdf.addFileToVFS("LiberationSans-Regular.ttf", font);
        pdf.addFont("LiberationSans-Regular.ttf", "Liberation Sans", "normal");

        pdf.svg(svgE, { width, height }).then(() => { pdf.save('myPdf.pdf')});

    }

and when called it throws

jsPDF PubSub Error No unicode cmap for font Error: No unicode cmap for font
    registerTTF ttffont.js:128
    t ttffont.js:38
    open ttffont.js:20
    <anonymous> ttfsupport.js:33
    <anonymous> ttfsupport.js:64
    publish jspdf.js:70
    Se jspdf.js:2454
    addFont jspdf.js:4924
    toPdf fu-svg.js:115
    async* debugger eval code:1
    <anonymous> form-ular.js:225
    jQuery 9
    <anonymous> form-ular.js:224
    jQuery 13
console.js:22:33

and

jsPDF PubSub Error e.metadata.Unicode is undefined TypeError: e.metadata.Unicode is undefined
    pdfEscape16 utf8.js:17
    i utf8.js:315
    <anonymous> utf8.js:361
    publish jspdf.js:70
    text jspdf.js:3909
    put svg2pdf.umd.js:2971
    renderCore svg2pdf.umd.js:3122
    renderCore svg2pdf.umd.js:3114
    step svg2pdf.umd.js:105
    verb svg2pdf.umd.js:86
    __awaiter svg2pdf.umd.js:79
    __awaiter svg2pdf.umd.js:75
    renderCore svg2pdf.umd.js:3047
    render svg2pdf.umd.js:2215
    step svg2pdf.umd.js:105
    verb svg2pdf.umd.js:86
    __awaiter svg2pdf.umd.js:79
    __awaiter svg2pdf.umd.js:75
    render svg2pdf.umd.js:2188
    renderCore svg2pdf.umd.js:5014
    step svg2pdf.umd.js:105
    verb svg2pdf.umd.js:86
    __awaiter svg2pdf.umd.js:79
    __awaiter svg2pdf.umd.js:75
    renderCore svg2pdf.umd.js:5004
    render svg2pdf.umd.js:2215
    step svg2pdf.umd.js:105
    verb svg2pdf.umd.js:86
    __awaiter svg2pdf.umd.js:79
    __awaiter svg2pdf.umd.js:75
    render svg2pdf.umd.js:2188
    renderCore svg2pdf.umd.js:5014
    step svg2pdf.umd.js:105
    verb svg2pdf.umd.js:86
    fulfilled svg2pdf.umd.js:76
    <anonymous> form-ular.js:225
    jQuery 9
    <anonymous> form-ular.js:224
    jQuery 13

for every rendered text.

@jhkst
Copy link
Owner Author

jhkst commented Apr 25, 2021

The font is rendered properly after that, but unicode chars (glyphs, etc.) are rendered as from different encoding.
Eg.

'doručováno' => 'doru ovÆno'

@jhkst
Copy link
Owner Author

jhkst commented Apr 25, 2021

Moreover Acrobat Reader reports 'The font LiberationSans-Regular.ttf' contains a bad /BBox'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant