【发布时间】:2017-02-01 13:51:59
【问题描述】:
我正在尝试使用ITextSharp 将文本添加到现有的 pdf 文件。我完全不知道如何解决它。这是我到目前为止所尝试的。我想将 wordDocContents 附加到 pdf 文件中。我想在 pdf 文件的开头附加文本,因为 pdf 文件是空的。
using System;
using System.Web;
using System.Web.UI;
using TikaOnDotNet.TextExtraction;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
namespace Project
{
public partial class Default : System.Web.UI.Page
{
public void button1Clicked(object sender, EventArgs args)
{
button1.Text = "You clicked me";
var textExtractor = new TextExtractor();
var wordDocContents = textExtractor.Extract("t.csv");
Console.WriteLine(wordDocContents);
Console.ReadLine();
generatepdffile();
}
protected void generatepdffile()
{
Document doc = new Document();
PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("file1.pdf"), FileMode.Create));
}
}
}
“wordDocContents”中的内容如下。我的目标是按照其在 pdf 文件中打印的方式附加内容。
ACCOUNT_NUMBER,CUSTOMER_NAMES,VALUE_DATE,BOOKING_DATE,TRANSACTION,ACCOUNT_TYPE,BALANCE_TYPE,REFERENCE,MONEY.OUT,MONEY.IN,RUNNING.BALANCE,BRANCH,EMAIL,ACTUAL.BALANCE,AVAILABLE.BALANCE
1000000001,TEST,,2847899,KES,Account,,,10/10/2016,9/11/2016,15181800,UPPER HILL BRANCH,another@yahoo.com,5403.75,5403.75,
1000000001,,9/11/2016,9/11/2016,Opening Balance,,,,,,4643.22,,,,,
1000000001,,12/10/2016,12/10/2016,Mobile Mpesa Transfer,,,,1533,,3110.22,,,,,
1000000001,,17-10-2016,17-10-2016,ATM Withdrawal,,,6.29006E+11,1000,,2110.22,,,,,
1000000001,,17-10-2016,17-10-2016,ATM Withdrawal,,,6.29118E+11,2000,,110.22,,,,,
1000000001,,17-10-2016,17-10-2016,Mobile Mpesa Transfer,,,,2083,,-1972.78,,,,,
1000000001,,17-10-2016,17-10-2016,Transfer from Mpesa,,,,0,4000,2027.22,,,,,
1000000001,,18-10-2016,18-10-2016,Mobile Mpesa Transfer,,,,333,,1694.22,,,,,
上述问题与建议的问题不重复,请查看以下链接。输出 pdf 的格式与链接中的格式完全不同。 https://postimg.org/image/tul7vxvrh/
【问题讨论】:
-
为什么这个问题看起来和另一个人的这个问题完全一样? stackoverflow.com/questions/41981371/…(当然现在已经删除了..)
-
“添加到现有的 pdf 文件” 到底是什么意思?从新页面开始?还是从当前内容的末尾开始?或者在给定页面上的给定坐标?或者在某些表单域中?请足够精确,以便其他人可以帮助您。