2016-01-06 9 views
0

我正在使用C#和ITextSharp。 我需要基於鍵/值字典生成PDF文檔。帶AcroFields的pdf上的富文本框ITextSharp

一切工作,除了從富文本框中的值。

這裏是我的代碼:

Output.AcroFields.GenerateAppearances = false; 
Output.AcroFields.SetFieldRichValue(key, value); 

我嘗試不同的值(這裏有一個例子)

<p><em>No rece</em>nt c<s>hanges in marital st</s>atus or dependen<strong>ts test</strong></p> 

<p>&nbsp;</p> 

<h2><s><em><strong>Hello !</strong></em></s></h2> 

而且,只有一個空場在我的PDF顯示...

任何想法爲什麼?

+0

richText設置的字段的richValue實際上是一個span對象的數組(請參閱Acrobat JavaScript文檔)。 –

回答

1

在PDF規範的例子richt文本字符串看起來像一個更完整的XML:

<?xml version="1.0"?> 
<body xmlns="http://www.w3.org/1999/xtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:contentType="text/html" xfa:APIVersion="Acrobat:8.0.0" xfa:spec="2.4"> 
    <p style="text-align:left"> 
    <b> 
     <i> 
     Here is some bold italic text 
     </i> 
    </b> 
    </p> 
    <p style= "font-size:16pt"> 
    This text uses default text state parameters but changes the font size to 16. 
    </p> 
</body> 

(第12.7.3.4富文本字符串ISO 32000-1

您可能要使用這樣一個例子開始你的測試。

此外AcroFields.SetFieldRichValue返回布爾結果,指示iText(Sharp)是否認爲設置值已成功。你也可能想檢查這個結果。