Comments (10)
Is there any way to do this currently or is it not available?
We are using pdfmake which makes use of this library and we will need to add support for these soon.
from pdfkit.
I would be interested in this feature too.
from pdfkit.
We need to add superscript to the text for footnote references. This is an important feature for us. Can support for this feature be added to the library soon?
from pdfkit.
Is this a feature that will be implemented soon? We also need to add an important superscript in our pdfs.
from pdfkit.
Just a note, you can achieve superscript by using:
document.font(originalFont, originalSize * 0.5);
document.text(str, options);
document.font(originalFont, originalSize);
I would assume that you could do something along the lines of this for subscript (haven't tested, just an example):
const currentLineHeight = document.currentLineHeight(),
currentY = document.y,
originalOptionsY = options.y;
document.font(originalFont, originalSize * 0.5);
options.y = currentY + (currentLineHeight * 0.5);
document.text(str, options);
document.y = currentY;
options.y = originalOptionsY;
document.font(originalFont, originalSize);
from pdfkit.
A better way would be to use the OpenType features if available in the font used. Optically designed superscript and subscripts are better than scaled ones. Use {features: ['sups']}
on the text that should be superscript and {features: ['subs']}
on the text that should be subscript.
For example
doc.text('Some text', {continue: true});
doc.text('a', {features: ['sups'], continue: true});
doc.text(', some more text.', {features: []});
from pdfkit.
@moyogo Had tried that, with the font I was using it didn't appear to work. However I do agree using the OpenType features is the correct way
from pdfkit.
The OpenType approach doesn't work for me with Helvetica.
What about Unicode superscripts? They don't work either.
I have a lot of text with Unicode superscripts in it and these characters just don't get displayed.
Manually cracking up these texts is also no option.
How to add support for Unicode superscripts?
EDIT: Embedding the Liberation font was a solution to this!
from pdfkit.
I want to add a function similar to text that will substitute tags <sup> or <sub> with actual conversion of enclosed characters(s) into respective superscript or subscript.
Although I used the linkToPage function, but cannot understand much of it. I want to create something like linkToPage for this as well.
from pdfkit.
A better way would be to use the OpenType features if available in the font used. Optically designed superscript and subscripts are better than scaled ones. Use
{features: ['sups']}
on the text that should be superscript and{features: ['subs']}
on the text that should be subscript.For example
doc.text('Some text', {continue: true}); doc.text('a', {features: ['sups'], continue: true}); doc.text(', some more text.', {features: []});
It works (thank you for idea), but:
- Right syntax is
continued: true
(with d). - Only with fonts, that support "sups" OpenType feature (you can choose it from this list (https://code.thisarmy.com/fontsinfo/) or you may google if your font supports this feature).
- Chosen font must be added to the fonts directory and registered in index.js file that uses PdfKit. For example:
doc.registerFont('Ubuntu', '__dirname/fonts/Ubuntu-Regular.ttf');
- Even if your main font doesn't support "sups" OpenType feature you can additionally register font that does it and use it only for superscripted text. For example:
doc.text('Total area: ' + totalArea + ' m', {continued: true});
doc.font('Ubuntu').text('2', {features: ['sups']});
from pdfkit.
Related Issues (20)
- Transparent images will have gray edges
- Get detailed font metrics
- Encryption breaks GoTo Destinations
- how to set the orientation to landscape
- How do I use the fonts that come with my system? HOT 1
- Use Path.join() instead - Error: ENOENT: no such file or directory, open '/...//data/Helvetica.afm'
- Bullet number on version 0.15.0 not work HOT 2
- PDFKit does not create a new page on iOS Safari HOT 8
- Links on SVGs
- Is it normal for strings to be rendered slightly differently three times than once?
- Generate PDF using HTML? HOT 1
- rollup: output.interop no longer allows value `false`
- Y position of document not updated after adding image HOT 4
- Incorrect ordering of text when RTL (arabic) text mixed with LTR (english) HOT 1
- Prevent Text Overflow
- Support for other javascript runtimes (deno, cloudflare worker, bun)
- Please use lru to cache font layout to fix memory leak HOT 1
- `pageAdded` event not called for first page with `autoFirstPage: true`
- Pattern fills HOT 1
- pdfkit generates PDFs with technical errors and incorrect PDF version
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdfkit.