2013-05-04 38 views
0

我希望把使用我的PDF文檔zapfdingbatslistiTextSharp的複選標記在特定位置在PDF文檔中的zapfdingbatslist。如何在特定的位置寫使用iTextSharp的

我到目前爲止所能做的是我可以顯示覆選標記,但它全部位於文檔的一側,而不是我想要的特定X,Y座標。我在下面有一個代碼,希望能夠讓你知道我在說什麼。

String outputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf"); 
    System.IO.FileStream fs; 
    Document doc = new Document(PageSize.A4, 20, 20, 10, 10); 
    PdfContentByte cb; 
    PdfWriter writer; 

    fs = new System.IO.FileStream(outputFile, System.IO.FileMode.Create); 
    writer = PdfWriter.GetInstance(doc, fs); 
    doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); 
    writer.AddViewerPreference(PdfName.PICKTRAYBYPDFSIZE, PdfBoolean.PDFTRUE); 

    doc.Open(); 
    cb = writer.DirectContent; 

    List myList = new ZapfDingbatsList(52); // Check mark symbol from Dingbatslist 

    // I have some more code here but it is not needed for the problem 
    // and thererfore not shown 


    // I could shohw the dingbatslist check mark here 
    myList.Add(" "); 
    doc.Add(myList); // However I want to show it in a specific X, Y position 

    doc.Close(); 
    writer.Close(); 
    fs.Close(); 

任何想法?

回答

3

順便說一句,我的大部分iText documentation的作者(以及iText的原開發商,包括DocumentPdfWriterZapfdingbatsList,...班),我會很感激,如果你花了一些有時間閱讀iText文檔。

讓我們從chapter 2開始,看看some C# examples,它介紹了Font類。

例如:

Font font = new Font(Font.FontFamily.ZAPFDINGBATS, 12); 

一旦你有一個Font對象,你可以創建一個Phrase(第2章還解釋):

Phrase phrase = new Phrase(zapfstring, font); 

哪裏zapfstring是含有任何ZAPFDINGBATS字符string你要。

對於在絕對位置添加這句話,你需要閱讀第3章看一看the examples靈感,比如FoobarFilmfestival.cs

PdfContentByte canvas = writer.DirectContent; 
ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, phrase, 200, 500, 0); 

200500是X和Y座標和0是用度表示的角度。代替ALIGN_CENTER,您也可以選擇ALIGN_RIGHTALIGN_LEFT

在您的代碼示例中,您正在使用列表向文檔添加Zapfdingbats字形。請花一點時間讓自己置身於我的位置。難道你不覺得你是出席紅辣椒音樂會的襪子的發明者嗎?

+0

這就是我在這裏所喜愛的,因此你可以撿到許多聰明的頭腦。有多少人會直接從質量書的作者那裏得到答案?我猜不是太多。謝謝Mr @BrunoLowagie我非常感謝你的正確迴應/解決方案。上帝保佑。 – Edper 2013-05-04 10:29:15

+1

我工作的一部分是回答問題,但在SO上很有趣;-) – 2013-05-04 16:18:42

相關問題