Skip to content
PDF Rendering backend for the HTML Canvas (2D) API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
lib/HTML/Canvas/To
t
.gitignore
.travis.yml
Changes
LICENSE
META6.json
README.md
dist.ini

README.md

HTML-Canvas-To-PDF-p6

Build Status

This is a PDF rendering back-end for HTML::Canvas.

  • A canvas may be rendered to either a page, or an XObject form, using a PDF::Content graphics object
  • This back-end is compatible with PDF::Lite, PDF::Class and PDF::API6.
  • Supported canvas image formats are PNG, GIF, JPEG and PDF

This back-end is experimental.

It may be useful, if you wish to manipulate existing PDF files use the HTML Canvas API.

use v6;
# Finish an existing PDF. Add a background color and page numbers

use PDF::Lite;
use PDF::Content;
use HTML::Canvas;
use HTML::Canvas::To::PDF;

# render to a PDF page
my PDF::Lite $pdf .= open: "examples/render-pdf-test-sheets.pdf";

# use a cache for shared resources such as fonts and images.
# for faster production and smaller multi-page PDF files
my HTML::Canvas::To::PDF::Cache $cache .= new;
my $pages = $pdf.page-count;

for 1 .. $pages -> $page-num {
    my $page = $pdf.page($page-num);
    my HTML::Canvas $canvas .= new;
    my PDF::Content $gfx = $page.pre-gfx;
    my HTML::Canvas::To::PDF $feed .= new: :$gfx, :$canvas, :$cache;
    $canvas.context: -> \ctx {
        ctx.fillStyle = "rgba(0, 0, 200, 0.2)";
        ctx.fillRect(10, 25, $page.width - 20, $page.height - 45);
        ctx.font = "12px Arial";
        ctx.fillStyle = "rgba(50, 50, 200, 0.8)";
        ctx.fillText("Page $page-num/$pages", 550, 15);
    }
}

$pdf.save-as: "examples/demo.pdf";

Images

You can’t perform that action at this time.