我正在努力做某事
像:这样(在同一行上具有粗体和普通文本)。
我一直在使用流:
创建粗体(或其他样式)文本的首选方法是使用
已为该变体显式创建的字体变体。
但是,如果没有这样的字体,则可以人工模拟这些
样式:
- 人工加粗:使用文本呈现模式2不仅填充字母区域,而且沿其轮廓画一条线
- 人工勾勒轮廓:使用文本呈现模式1沿字母轮廓绘制一条线,而不是填充它
人工斜体(实际上是倾斜的:更改文本矩阵以使输出倾斜。
在代码中:PDRectangle rec = new PDRectangle(220, 120);
PDdocument document = null;
document = new PDdocument();PDPage page = new PDPage(rec);
document.addPage(page);PDPageContentStream content = new PDPageContentStream(document, page, true, true);
content.beginText();
content.moveTextPositionByAmount(7, 105);
content.setFont(PDType1Font.HELVETICA, 12);
content.drawString(“Normal text and “);
content.setFont(PDType1Font.HELVETICA_BOLD, 12);
content.drawString(“bold text”);
content.moveTextPositionByAmount(0, -25);
content.setFont(PDType1Font.HELVETICA_OBLIQUE, 12);
content.drawString(“Italic text and “);
content.setFont(PDType1Font.HELVETICA_BOLD_OBLIQUE, 12);
content.drawString(“bold italic text”);
content.endText();content.setLineWidth(.5f);
content.beginText();
content.moveTextPositionByAmount(7, 55);
content.setFont(PDType1Font.HELVETICA, 12);
content.drawString(“Normal text and “);
content.appendRawCommands(“2 Trn”);
content.drawString(“artificially bold text”);
content.appendRawCommands(“0 Trn”);
content.moveTextPositionByAmount(0, -25);
content.appendRawCommands(“1 Trn”);
content.drawString(“Artificially outlined text”);
content.appendRawCommands(“0 Trn”);
content.setTextMatrix(1, 0, .2f, 1, 7, 5);
content.drawString(“Artificially italic text and “);
content.appendRawCommands(“2 Trn”);
content.drawString(“bold italic text”);
content.appendRawCommands(“0 Trn”);
content.endText();content.close();
document.save(“StyledTexts.pdf”);
document.close();



