-
-
Save trevordixon/3875911 to your computer and use it in GitHub Desktop.
PDFKit examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doc.addPage | |
size: 'legal' | |
layout: 'landscape' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doc.circle(100, 100, 50) | |
.lineWidth(3) | |
.fillOpacity(0.8) | |
.fillAndStroke("red", "#900") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PDFDocument = require 'pdfkit' | |
doc = new PDFDocument |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doc.circle(100, 100, 50) | |
.dash(5, space: 10) | |
.stroke() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# these examples are easier to see with a large line width | |
doc.lineWidth(25) | |
# line cap settings | |
doc.lineCap('butt') | |
.moveTo(50, 50) | |
.lineTo(100, 50) | |
.stroke() | |
doc.lineCap('round') | |
.moveTo(150, 50) | |
.lineTo(200, 50) | |
.stroke() | |
# square line cap shown with a circle instead of a line so you can see it | |
doc.lineCap('square') | |
.moveTo(250, 50) | |
.circle(275, 60, 15) | |
.stroke() | |
# line join settings | |
doc.lineJoin('miter') | |
.rect(50, 150, 50, 50) | |
.stroke() | |
doc.lineJoin('round') | |
.rect(150, 150, 50, 50) | |
.stroke() | |
doc.lineJoin('bevel') | |
.rect(250, 150, 50, 50) | |
.stroke() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set some meta data on an existing document | |
doc.info['Title'] = 'Test Document' | |
doc.info['Author'] = 'Devon Govett' | |
# Create a new document with some metadata | |
doc = new PDFDocument | |
info: | |
Title: 'Test Document' | |
Author: 'Devon Govett' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doc.moveTo(100, 20) # set the current point | |
.lineTo(200, 160) # draw a line | |
.quadraticCurveTo(230, 200, 250, 120) # draw a quadratic curve | |
.bezierCurveTo(290, -40, 300, 200, 400, 150) # draw a bezier curve | |
.lineTo(500, 90) # draw another line | |
.stroke() # stroke the path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doc.polygon [100, 100], [50, 200], [150, 200] | |
doc.stroke() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doc.path('M 100,20 L 200,160 Q 230,00 250,120 C 290,-40 300,200 400,150 L 500,90') | |
.stroke() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Save the document as a file | |
doc.write 'out.pdf' | |
# Get a string representation of the document | |
doc.output (string) -> | |
console.log string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding page with page size is not working.