
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@pdftron/canvas-to-pdf
Advanced tools
CanvasToPDF can create vector quality PDF images using the canvas API.
CanvasToPDF can create vector quality PDF images using the canvas API.
Internally, CanvasToPDF uses modified versions of canvas2pdf and PDFKit to call on actual PDF drawing methods. CanvasToPDF has several notable improvements from canvas2pdf in that it has no issues calling fill and stroke consecutively and that reading canvas properties do not lead to errors. Thus, you can create vectorized PDFs such as the one below.
CanvasToPDF internally manages a mock 2d canvas context. Thus, you only need to pass a draw function calling on canvas commands and not the canvas itself.
CanvasToPDF currently only supports client-side usage. You can use this library similar to the manner below.
import canvasToPDF from "@pdftron/canvas-to-pdf";
import saveAs from "./FileSaver";
const draw = (ctx) => {
// canvas methods
};
canvasToPDF(draw, { width: 100, height: 150 }).then((res) => {
saveAs(res, "example.pdf", true);
});
The canvasToPDF function returns a blob containing vector graphics based PDF file, but since it is difficult to check that the blob has the expected images drawn you can use FileSaver to download an actual PDF as seen in the code above.
const draw = (ctx) => {
for (let i = 0; i < 12; i++) {
for (let j = 0; j < 12; j++) {
ctx.strokeStyle = `rgb(
0,
${Math.floor(255 - 42.5 * i)},
${Math.floor(255 - 42.5 * j)})`;
ctx.beginPath();
ctx.arc(25 + j * 40, 25 + i * 40, 15, 0, Math.PI * 2, true);
ctx.stroke();
}
}
};
The above code will draw multiple circles with gradient borders:
MIT
FAQs
CanvasToPDF can create vector quality PDF images using the canvas API.
The npm package @pdftron/canvas-to-pdf receives a total of 12 weekly downloads. As such, @pdftron/canvas-to-pdf popularity was classified as not popular.
We found that @pdftron/canvas-to-pdf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.