Open devongovett opened 13 years ago
I would be interested in this feature too.
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?
Is this a feature that will be implemented soon? We also need to add an important superscript in our pdfs.
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);
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: []});
@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
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!
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.
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:
continued: true
(with d). doc.registerFont('Ubuntu', '__dirname/fonts/Ubuntu-Regular.ttf');
doc.text('Total area: ' + totalArea + ' m', {continued: true});
doc.font('Ubuntu').text('2', {features: ['sups']});
Is there any update on this superscript/subscript feature?
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.