Open GeorgeP39 opened 5 years ago
Related to #976
This is what I use now 🙈
// Make a temporary wrap object by calling "continued" on the text function.
// Use the _text so it has no effect on the actual document.
const tmpWrapper = doc._text("", 0, 0, { width: 100, continued: true }, () => {});
// Extract the LineWrapper object, and its class constructor, from the returned wrapper.
const LineWrapper = tmpWrapper._wrapper.__proto__.constructor;
// Construct a new instance with this constructor.
const wrapper = new LineWrapper(doc, { width: 400, indent: 0 });
// Wrap the text.
wrapper.on("line", yourCallback);
wrapper.wrap(article.body, { width: 400, indent: 0 });
Make pdfkit's wrapper accessible externally.
Allow the use of pdfkit's powerful LineWrapper from outside of pdfkit.
Allow access to pdfkit's wrapper from outside the js. I wanted to create multi-line links by creating rectangular annotations over the top of some text. In order to achieve this, I need to know the "rectangles" that describe the lines of text. pdfkit already has a powerful
LineWrapper
but I couldn't access it without moving its declaration outside of the function it's currently in.I want to be able to do something like
where
measure
is an option to have it return the bounding rectangles andwrapRects
will be an array of these rectangles.