自动换行生成的PDF(使用jsPDF)? [英] Word wrap in generated PDF (using jsPDF)?

查看:311
本文介绍了自动换行生成的PDF(使用jsPDF)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做的是使用jsPDF创建我生成的图形的PDF.但是,我不确定如何包装标题(通过使用text()函数添加).标题的长度将因图形而异.目前,我的标题不在页面上.任何帮助将不胜感激!

what I'm doing is using jsPDF to create a PDF of the graph I generated. However, I am not sure how to wrap the title (added by using the text() function). The length of the title will vary from graph to graph. Currently, my titles are running off the page. Any help would be appreciated!

这是我到目前为止的代码:

This is the code i have so far:

var doc = new jsPDF();
doc.setFontSize(18);
doc.text(15, 15, reportTitle);
doc.addImage(outputURL, 'JPEG', 15, 40, 180, 100);
doc.save(reportTitle);

没有什么可以阻止reportTitle在页面上运行

Nothing to keep the reportTitle from running off the page

推荐答案

好的,我已经解决了这个问题.我使用了jsPDF函数splitTextToSize(text,maxlen,options).该函数返回一个字符串数组.幸运的是,用于写入文档的jsPDF text()函数可以接受字符串和字符串数组.

Okay I've solved this. I used the jsPDF function, splitTextToSize(text, maxlen, options). This function returns an array of strings. Fortunately, the jsPDF text() function, which is used to write to the document, accepts both strings and arrays of strings.

var splitTitle = doc.splitTextToSize(reportTitle, 180);
doc.text(15, 20, splitTitle);

这篇关于自动换行生成的PDF(使用jsPDF)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆