2017-04-07 59 views
1

我試圖放大PDF粘滯便箋的圖標。下面是表明我對PDF的第一頁上的蓋章上下文粘圖標的圖像:如何更改通過iTextSharp放置的PDF便籤的圖標大小?

enter image description here

我的印象圖標被可能被操縱的矩形引導。這裏是我的代碼沒有得到有效尚未:

using (PdfStamper stamp = new PdfStamper(reader, fs)) 
{ 
    PdfWriter attachment = stamp.Writer; 
    foreach (string file in files_to_attach) 
    { 
     PdfFileSpecification pdfAttch = PdfFileSpecification.FileEmbedded(attachment, file, file, null); 
     stamp.AddFileAttachment(file, pdfAttch); 
    } 

    //Create Note for first page 
    Rectangle rect = new Rectangle(850, 850, 650, 650); 
    PdfAnnotation annotation = PdfAnnotation.CreateText(stamp.Writer, rect, "TITLE OF NOTE", "Body text of the note", false, "Comment"); 

    //Enlarge the Sticky Note icon 
    PdfDictionary page = reader.GetPageN(1); 
    PdfArray annots = page.GetAsArray(PdfName.ANNOTS); 
    PdfDictionary sticky = annots.GetAsDict(0); 
    PdfArray stickyRect = sticky.GetAsArray(PdfName.RECT); 
    PdfRectangle stickyRectangle = new PdfRectangle(
     stickyRect.GetAsNumber(0).FloatValue - 50, stickyRect.GetAsNumber(1).FloatValue - 20, 
     stickyRect.GetAsNumber(2).FloatValue, stickyRect.GetAsNumber(3).FloatValue - 30); 
    sticky.Put(PdfName.RECT, stickyRectangle); 

    //Apply the Note to the first page 
    stamp.AddAnnotation(annotation, 1); 

    stamp.Close(); 
} 

我想我可以改變浮點值,並且將改變圖標的​​形狀,但到目前爲止還沒有實現這一切。謝謝你的任何建議。

回答

1

你不能。爲「註釋」註釋顯示的圖標由查看器提供。 rect屬性僅用於定義查看器在圖標放置在頁面的左下角。根據類型爲「文本」的註釋的PDF規範,「符合標準的讀者應至少爲以下標準名稱提供預定義的圖標外觀:註釋,註釋,註釋,幫助,新段落,段落,插入。

您可以然而,創建自己的任意大小的圖像,並將其用作「圖章」註釋的外觀,它甚至可以看起來像一個「評論」圖標,只是更大一些,它最終會以同樣的方式運行最終用戶

+0

因此,爲了讓它「以同樣的方式向最終用戶使用」,它仍然需要表示爲註釋,對嗎?如: PdfAnnotation annotation = PdfAnnotation.CreateText(stamp。作家,rect,「標題筆記」,「筆記正文」,假,「評論」); 但不是「評論」,我會通過一個圖像。 「評論」是一個字符串,什麼語法允許圖像成爲一個字符串? – DBlair

+1

請參閱Bruno的AddStamp示例。這是Java,但你會明白。 http://developers.itextpdf.com/examples/actions-and-annotations/clone-creating-and-adding-annotations#2260-addstamp.java – joelgeraci

相關問題