相关疑难解决方法(0)

旋转段落或单元格任意数度 - Itext

我有一个网站,用户上传照片和创建相册.此外,他们可以在绝对位置,旋转和对齐方式添加文本.文本可以有新行.

我一直在使用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 …
Run Code Online (Sandbox Code Playgroud)

rotation cell itext paragraph

11
推荐指数
1
解决办法
2919
查看次数

如何使用itextsharp在PdfContentByte矩形中添加文本?

我用PdfContentByte创建了矩形.现在我想在这个矩形中添加一个文本.我怎样才能做到这一点.如果有人有想法请与我分享.我的矩形代码是

 Document doc = new Document(new Rectangle(570, 924f));
 PdfWriter writer = PdfWriter.GetInstance(doc,Response.OutputStream);
 PdfContentByte cb = writer.DirectContent;
 cb.Rectangle(doc.PageSize.Width -90f, 830f, 50f,50f);
 cb.Stroke();
Run Code Online (Sandbox Code Playgroud)

c# asp.net itextsharp

5
推荐指数
1
解决办法
2万
查看次数

使用itext中心旋转文本

我正在转换使用在线编辑器创建的文档.我需要能够使用它的中心点旋转文本,而不是(0,0).

由于Image使用中心旋转,我认为这可以工作,但事实并非如此.任何人都知道如何使用itext中的中心点旋转文本?

float fw = bf.getWidthPoint(text, textSize);
float fh = bf.getAscentPoint(text, textSize) - bf.getDescentPoint(text, textSize); 
PdfTemplate template = content.createTemplate(fw, fh);

Rectangle r = new Rectangle(0,0,fw, fw);
r.setBackgroundColor(BaseColor.YELLOW);
template.rectangle(r);

template.setFontAndSize(bf, 12);
template.beginText();
template.moveText(0, 0);
template.showText(text);
template.endText();

Image tmpImage = Image.getInstance(template);
tmpImage.setAbsolutePosition(Utilities.millimetersToPoints(x), Utilities.millimetersToPoints(pageHeight-(y+Utilities.pointsToMillimeters(fh))));
tmpImage.setRotationDegrees(0);
document.add(tmpImage);
Run Code Online (Sandbox Code Playgroud)

rotation itext

2
推荐指数
1
解决办法
5820
查看次数

标签 统计

itext ×2

rotation ×2

asp.net ×1

c# ×1

cell ×1

itextsharp ×1

paragraph ×1