Enhance client side PDFKit:
- Adds HTML primitives like h1, h2, h3, p, img, br, hr, table.
- Can take a SimpleSchema, parse it and render it.
- Support for internationalization.
- Can render external image or images within CollectionFS.
- Support regular SVG as well as D3 SVG.
- Can add screenshot of a rendered Blaze's template.
meteor add pierreeric:pdfrenderer
Here is the generated PDF from this sample app: sample.
CustomerSchema = new SimpleSchema
name:
type: String
label: TAPi18n.__ 'name'
images:
type: String
label: TAPi18n.__ 'images'
optional: true
autoform: afFieldInput:
type: 'fileUpload'
collection: 'Images'
address:
type: Object
label: TAPi18n.__ 'address'
'address.street':
type: String
label: TAPi18n.__ 'street'
pdf: true
'address.city':
type: String
label: TAPi18n.__ 'city'
pdf: true
Customers = new Mongo.Collection 'customers'
Customers.attachSchema CustomerSchema
if Meteor.isServer
if Customers.find().count() is 0
Customers.insert
name: 'Mathilde Charpentier'
address:
street: '227, rue Camille de Richelieu'
city: 'Strasbourg'
Meteor.publish 'customers', -> Customers.find()
if Meteor.isClient
Template.svgTest.onCreated ->
sub = @subscribe 'customers'
@autorun =>
if sub.ready()
@customer = Customers.findOne()
Template.svgTest.helpers
customer: -> Template.instance().customer
Template.svgTest.events
'click button': (e, t) ->
# Create the initial PDF document
pdf = new PdfRenderer size: 'a4'
# Load all required assets
pdf.addAsset "/cfs/files/images/#{t.customer.images}" if t.customer.images
# Use reactivity for loading assets if any
t.autorun ->
if pdf.ready()
# Customer image if exists
if t.customer.images?
pdf.img "/cfs/files/images/#{t.customer.images}", 'RIGHT',
width: 100
# Customer's name
pdf.h1 t.customer.name
# Address of customer
pdf.h2 TAPi18n.__ 'address'
pdf.schema CustomerSchema, 'address', t.customer
# End the PDF document, display it and enable back the PDF button
pdf.finish "file-#{t.customer.name}.pdf", ->
console.log 'PDF finished'
Contributions are very welcomed. Feel free to PR for enhancing this package.
Your i18n file must at least contain the following for using SimpleSchema:
{
"colon": ": ",
"yes": "Yes",
"no": "No"
}
Use the proper package modifier of MomentJS for your locales:
# For french:
meteor add rzymek:moment-locale-fr
# For German:
meteor add rzymek:moment-locale-de
...
A test application is provided in the app
folder.
API's documentation uses DocBlockr syntax. Generates the API's documentation using markdox.
markdox PdfRenderer.coffee -o doc/api.md