我一直在使用reportlab pdfgen 来创建用于打印的动态pdf 文档。多年来,它一直运行良好。
我们即将举行筹款活动,并希望使用我们正在使用的“主题”字体(特别是 talldeco.ttf)生成 pdf 收据。
我使用以下方法设置字体没问题:
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
ttfFile = "/usr/share/fonts/truetype/ttf-tall-deco/TALLDECO.TTF"
pdfmetrics.registerFont(TTFont("TallDeco", ttfFile))
p.setFont("TallDeco", 18) # Was Times-Bold...
Run Code Online (Sandbox Code Playgroud)
现在问题来了:一些文本需要加粗和斜体,而高装饰只带有 1 个文件(与其他一些字体不同)。我可以在 openoffice 中将此字体的文本加粗和斜体。
根据 reportlab 用户指南 (http://www.reportlab.com/software/opensource/rl-toolkit/guide/) 第 53 页,这应该是可能的,它们显示了一些代码和结果,但我们的软件正在使用 drawString 调用而不是段落。基于上述示例的测试应用程序:
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase.pdfmetrics import registerFontFamily
ttfFile = "/usr/share/fonts/truetype/ttf-tall-deco/TALLDECO.TTF"
pdfmetrics.registerFont(TTFont("TallDeco", ttfFile))
registerFontFamily('TallDeco',normal='TallDeco',bold='TallDeco-Bold',italic='TallDeco-Italic',boldItalic='TallDeco-BoldItalic')
p.setFont("TallDeco-Bold", 18) # Was Times-Bold...
Run Code Online (Sandbox Code Playgroud)
只是在“TallDeco-Bold”上给出一个关键错误。
有什么建议?
我是node.js的新手,并且正在玩一些教程并偶然发现这个问题进行了一些重构.
我关注的教程链接在这里:http: //www.tutorialspoint.com/nodejs/nodejs_web_module.htm
我决定拆分回调以使代码更具可读性,因此创建了一个文件读取器方法和一个'monitor'方法:
function monitor(request, response)
{
var pathname = url.parse(request.url).pathname;
fs.readFile(pathname.substr(1), reader() );
}
http.createServer(monitor()).listen(8080);
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我收到以下错误:
var pathname = url.parse(request.url).pathname;
^
TypeError: Cannot read property 'url' of undefined
at monitor
Run Code Online (Sandbox Code Playgroud)
显然这是一个类型问题.我正在考虑转换为http.incomingMessage,但我对javascript不够熟悉,我的网络搜索没有产生快速解决方案.
谢谢!