Giter Site home page Giter Site logo

html-canvas-to-pdf-raku's Introduction

HTML-Canvas-To-PDF-raku

Actions Status

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

  • 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.

This module is an alternative to HTML::Canvas, which is also able to save complete PDF files via Cairo.

It may be useful, for manipulating existing PDF files using the HTML Canvas API, or for integration with Raku PDF modules such as PDF::Lite or PDF::API6.

If this module is installed, the PDF::Content html-canvas() method will automatically render to a graphics stream using the HTML::Canvas::To::PDF back-end. The backend can thus be used on PDF Pages or XObject Forms:

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

use PDF::Lite;
use PDF::Content;
use PDF::Content::Page;
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 UInt $pages = $pdf.page-count;

for 1 .. $pages -> $page-num {
    my PDF::Content::Page $page = $pdf.page($page-num);
    my PDF::Content $gfx = $page.pre-gfx;
    $gfx.html-canvas: :$cache, -> \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";

html-canvas-to-pdf-raku's People

Contributors

dwarring avatar

Watchers

 avatar  avatar

html-canvas-to-pdf-raku's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.