Giter VIP home page Giter VIP logo

Comments (10)

stretch4x4 avatar stretch4x4 commented on July 20, 2024

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.

steschi avatar steschi commented on July 20, 2024

I would be interested in this feature too.

from pdfkit.

shuaybi avatar shuaybi commented on July 20, 2024

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.

meganmcmillan avatar meganmcmillan commented on July 20, 2024

Is this a feature that will be implemented soon? We also need to add an important superscript in our pdfs.

from pdfkit.

fabiancook avatar fabiancook commented on July 20, 2024

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.

moyogo avatar moyogo commented on July 20, 2024

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.

fabiancook avatar fabiancook commented on July 20, 2024

@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.

datenstau avatar datenstau commented on July 20, 2024

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.

rohitverma1986 avatar rohitverma1986 commented on July 20, 2024

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.

ITSurgeon avatar ITSurgeon commented on July 20, 2024

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:

  1. Right syntax is continued: true (with d).
  2. 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).
  3. 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');
  4. 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.