0

I am trying to export multiple highcharts to a PDF with a title in the top center of the PDF.

I am able to export my charts with the title in the top left of the PDF. How do I style my text so that it is in the center of the PDF?

Here is my code: https://jsfiddle.net/jethanger/1ey0fox6/2/

I have tried to increase the text x position to center the text but that has not worked. the Text still prints at the left edge of the PDF.

 title= 'Daily Log  ';

  txt = '<text x= "' + 5000 + '" y = "' + (top) + '"><tspan x="0" dy="1.2em">'  + title +'</br>' + ' at '  + '</tspan></text>';
  if(i==0){

  top +=  100
  svgArr.push(txt);

  }
jethanger
  • 3
  • 4

1 Answers1

0

It can be done using transform="translate(500, 30)" attribute:

title = 'Daily Log  ';
value = $(txt).val().replace(/\n/g, '</tspan><tspan x="0" dy="1.2em">');

numberOfLines = $(txt).val().split("\n").length;
txt = '<text transform="translate(' + 560 + ', ' + 30 + ')"><tspan x="0" dy="1.2em">' + title + '</br>' + ' at ' + '</tspan></text>';
if (i == 0) {

  top += 100
  svgArr.push(txt);

}
i += 1;

Demo:

Wojciech Chmiel
  • 7,302
  • 1
  • 7
  • 16
  • thank you @Wojciech Chmiel ! This is exactly what i needed. Do you know how to add an image to a PDF in this manner? – jethanger Jul 31 '19 at 21:03
  • If this answer was helpful for you, please mark it as a correct one and upvote, thanks. To add images you can check solutions mentioned in these threads: https://www.highcharts.com/forum/viewtopic.php?f=9&t=40947, example: http://jsfiddle.net/wchmiel/6ns8v3ru/. Or use a separate library (like jspdf) to build more sophisticated pdfs, see: https://stackoverflow.com/questions/54761784/highcharts-export-multiple-charts-using-jspdf/54768981#54768981. – Wojciech Chmiel Aug 01 '19 at 07:16
  • Thank you again @Wojciech Chmiel and my apologies for not immediately marking your answer as a correct one. Could you also point me to a guide for adding tables to PDF in addition to the charts and images? – jethanger Aug 01 '19 at 20:37
  • Yes, sure. Check this thread: https://stackoverflow.com/questions/56200659/generate-export-tablegraph-in-highcharts-in-pdf-format – Wojciech Chmiel Aug 05 '19 at 05:16