我的照片是在第2页中创建的,但之后创建的段落是在插入之后(第1页)

问题描述 投票:0回答:2

我正在使用itextsharp(itext),我正在设置这样的图片:

img = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Areas/ActionPlan/uploads/") + doc.path);
float width = (document.PageSize.Width / 100 * 88) / 2;  // half width of the page
float height = width / img.Width * img.Height;
img.ScaleAbsoluteWidth(width);
img.ScaleAbsoluteHeight(height);
document.Add(img);

和文字一样:

document.Add(new Chunk(Environment.NewLine));
document.Add(new Paragraph("Document : " + doc.path, times));

这是我的应用程序的应用程序序列:

  1. 占用页面高度80%的段落
  2. 图片(有时它适合第1页,有时第2页)
  3. 一行文字

如果图片高于页面的其余部分,这是PDF结果:

  1. 一行文字
  2. 图片

在任何情况下,我想要图片后面的图片名称。我是怎么解决的?

非常感谢

image itext
2个回答
2
投票

调用writer.StrictImageSequence = true以确保文本和图像以相同的顺序打印。

有关https://developers.itextpdf.com/question/why-arent-images-added-sequentially的更多信息。


0
投票

最后,我检查图像高度和剩余空间。如果没有剩余空间,我会创建一个分页符。

img = Image.GetInstance(Server.MapPath("~/Areas/Audit/uploads/") + item.link);
float width = (document.PageSize.Width / 100 * 88) / 2;  // resize picture to half width of the page
float height = width / img.Width * img.Height;
img.ScaleAbsoluteWidth(width);
img.ScaleAbsoluteHeight(height);

if ((pdfWriter.GetVerticalPosition(false) - document.BottomMargin) < height)
    {
        document.NewPage();
    }
document.Add(img);
© www.soinside.com 2019 - 2024. All rights reserved.