Ber*_*los 11 rotation cell itext paragraph
我有一个网站,用户上传照片和创建相册.此外,他们可以在绝对位置,旋转和对齐方式添加文本.文本可以有新行.
我一直在使用Itext Library来自动创建后来打印的Photobooks高质量Pdfs.
将用户上传的图像添加到PDF非常简单,当我尝试添加文本时出现问题.
理论上我需要做的是定义一个定义宽度和高度的段落,设置用户文本,字体,字体样式,对齐(中心,左,右,对齐),最后设置旋转.
对于我读过的关于Itext的内容,我可以创建一个设置用户属性的段落,并使用ColumnText对象来设置绝对位置,宽度和高度.但是,不可能将任何大于单线的旋转设置为旋转.
我也不能使用表格单元格,因为旋转方法只允许90度的倍数.
有没有办法添加一个旋转(如20度)的段落,而不必使用该ColumnText.showTextAligned()
方法逐行添加文本和涉及的所有数学?
----编辑:08-Ago-2013 ----
如果它可以帮助任何人,这是我用来解决这个问题的代码(感谢Bruno):
//Create the template that will contain the text
PdfContentByte canvas = pdfWriter.getDirectContent();
PdfTemplate textTemplate = canvas.createTemplate(imgWidth, imgHeight); //The width and height of the text to be inserted
ColumnText columnText = new ColumnText(textTemplate);
columnText.setSimpleColumn(0, 0, imgWidth, imgHeight);
columnText.addElement(paragraph);
columnText.go();
//Create de image wraper for the template
Image textImg = Image.getInstance(textTemplate);
//Asign the dimentions of the image, in this case, the text
textImg.setInterpolation(true);
textImg.scaleAbsolute(imgWidth, imgHeight);
textImg.setRotationDegrees((float) -textComp.getRotation()); //Arbitrary number of degress
textImg.setAbsolutePosition(imgXPos, imgYPos);
//Add the text to the pdf
pdfDocument.add(textImg);
Run Code Online (Sandbox Code Playgroud)
Bru*_*gie 10
PdfTemplate
对象; 只是一个矩形.ColumnText
这个PdfTemplate
; 不要担心旋转,只需用要添加到列的任何内容填充矩形.PdfTemplate
内部包裹起来Image
; 这只是为了方便,避免数学.这并不意味着您的文本将被栅格化.Image
并将其添加到文档中.你的问题现在解决了;-)
PS:我是iText in Action书籍的作者.
归档时间: |
|
查看次数: |
2919 次 |
最近记录: |