我有一個PDF模板文件,我試圖用「MyDocument」的內容填充。所有的字段填充正常,但問題是我的PDF中的「計算」字段沒有刷新,也沒有在其他字段上設置格式。如何使計算的字段刷新和格式化以使用ITextSharp? (如果我得到一個C#或VB.NET回答我不在乎)如何刷新非計算字段上的格式並刷新可填寫PDF表單中的計算字段
VB.NET:
Public Shared Sub Serialize(ByVal stmt As MyDocument, ByVal file As FileInfo)
Dim reader As New PdfReader(TemplateFilePath.FullName)
Dim pdfStamper As New PdfStamper(reader, New FileStream(file.FullName, FileMode.Open))
Try
With itsDaDetailFields
.MoveFirst()
While Not .EOF
Dim pdfFieldName As String = NsT(Of String)(!PDFFieldName, Nothing)
If Not String.IsNullOrEmpty(pdfFieldName) Then
Dim value As String = NsT(Of String)(stmt.GetValueFromPDFField(pdfFieldName), Nothing)
If Not String.IsNullOrEmpty(value) Then
pdfStamper.AcroFields.SetField(pdfFieldName, value)
End If
End If
.MoveNext()
End While
End With
Finally
pdfStamper.FormFlattening = False
reader.Close()
pdfStamper.Close()
End Try
End Sub
C#:
public static void Serialize(MyDocument stmt, FileInfo file)
{
PdfReader reader = new PdfReader(TemplateFilePath.FullName);
PdfStamper pdfStamper = new PdfStamper(reader, new FileStream(file.FullName, FileMode.Open));
try {
var _with1 = itsDaDetailFields;
_with1.MoveFirst();
while (!_with1.EOF) {
string pdfFieldName = NsT<string>(_with1["PDFFieldName"], null);
if (!string.IsNullOrEmpty(pdfFieldName)) {
string value = NsT<string>(stmt.GetValueFromPDFField(pdfFieldName), null);
if (!string.IsNullOrEmpty(value)) {
pdfStamper.AcroFields.SetField(pdfFieldName, value);
}
}
_with1.MoveNext();
}
} finally {
pdfStamper.FormFlattening = false;
reader.Close();
pdfStamper.Close();
}
}
根據此鏈接引用的2006年的帖子,這不支持http://stackoverflow.com/a/500999/231316。有可能在過去的7年中發生了一些變化,但我猜測並非如此。 –
任何地方我可以找到更多關於這方面的信息? – Denis
我會直接進入iText郵件列表。首先,搜索是否有更近的答案,然後詢問你是否找不到任何東西。 https://lists.sourceforge.net/lists/listinfo/itext-questions –