我有一個網站,用戶上傳照片和創建相冊。而且,他們可以在絕對位置,旋轉和對齊中添加文本。文本可以有新的行。旋轉段落或單元格一些任意度 - Itext
我一直在使用Itext庫自動化後期印刷的Photobooks高質量PDF的創建。
將用戶上傳的圖像添加到PDF中非常簡單,當我嘗試添加文本時出現問題。
從理論上講,我需要做的是定義一些定義寬度和高度的段落,設置用戶文本,字體,字體樣式,對齊方式(居中,左右,對齊),最後設置迴轉。
對於我讀過的Itext,我可以創建一個設置用戶屬性的段落,並使用ColumnText對象設置絕對位置,寬度和高度。但是,不可能設置大於單行的任何東西的旋轉。
我不能使用表格單元格要麼,因爲旋轉法只允許是90
倍數度是否有辦法增加一個段落與一些旋轉(例如20度),而無需添加一行一行地使用ColumnText.showTextAligned()
方法和所有涉及到的數學方法?
----編輯:2008年以前,2013 ----
如果有幫助的人,這是我用來解決這個問題的代碼(感謝布魯諾):
//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);
編輯與我使用的代碼的問題。 – BernalCarlos 2013-08-08 15:03:19