Skip to content

Commit

Permalink
update browserify
Browse files Browse the repository at this point in the history
  • Loading branch information
liborm85 committed Dec 23, 2024
1 parent 52daaf6 commit 0bf09fb
Show file tree
Hide file tree
Showing 51 changed files with 3,049 additions and 56 deletions.
42 changes: 42 additions & 0 deletions examples - kopie/attachment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const PDFDocument = require('../');
const fs = require('fs');
const path = require('path');

const doc = new PDFDocument({ pdfVersion: '1.4' });

doc.pipe(fs.createWriteStream('attachment.pdf'));

doc.info['Title'] = 'Attachment Test';

// add an embedded file from file system
doc.file(path.join(__dirname, 'images', 'test.png'), {
name: 'test.png',
type: 'image/png',
description: 'this is a test image'
});

// add some text
doc.text(`This PDF contains three text files:
Two file attachment annotations and one embedded file.
If you can see them (not every PDF viewer supports embedded files),
hover over the paperclip to see its description!`);

// add a file attachment annotation
// first, declare the file to be attached
const file = {
src: Buffer.from('buffered input!'),
name: 'embedded.txt',
creationDate: new Date(2020, 3, 1)
};
// then, add the annotation
doc.fileAnnotation(100, 150, 10, doc.currentLineHeight(), file);

// declared files can be reused, but they will show up separately in the PDF Viewer's attachments panel
// we're going to use the paperclip icon for this one together with a short description
// be aware that some PDF Viewers may not render the icon correctly — or not at all
doc.fileAnnotation(150, 150, 10, doc.currentLineHeight(), file, {
Name: 'Paperclip',
Contents: 'Paperclip attachment'
});

doc.end();
Binary file added examples - kopie/attachment.pdf
Binary file not shown.
54 changes: 54 additions & 0 deletions examples - kopie/browserify/browser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<style>
body {
width: 1230px;
margin: 20px auto;
font-family: Georgia;
}

h1 {
margin: 0;
}


a {
color: blue;
}

#editor {
width: 600px;
height: 775px;
margin-right: 20px;
display: inline-block;
}

iframe {
border: 1px solid black;
}
</style>
</head>

<body>
<h1>PDFKit Browser Demo</h1>
<p>Bundled with Browserify</p>
<p><a href="http://pdfkit.org/">Website</a> | <a href="http://github.com/foliojs/pdfkit">Github</a></p>
<div id="editor"></div>
<iframe width="600" height="775"></iframe>
<script src="bundle.js"></script>
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-48340245-1', 'pdfkit.org');
ga('send', 'pageview');
</script>
</body>

</html>
124 changes: 124 additions & 0 deletions examples - kopie/browserify/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
var PDFDocument = require('../..');
var blobStream = require('blob-stream');
var ace = require('brace');
require('brace/mode/javascript');
require('brace/theme/monokai');

var lorem =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in suscipit purus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus nec hendrerit felis. Morbi aliquam facilisis risus eu lacinia. Sed eu leo in turpis fringilla hendrerit. Ut nec accumsan nisl. Suspendisse rhoncus nisl posuere tortor tempus et dapibus elit porta. Cras leo neque, elementum a rhoncus ut, vestibulum non nibh. Phasellus pretium justo turpis. Etiam vulputate, odio vitae tincidunt ultricies, eros odio dapibus nisi, ut tincidunt lacus arcu eu elit. Aenean velit erat, vehicula eget lacinia ut, dignissim non tellus. Aliquam nec lacus mi, sed vestibulum nunc. Suspendisse potenti. Curabitur vitae sem turpis. Vestibulum sed neque eget dolor dapibus porttitor at sit amet sem. Fusce a turpis lorem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;\nMauris at ante tellus. Vestibulum a metus lectus. Praesent tempor purus a lacus blandit eget gravida ante hendrerit. Cras et eros metus. Sed commodo malesuada eros, vitae interdum augue semper quis. Fusce id magna nunc. Curabitur sollicitudin placerat semper. Cras et mi neque, a dignissim risus. Nulla venenatis porta lacus, vel rhoncus lectus tempor vitae. Duis sagittis venenatis rutrum. Curabitur tempor massa tortor.';

function makePDF(PDFDocument, blobStream, lorem, iframe) {
// create a document and pipe to a blob
var doc = new PDFDocument();
var stream = doc.pipe(blobStream());

// draw some text
doc.fontSize(25).text('Here is some vector graphics...', 100, 80);

// some vector graphics
doc
.save()
.moveTo(100, 150)
.lineTo(100, 250)
.lineTo(200, 250)
.fill('#FF3300');

doc.circle(280, 200, 50).fill('#6600FF');

// an SVG path
doc
.scale(0.6)
.translate(470, 130)
.path('M 250,75 L 323,301 131,161 369,161 177,301 z')
.fill('red', 'even-odd')
.restore();

doc.save();
// a gradient fill
var gradient = doc
.linearGradient(100, 300, 200, 300)
.stop(0, 'green')
.stop(0.5, 'red')
.stop(1, 'green');
doc.rect(100, 300, 100, 100).fill(gradient);

// stroke & fill uncolored tiling pattern

var stripe45d = doc.pattern(
[1, 1, 4, 4],
3,
3,
'1 w 0 1 m 4 5 l s 2 0 m 5 3 l s'
);
doc.circle(280, 350, 50).fill([stripe45d, 'blue']);

doc
.rect(380, 300, 100, 100)
.fillColor('lime')
.strokeColor([stripe45d, 'orange'])
.lineWidth(5)
.fillAndStroke();
doc.restore();

// and some justified text wrapped into columns
doc
.text('And here is some wrapped text...', 100, 450)
.font('Times-Roman', 13)
.moveDown()
.text(lorem, {
width: 412,
align: 'justify',
indent: 30,
columns: 2,
height: 300,
ellipsis: true
});

// end and display the document in the iframe to the right
doc.end();
stream.on('finish', function() {
iframe.src = stream.toBlobURL('application/pdf');
});
}

var editor = ace.edit('editor');
editor.setTheme('ace/theme/monokai');
editor.getSession().setMode('ace/mode/javascript');
editor.setValue(
makePDF
.toString()
.split('\n')
.slice(1, -1)
.join('\n')
.replace(/^ /gm, '')
);
editor
.getSession()
.getSelection()
.clearSelection();

var iframe = document.querySelector('iframe');
makePDF(PDFDocument, blobStream, lorem, iframe);

let debounceTimeout;

editor.getSession().on('change', function() {
try {
if (debounceTimeout) {
clearTimeout(debounceTimeout);
}
var fn = new Function(
'PDFDocument',
'blobStream',
'lorem',
'iframe',
editor.getValue()
);
debounceTimeout = setTimeout(() => {
fn(PDFDocument, blobStream, lorem, iframe);
debounceTimeout = undefined;
}, 100);
} catch (e) {
console.log(e);
}
});
Binary file added examples - kopie/fonts/Chalkboard.ttc
Binary file not shown.
Binary file added examples - kopie/fonts/DejaVuSans.ttf
Binary file not shown.
Binary file added examples - kopie/fonts/GoodDog.ttf
Binary file not shown.
Binary file added examples - kopie/fonts/Helvetica.dfont
Binary file not shown.
Binary file added examples - kopie/fonts/Montserrat-Bold.otf
Binary file not shown.
Binary file added examples - kopie/fonts/PalatinoBold.ttf
Binary file not shown.
85 changes: 85 additions & 0 deletions examples - kopie/form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
var PDFDocument = require('../');
var fs = require('fs');

// Create a new PDFDocument
var doc = new PDFDocument();

doc.pipe(fs.createWriteStream('form.pdf'));

// Set some meta data
doc.info['Title'] = 'Test Form Document';
doc.info['Author'] = 'test-acroform.js';

doc.font('Helvetica'); // establishes the default font for forms
doc.initForm();

let rootField = doc.formField('rootField');
doc.font('Courier');
let child1Field = doc.formField('child1Field', { parent: rootField });
doc.font('Helvetica');
let child2Field = doc.formField('child2Field', { parent: rootField });

let y = 10;
doc.formText('leaf1', 10, y, 200, 20, {
parent: child1Field,
value: '1999-12-31',
format: {
type: 'date',
param: 'yyyy-mm-dd'
},
align: 'center'
});

y += 30;
opts = {
parent: child1Field,
value: 32.98,
format: {
type: 'number',
nDec: 2,
currency: '$',
currencyPrepend: true
},
align: 'right'
};
doc.formText('dollar', 10, y, 200, 20, opts);

y += 30;
doc.formText('leaf2', 10, y, 200, 40, {
parent: child1Field,
multiline: true,
align: 'right'
});
y += 50;
doc.formText('leaf3', 10, y, 200, 80, {
parent: child2Field,
multiline: true
});

y += 90;
var opts = {
backgroundColor: 'yellow',
label: 'Test Button'
};
doc.formPushButton('btn1', 10, y, 100, 30, opts);

y += 40;
opts = {
borderColor: 'black',
select: ['Select Option', 'github', 'bitbucket', 'gitlab'],
value: 'Select Option',
defaultValue: 'Select Option',
align: 'center',
edit: true
};
doc.formCombo('ch1', 10, y, 100, 20, opts);

y += 30;
opts = {
borderColor: '#808080',
select: ['github', 'bitbucket', 'gitlab', 'sourcesafe', 'perforce'],
sort: true
};
doc.formList('ch2', 10, y, 100, 45, opts);

doc.end();
Binary file added examples - kopie/form.pdf
Binary file not shown.
Binary file added examples - kopie/images/dice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples - kopie/images/fish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples - kopie/images/interlaced-rgb-16bit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples - kopie/images/interlaced-rgb-8bit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples - kopie/images/straight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples - kopie/images/test.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples - kopie/images/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples - kopie/images/test2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples - kopie/images/test3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0bf09fb

Please sign in to comment.