所以我的問題是,究竟怎樣的setRotateContent()的作品
由於有點背景的,你需要知道每個PDF頁面包含一個屬性旋轉被指定爲「的顯示或打印時頁面順時針旋轉的度數,其值應爲90的倍數。默認值:0。
如果你想添加一些具有非平凡旋轉值(即360倍數)的網頁,因此,有兩種不同的情況:
- 要麼你想無論頁面最終如何旋轉,在頁面座標系統的某個位置和方向上添加一些東西,或者您想在相對於頁面顯示方式的位置添加內容。
前者是微不足道的,只需要使用指定的座標和方向,後者要求您閱讀旋轉值,並將其計入你的座標和角度。
iText在這裏試圖幫助你,併爲setRotateContent(true)
,首先添加一個變換overcontent和undercontent,讓您只需繼續選擇座標和角度,就好像沒有頁面旋轉涉及。
看起來後一種情況已經被認爲比前者更頻繁地發生。因此,默認RotateContent
值是true
。因此,在前一種情況下,您實際上必須使用setRotateContent(false)
將其關閉。
由於問題是如何工作的準確:這是執行以初始化undercontent和overcontent ByteBuffer
表示的方法:
void applyRotation(PdfDictionary pageN, ByteBuffer out) {
if (!rotateContents)
return;
Rectangle page = reader.getPageSizeWithRotation(pageN);
int rotation = page.getRotation();
switch (rotation) {
case 90:
out.append(PdfContents.ROTATE90);
out.append(page.getTop());
out.append(' ').append('0').append(PdfContents.ROTATEFINAL);
break;
case 180:
out.append(PdfContents.ROTATE180);
out.append(page.getRight());
out.append(' ');
out.append(page.getTop());
out.append(PdfContents.ROTATEFINAL);
break;
case 270:
out.append(PdfContents.ROTATE270);
out.append('0').append(' ');
out.append(page.getRight());
out.append(PdfContents.ROTATEFINAL);
break;
}
}
(PdfStamperImp
)
與
static final byte ROTATE90[] = DocWriter.getISOBytes("0 1 -1 0 ");
static final byte ROTATE180[] = DocWriter.getISOBytes("-1 0 0 -1 ");
static final byte ROTATE270[] = DocWriter.getISOBytes("0 -1 1 0 ");
static final byte ROTATEFINAL[] = DocWriter.getISOBytes(" cm\n");
(PdfContents
)
PS:雖然RotateContent
屬性控制這些轉換是否被添加到該overcontent和undercontent與否,存在一種用於註釋類似的機制不能由被禁用該屬性,比照。 this answer。
來源
2017-01-23 10:54:32
mkl
您可以添加簡碼的代碼嗎?開始一個新項目,只添加足夠的代碼來顯示你在做什麼和看到什麼。這應該讓你圍繞你的限制,因爲否則你將不被允許在Stack Overflow上發佈問題...... –