TalkingBot/ingestion/tests/helpers/samplePdf.js

41 lines
1.3 KiB
JavaScript

const PDFDocument = require('pdfkit');
/**
* Five-page PDF with two top-level outline entries.
* @returns {Promise<Buffer>}
*/
function buildSamplePdf() {
return new Promise((resolve, reject) => {
const doc = new PDFDocument({ margin: 50 });
const chunks = [];
doc.on('data', (chunk) => chunks.push(chunk));
doc.on('end', () => resolve(Buffer.concat(chunks)));
doc.on('error', reject);
doc.fontSize(18).text('Sample Book', { align: 'center' });
doc.moveDown();
doc.fontSize(12).text('A short booklet used to test outline detection.');
doc.addPage();
doc.outline.addItem('Chapter One');
doc.fontSize(16).text('Chapter One');
doc.moveDown();
doc.fontSize(12).text('The first chapter begins with a river and a long road through the valley.');
doc.addPage();
doc.fontSize(12).text('The first chapter continues across the valley until the light changes.');
doc.addPage();
doc.outline.addItem('Chapter Two');
doc.fontSize(16).text('Chapter Two');
doc.moveDown();
doc.fontSize(12).text('The second chapter starts in a city beside a harbor.');
doc.addPage();
doc.fontSize(12).text('The second chapter ends when the ship leaves the harbor.');
doc.end();
});
}
module.exports = { buildSamplePdf };