【问题标题】:Wrong paragraph order in PDF by iTextSharpiTextSharp 在 PDF 中的段落顺序错误
【发布时间】:2011-04-20 04:48:33
【问题描述】:

我正在尝试使用 iTextSharp 生成 PDF。
它将由许多图像组成,每个图像前面都有一个标题。但是当我生成 PDF 时,不会保留元素的顺序 - 多个标题被组合在一起等。

我将标题和图像包装在一个段落中,如下所示:

' Create paragraph and heading
Dim paragraph As New iTextSharp.text.Paragraph()
Dim heading As New iTextSharp.text.Chunk("Image title" & vbNewLine, pdfHeadingFont)

' Create image from Chart
Dim image = GetPdfImage(Me.chtMain)
Dim width = iTextSharp.text.PageSize.A4.Width - pdfDocument.LeftMargin - pdfDocument.RightMargin
Dim height = iTextSharp.text.PageSize.A4.Height - pdfDocument.TopMargin - pdfDocument.BottomMargin
image.Alignment = image.ALIGN_CENTER Or image.TEXTWRAP
image.ScaleToFit(width, height)

' Add heading and image to paragraph
paragraph.Add(heading)
paragraph.Add(image)

' Add paragraph to document
pdfDocument.Add(paragraph)

为什么图像和标题没有放在 PDF 中?我可以用其他方式吗?

谢谢,

马丁

【问题讨论】:

    标签: image pdf itextsharp


    【解决方案1】:

    想通了,感谢this question

    显然,设置 PdfWriter.StrictImageSequence = true 可以解决此问题。
    iTextSharp 通过尝试在每一页上放置尽可能多的段落来“优化”您的文档 - 无论顺序如何。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-29
      • 2012-12-21
      • 2015-06-13
      • 2011-07-01
      • 2015-04-04
      • 1970-01-01
      • 1970-01-01
      • 2020-03-11
      相关资源
      最近更新 更多