pdfmake icon indicating copy to clipboard operation
pdfmake copied to clipboard

Align text in a table column vertically

Open jimmyting44 opened this issue 10 years ago • 135 comments

Is it possible to center some text vertically such that the text is the same distance apart from the top and bottom borders?

I'm aware of alignment : 'center' but this only works horizontally.

jimmyting44 avatar Aug 19 '14 10:08 jimmyting44

not at the moment, this would be a little bit problematic to support all boundary cases

bpampuch avatar Oct 20 '14 14:10 bpampuch

Yes. to be able to align text to the bottom border of a table cell would be useful.

TheShakyCoder avatar Jan 06 '15 18:01 TheShakyCoder

+1

silveur avatar Oct 31 '15 10:10 silveur

+1

tihomirsmudj avatar Nov 07 '15 06:11 tihomirsmudj

I've managed to do this by using html canvas to create vertical text and then importing it in as an image

// define your function for generating rotated text
writeRotatedText = function(text) {
  var ctx, canvas = document.createElement('canvas');
  // I am using predefined dimensions so either make this part of the arguments or change at will 
  canvas.width = 36;
  canvas.height = 270;
  ctx = canvas.getContext('2d');
  ctx.font = '36pt Arial';
  ctx.save();
  ctx.translate(36,270);
  ctx.rotate(-0.5*Math.PI);
  ctx.fillStyle = '#000';
  ctx.fillText(text , 0, 0);
  ctx.restore();
  return canvas.toDataURL();
};

// set the fitted width/height to a fraction for mitigating pixelation on print/zoom
var tableBody = [
 [{image: writeRotatedText('I am rotated'), fit:[7,53], alignment: 'center'}]
];

// use this body in a table definition

EDIT: Sorry guys, I thought this was about "vertically rotated text" since I was looking for that when I saw this issue. I'm leaving this reply here in case anyone still finds this useful.

serkandurusoy avatar Jan 20 '16 22:01 serkandurusoy

+1

jorgebo10 avatar Jan 30 '16 02:01 jorgebo10

The only way I could do it was by setting margin-top. i.e.: margin: [0, 20, 0, 0]

BubuInc avatar Feb 15 '16 07:02 BubuInc

+1

sirhcybe avatar Apr 22 '16 16:04 sirhcybe

+1

fguillen avatar Jun 28 '16 17:06 fguillen

+1

csvan avatar Sep 13 '16 09:09 csvan

+1

Dejab666 avatar Sep 22 '16 15:09 Dejab666

+1

mehmetalidumlu avatar Dec 22 '16 12:12 mehmetalidumlu

I think this feature is really an important one. As we really need to tweak vertical alignment in the table cell most often. Is there any recent update on this issue?

kabirbaidhya avatar Feb 28 '17 08:02 kabirbaidhya

+1

sheikirfanbasha avatar Mar 14 '17 12:03 sheikirfanbasha

+1

lerit avatar Apr 06 '17 00:04 lerit

+1

filipejoe avatar Apr 10 '17 21:04 filipejoe

+1

olgaivanysko avatar Apr 21 '17 13:04 olgaivanysko

+1

beebha avatar Jun 27 '17 17:06 beebha

+1

rdkleine avatar Jun 29 '17 09:06 rdkleine

👍

d3mi3n avatar Jun 30 '17 02:06 d3mi3n

+1

helloworld1987 avatar Jul 09 '17 12:07 helloworld1987

Im new on github, sorry for the dumb question, but the commit by sherpya fixed this issue? I tried putting verticalAlign: "center" in my code and it didnt work! :(

Daniel147 avatar Jul 21 '17 20:07 Daniel147

@Daniel147 it might but he pushed it to his own fork. When he makes a Pull Request to add it to this repro and when it gets accepted then it will.

rdkleine avatar Jul 24 '17 08:07 rdkleine

+1

elliskot avatar Aug 07 '17 11:08 elliskot

+1

Julian-Sam avatar Aug 08 '17 13:08 Julian-Sam

+1

Tonio31 avatar Aug 09 '17 13:08 Tonio31

+1

mitchdennett avatar Aug 10 '17 15:08 mitchdennett

+1

ooKriangsaKoo avatar Aug 22 '17 08:08 ooKriangsaKoo

+1

factor4 avatar Aug 29 '17 09:08 factor4

+1

leontalbot avatar Aug 30 '17 09:08 leontalbot