Comments (8)
Just in case someone finds this issue. I've used a solution shown here: https://jsfiddle.net/j9vaqpnz/10/
from jspdf-autotable.
Unfortunately there is no simple way of doing alignment and you have to manually calculate the text positions for now in the renderCell
method. In the Custom Style example I made an example of center alignment. To simplify alignments is very high on the priority list however.
from jspdf-autotable.
Ok. Thanks for the tip. 😄
from jspdf-autotable.
When I look at the Custom Style example PDF, I don't see anything centered. What I'm trying to accomplish is right aligning currency data. My initial thought was to do something like this:
// Inside renderCell
x = doc.internal.pageSize.width - width
However, it appears that width
represents cell width, not width of the actual text value. I'm having trouble finding documentation on the text object, so any suggestions would be appreciated. Thanks.
from jspdf-autotable.
I updated the advanced styling example with a right aligned currency column. It should work, however as mentioned this is harder than it should be and it will be easier to style tables in version 2.0.
// In the renderCell function
// All cells with key 'currency' will be right aligned
doc.rect(x, y, width, height, 'S');
if (key === 'currency') {
var strWidth = doc.getStringUnitWidth('' + value) * doc.internal.getFontSize();
x += width;
x -= 2 * settings.padding;
x -= strWidth;
}
y += settings.lineHeight / 2 + doc.internal.getLineHeight() / 2 - 2.5;
doc.text('' + value, x + settings.padding, y);
from jspdf-autotable.
I had just cobbled this together from using the jsPDF API, which gave me a similar result:
if (key === 'currency') {
var textWidth = doc.getTextDimensions(value);
var padding = settings.padding || 0;
var margin = settings && settings.margins ? settings.margins.horizontal : 0;
x = doc.internal.pageSize.width - textWidth.w - padding - margin;
}
However, I'll use your example since you have a lot more experience with this kind of work. 😄
Thanks so much for your help!
from jspdf-autotable.
First of, no need to check if settings values exists. If not set by the user, I set default values for them. Second, your solution would only work for the right most column, but otherwise it looks good!
Some time ago I tested getTextDimensions
versus using getStringUnitWidth
and found that getStringUnitWidth was somewhat more exact. However, none of the them are perfect unfortunately.
No worries! :)
from jspdf-autotable.
Thanks for the info.
from jspdf-autotable.
Related Issues (20)
- Memory is not deallocating for autotable. js heap is increasing eventhough for small amount of data HOT 6
- HTML Entities or HEX Code issues for symbols HOT 5
- line breaks are not working
- Change row colors on page break HOT 1
- jspdf Auto Table, can we break the if the lines are more than 10 HOT 1
- (0 , import_jspdf_autotable.default) is not a function HOT 9
- Textfield Signature?
- 表格项合并时表格项与表头信息不对应 HOT 2
- Multitable loop doesn't align properly and creates unusual gaps or overlaps each other HOT 11
- HorizontalPageBreak page break can continue on same page if vertical space is enough HOT 6
- Cannot Read html tags HOT 1
- Merge Cell Inside the body of the table HOT 1
- Parsing HTML with tables HOT 1
- Rowspan on heading HOT 1
- Inconsistent Table Width Across Pages When Exporting Using jsPDF-AutoTable HOT 4
- Table Border is off and value is not displayed when the first column is having large rowSpan. HOT 7
- Some columns are shrinked because of large texts in some columns HOT 2
- I wanted to highlight some part of text in cell text. HOT 1
- How to set specific startY even after page break HOT 1
- Autotable heading or subheading HOT 1
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 jspdf-autotable.