question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Justify text alignment using jsPDF

See original GitHub issue

Hi All,

May I just ask if the justify alignment is possible using jsPDF? Especially, when I used the split_text_to_size.js plugin.

Below is the method that I used to fit my long texts in the pdf. `function getSplitText(text, doc){ var maxLength = doc.internal.pageSize.width - 60;

var splitText = doc.splitTextToSize(text, maxLength);

return splitText;

}`

They are currently aligned LEFT.

Thank you very much!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

7reactions
Sarfarazsajjadcommented, Sep 16, 2017

@JPaulPunzalan not sure about justified text but the text can be centred by using doc.text(text,left,top,‘center’)

    var lMargin=15; //left margin in mm
    var rMargin=15; //right margin in mm
    var pdfInMM=210;  // width of A4 in mm
    var pageCenter=pdfInMM/2;
    
    var doc = new jsPDF("p","mm","a4");
    var paragraph="Apple's iPhone 7 is officially upon us. After a week of pre-orders, the latest in the iPhone lineup officially launches today.\n\nEager Apple fans will be lining up out the door at Apple and carrier stores around the country to grab up the iPhone 7 and iPhone 7 Plus, while Android owners look on bemusedly.\n\nDuring the Apple Event last week, the tech giant revealed a number of big, positive changes coming to the iPhone 7. It's thinner. The camera is better. And, perhaps best of all, the iPhone 7 is finally water resistant.\n\nStill, while there may be plenty to like about the new iPhone, there's plenty more that's left us disappointed. Enough, at least, to make smartphone shoppers consider waiting until 2017, when Apple is reportedly going to let loose on all cylinders with an all-glass chassis design.";
		
    var lines =doc.splitTextToSize(paragraph, (pdfInMM-lMargin-rMargin));
    doc.text(lines,pageCenter,20,'center'); //see this line
    doc.save('Generated.pdf');
    }
2reactions
Uzlopakcommented, May 23, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

jsPDF justify text - javascript - Stack Overflow
In jspdf. js (L:1413) I have added this code: if (align) { ... else if (align === 'justify') { left = x; }...
Read more >
Justify text alignment using jsPDF · Issue #1245 - GitHub
Hi All, May I just ask if the justify alignment is possible using jsPDF? Especially, when I used the split_text_to_size.js plugin.
Read more >
How to align text in center using jspdf? - Coders Diaries
I am using jsPDF for my project where have to create a PDF from user submitted data. I want to align text in...
Read more >
change font face, fontsize, text align and rotated text in jspdf
Learn how to change font face, fontsize, text align and rotated text in jspdf.Gears List:Apple AirPods Pro: https://amzn.to/3QYEKtjFire TV ...
Read more >
how to align text in center using jspdf
Using a style sheet property. You can center text with CSS by specifying the text-align property of the element to be centered.. Centering...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found