使用 PDPageContentStream.drawLine 时出现 pdfbox 错误

发布于 2024-10-08 23:05:04 字数 609 浏览 0 评论 0原文

我正在使用 PDFBox 从用户输入的表单之一生成 pdf。为了绘制一条线,我使用 PDPageContentStream.drawLine 并使用 PDPageContentStream.drawString 绘制文本。文本工作完美,但在使用 drawLine 时,当我尝试打印 pdf 时,出现错误,如附图所示。我的代码看起来像这样

PDPage page = new PDPage();
release.addPage(page);
contentStream = new PDPageContentStream(release,page);
int margin = 40;
vertHeight -= thisFontHeight * fontSize * 1.05f + 5;

contentStream.drawLine(margin,vertHeight + margin - 5,                                     page.getMediaBox().getWidth() - margin, vertHeight + margin - 5)

任何帮助表示赞赏alt text

I am using PDFBox for generating a pdf from one of my user inputted forms. For drawing a line I am using PDPageContentStream.drawLine and for text PDPageContentStream.drawString. The text works perfect but while using drawLine, when I try to print the pdf, I get the error as shown in the attached Image. My code looks like this

PDPage page = new PDPage();
release.addPage(page);
contentStream = new PDPageContentStream(release,page);
int margin = 40;
vertHeight -= thisFontHeight * fontSize * 1.05f + 5;

contentStream.drawLine(margin,vertHeight + margin - 5,                                     page.getMediaBox().getWidth() - margin, vertHeight + margin - 5)

Any help appreciatedalt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说谎友 2024-10-15 23:05:04

您的代码示例没有显示它,但我怀疑您正在混合线条和文本。不得在 BT 和 ET 之间画线。

  1. 开始文本
  2. 绘制一些文本
  3. 结束文本
  4. 绘制一条线
  5. 开始文本
  6. 绘制一些文本
  7. 结束文本
  8. 绘制更多线
  9. 等等

例如,如果您在 1 和 3 之间绘制一条线,您将收到上述错误(或类似错误)。

PS:如果不是这样,我们需要一个示例 PDF 来诊断问题。

Your code sample doesn't show it, but I suspect you're mixing lines and text. You must not draw lines between BT and ET.

  1. begin Text
  2. draw some text
  3. end text
  4. draw a line
  5. begin text
  6. draw some text
  7. end text
  8. draw some more lines
  9. etc

If you drew a line between 1 and 3, for example, you'd get the above error (or one similar to it).

PS: If that's not it, we'll need a sample PDF to diagnose the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文