【问题标题】:iText Irregular Columns Images and Text WrapiText 不规则列图像和文本换行
【发布时间】:2015-12-13 07:13:15
【问题描述】:

我正在使用 iTextSharp 生成 PDF,而另一个部门坚持让我制作的 PDF 尽可能匹配他们的模型。我遇到了将文本环绕在列中的图像周围的问题。我从我的研究中知道,将图像放在带有文本的 PDFCell 中是行不通的,所以我试图使用不规则的列。下面是我的示例代码。

float width = 200.0f;
float height = 320.0f;
float gutter = 3;
PdfTemplate tempCanvas = writer.DirectContent.CreateTemplate(width, height);
float x1 = underPressure.ScaledWidth + gutter;
float y1 = height - underPressure.ScaledHeight - gutter;
float[] LEFT = new float[] { width, height, x1, y1, 0, y1, 0, 0 };
float[] RIGHT = new float[] {0,height,width,0};

ColumnText ct = new ColumnText(tempCanvas);
ct.SetColumns(LEFT, RIGHT);
underPressure.SetAbsolutePosition(x1 - 10, y1 - 120);
tempCanvas.AddImage(underPressure);
ct.SetText(tempPhrase);
...

我找到了将图像放在文本左侧的代码,并根据图像获取要换行的文本,但我需要如下所示的内容:

http://i.stack.imgur.com/xx4KU.png

我必须承认,我对 LEFT 和 RIGHT 列属性感到很困惑。从书中,LEFT 和 RIGHT 数组定义了您尝试创建的多边形的边界,但是有人可以更详细地描述它是如何工作的吗?我一直试图绕过它并且惨遭失败。提前感谢您的任何建议。

【问题讨论】:

    标签: c# itext word-wrap


    【解决方案1】:

    所以我终于想通了,我想我会在这里发帖。我不得不重读 iText 书几次才能弄清楚这一点,但 LEFT 和 RIGHT 数组只是您要为要绘制的多边形指定的点以制作列。

    //创建不规则列,必须以左侧坐标和右侧坐标的形式指定要绘制的多边形的点。

    //Because we only need a straight line for the left side of the shape of the column, we can specify two points: the top coordinate, and the bottom coordinate.
    //The right is a little trickier, but using Math, you can create the points you need the scaled width and scaled height of the image.
    float[] LEFT = new float[] { 0,height, 0,0 };
    float[] RIGHT = new float[] {width,height,  width,y1 + 40,  width - x1 - 5,y1 + 40,  width - x1 - 5,y1 - underPressure.ScaledHeight / 2.0f + 10,  width, y1 - underPressure.ScaledHeight / 2.0f + 10, width, 0 };
    

    给我我需要的结果。 LEFT 只是形状的顶部、左上角和形状的左下角。我只需要一条直线作为左边缘。 RIGHT 数组有点棘手,但它是我需要的形状,可以用数学计算出来。

    是的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-04
      • 2015-07-11
      • 2012-09-22
      • 1970-01-01
      • 2011-04-23
      • 2016-11-19
      相关资源
      最近更新 更多