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

feat: add closePath and transform in renderCanvas available methods #3080

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RNm-dove
Copy link

Summary

This PR enable SVG rendering in the <Canvas> painter by using svg-to-pdfkit.

Background

Since the canvas painter is a doc from pdfkit, I investigated whether svgToPdfkit could be used directly. I found that it works as long as transform and clipPath are exposed.

Related Issues

(None, but let me know if one should be created.)

Usage

import React from 'react';

import { Canvas } from '@react-pdf/renderer';

import SVGtoPDF from 'svg-to-pdfkit';

const svg = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<path d="M50,3l12,36h38l-30,22l11,36l-31-21l-31,21l11-36l-30-22h38z" fill="#FF0" stroke="#FC0" stroke-width="2"/>
</svg>
`;

const Star = () => (
  <Canvas
    style={{
      width: '100%',
      height: 100,
    }}
    paint={(painter, availableWidth, availableHeight) => {
      SVGtoPDF(painter, svg, 0, 0, {
        width: availableWidth,
        height: availableHeight,
      });
    }}
  ></Canvas>
);

export default Star;

Screenshots

スクリーンショット 2025-02-17 21 11 42

Copy link

changeset-bot bot commented Feb 17, 2025

⚠️ No Changeset found

Latest commit: b7094f8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@diegomura
Copy link
Owner

Can we leave this PR just to the addition of closePath and transform? The example is very cool but I'd rather not add this dependency here

@RNm-dove
Copy link
Author

Sure! I removed them and refreshed commit.
Thank you for your time.

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

Successfully merging this pull request may close these issues.

2 participants