Skip to content

Embed images with SVG #287

Description

@Leo-Nicolle

Describe the bug
tags with an href pointing to a SVG file are not displayed correctly

What version are you using (exact version of and jspdf)?
- jspdf: 2.5.1
- svg2pdf.js: 2.2.3

To Reproduce

  1. Test SVG:
<svg
      width="128"
      height="64"
      version="1.1"
      xmlns="http://www.w3.org/2000/svg"
      xmlns:xlink="http://www.w3.org/1999/xlink"
      style="user-select: none"
    >
      <rect x="0" y="0" width="128" height="64" stroke="black" fill="none" />
      <image
        width="64"
        height="64"
        x="0"
        y="0"
        href="https://upload.wikimedia.org/wikipedia/commons/1/16/Cellular_phone.svg"
      />
      <image
        width="64"
        height="64"
        x="64"
        y="0"
        href="https://upload.wikimedia.org/wikipedia/commons/a/a0/Goldfish-47022_1280.png"
      />
</svg>

Code:

import { jsPDF } from "jspdf";
import "svg2pdf.js";
const svg = document.querySelector("svg");
const doc = new jsPDF({ format: "a4", unit: "pt" });
doc.svg(svg, { x: 0, y: 0, width: 128, height: 64 }).then((doc) => {
  doc.save("doc.pdf");
});
  1. I get a square with the PNG image but not the SVG

Example Sandbox

Expected behavior
The SVG image should be drawn

Screenshots
Input SVG:
Screenshot from 2024-05-16 15-27-24
Output PDF:
Screenshot from 2024-05-16 15-27-08

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser Chromium
  • Version 125.0.6422.26

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wantedHelp with creating a proper test-case, looking up the spec, or creating a pull request.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions