@@ -62,56 +62,56 @@ Installation uses the [npm](http://npmjs.org/) package manager. Just type the f
6262
6363## Example
6464
65- ``` coffeescript
66- PDFDocument = require ' pdfkit'
65+ ``` javascript
66+ const PDFDocument = require ( ' pdfkit' );
6767
68- # Create a document
69- doc = new PDFDocument
68+ // Create a document
69+ const doc = new PDFDocument ;
7070
71- # Pipe its output somewhere, like to a file or HTTP response
72- # See below for browser usage
73- doc .pipe fs .createWriteStream (' output.pdf' )
71+ // Pipe its output somewhere, like to a file or HTTP response
72+ // See below for browser usage
73+ doc .pipe ( fs .createWriteStream (' output.pdf' ));
7474
75- # Embed a font, set the font size, and render some text
75+ // Embed a font, set the font size, and render some text
7676doc .font (' fonts/PalatinoBold.ttf' )
7777 .fontSize (25 )
78- .text (' Some text with an embedded font!' , 100 , 100 )
78+ .text (' Some text with an embedded font!' , 100 , 100 );
7979
80- # Add an image, constrain it to a given size, and center it vertically and horizontally
80+ // Add an image, constrain it to a given size, and center it vertically and horizontally
8181doc .image (' path/to/image.png' , {
8282 fit: [250 , 300 ],
8383 align: ' center' ,
8484 valign: ' center'
8585});
8686
87- # Add another page
87+ // Add another page
8888doc .addPage ()
8989 .fontSize (25 )
90- .text (' Here is some vector graphics...' , 100 , 100 )
90+ .text (' Here is some vector graphics...' , 100 , 100 );
9191
92- # Draw a triangle
92+ // Draw a triangle
9393doc .save ()
9494 .moveTo (100 , 150 )
9595 .lineTo (100 , 250 )
9696 .lineTo (200 , 250 )
97- .fill (" #FF3300" )
97+ .fill (" #FF3300" );
9898
99- # Apply some transforms and render an SVG path with the 'even-odd' fill rule
99+ // Apply some transforms and render an SVG path with the 'even-odd' fill rule
100100doc .scale (0.6 )
101101 .translate (470 , - 380 )
102102 .path (' M 250,75 L 323,301 131,161 369,161 177,301 z' )
103103 .fill (' red' , ' even-odd' )
104- .restore ()
104+ .restore ();
105105
106- # Add some text with annotations
106+ // Add some text with annotations
107107doc .addPage ()
108108 .fillColor (" blue" )
109109 .text (' Here is a link!' , 100 , 100 )
110- .underline (100 , 100 , 160 , 27 , color : " #0000FF" )
111- .link (100 , 100 , 160 , 27 , ' http://google.com/' )
110+ .underline (100 , 100 , 160 , 27 , { color: " #0000FF" } )
111+ .link (100 , 100 , 160 , 27 , ' http://google.com/' );
112112
113- # Finalize PDF file
114- doc .end ()
113+ // Finalize PDF file
114+ doc .end ();
115115```
116116
117117[ The PDF output from this example] ( http://pdfkit.org/demo/out.pdf ) (with a few additions) shows the power of PDFKit — producing
@@ -133,28 +133,29 @@ module.
133133The following example uses Browserify to load ` PDFKit ` and ` blob-stream ` , but if you're not using Browserify,
134134you can load them in whatever way you'd like (e.g. script tags).
135135
136- ``` coffeescript
137- # require dependencies
138- PDFDocument = require ' pdfkit'
139- blobStream = require ' blob-stream'
136+ ``` javascript
137+ // require dependencies
138+ const PDFDocument = require ( ' pdfkit' );
139+ const blobStream = require ( ' blob-stream' );
140140
141- # create a document the same way as above
142- doc = new PDFDocument
141+ // create a document the same way as above
142+ const doc = new PDFDocument ;
143143
144- # pipe the document to a blob
145- stream = doc .pipe (blobStream ())
144+ // pipe the document to a blob
145+ const stream = doc .pipe (blobStream ());
146146
147- # add your content to the document here, as usual
147+ // add your content to the document here, as usual
148148
149- # get a blob when you're done
150- doc .end ()
151- stream .on ' finish' , ->
152- # get a blob you can do whatever you like with
153- blob = stream .toBlob (' application/pdf' )
149+ // get a blob when you're done
150+ doc .end ();
151+ stream .on ( ' finish' , function () {
152+ // get a blob you can do whatever you like with
153+ const blob = stream .toBlob (' application/pdf' );
154154
155- # or get a blob URL for display in the browser
156- url = stream .toBlobURL (' application/pdf' )
157- iframe .src = url
155+ // or get a blob URL for display in the browser
156+ const url = stream .toBlobURL (' application/pdf' );
157+ iframe .src = url;
158+ });
158159```
159160
160161You can see an interactive in-browser demo of PDFKit [ here] ( http://pdfkit.org/demo/browser.html ) .
0 commit comments