内容流通过我想在矩形中显示“连接我们”文本。
contentStream.beginText();
contentStream.setFont(PDType1Font.TIMES_ROMAN, 10);
contentStream.newLineAtOffset(260, 240);
contentStream.showText("Connect with Us:");
contentStream.endText();
contentStream.setNonStrokingColor(235,235,235);
contentStream.addRect(50, 200, 500, 100);
contentStream.fill();
Run Code Online (Sandbox Code Playgroud)
我尝试使用此代码获取矩形中的文本,但没有在矩形中看到文本。
你首先绘制文字
contentStream.beginText();
contentStream.setFont(PDType1Font.TIMES_ROMAN, 10);
contentStream.newLineAtOffset(260, 240);
contentStream.showText("Connect with Us:");
contentStream.endText();
Run Code Online (Sandbox Code Playgroud)
然后填充矩形...
contentStream.setNonStrokingColor(235,235,235);
contentStream.addRect(50, 200, 500, 100);
contentStream.fill();
Run Code Online (Sandbox Code Playgroud)
嗯,会发生什么?你的矩形覆盖了文本!
要解决此问题,只需以相反的方式进行即可,先绘制矩形,重置非描边颜色,然后在其上书写。
contentStream.setNonStrokingColor(235,235,235);
contentStream.addRect(50, 200, 500, 100);
contentStream.fill();
contentStream.setNonStrokingColor(0,0,0);
contentStream.beginText();
contentStream.setFont(PDType1Font.TIMES_ROMAN, 10);
contentStream.newLineAtOffset(260, 240);
contentStream.showText("Connect with Us:");
contentStream.endText();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2126 次 |
| 最近记录: |