0
所以我一直在尝试使用iTextSharp编辑现有的PDF文件。我已经能够使用下面的代码来做到这一点。使用iTextSharp和MVC编辑现有的pdf并发送下载
public static void AddTextToPdf(string inputPdfPath, string outputPdfPath, string name, string mID, string dj)
{
//variables
string pathin = inputPdfPath;
string pathout = outputPdfPath;
//create PdfReader object to read from the existing document
using (PdfReader reader = new PdfReader(pathin))
//create PdfStamper object to write to get the pages from reader
using (PdfStamper stamper = new PdfStamper(reader, new FileStream(pathout, FileMode.Create)))
{
//select two pages from the original document
reader.SelectPages("1");
//gettins the page size in order to substract from the iTextSharp coordinates
var pageSize = reader.GetPageSize(1);
// PdfContentByte from stamper to add content to the pages over the original content
PdfContentByte pbover = stamper.GetOverContent(1);
//add content to the page using ColumnText
Font font = new Font();
font.Size = 45;
font.Color = Colors.stringToBaseColor("224,90,71");
//Do Name
DrawText(50, 260, pageSize, pbover, name, font);
//Do Date
font.Size = 16;
DrawText(200, 402, pageSize, pbover, dj, font);
//Do mID
DrawText(180, 422, pageSize, pbover, mID, font);
}
}
我想这个集成到MVC应用程序,将将修改后的PDF文件下载,但我已经遇到了一个心理障碍。任何帮助,将不胜感激。
您现在已将编辑的PDF保存到磁盘。你想下一步该做什么?发送下载是什么意思? –
我在想的是不是保存文件,而是修改方法使其返回,在此时我可以将它发送给mvc控制器下载。这将节省我将文件保存到磁盘的麻烦。 – Xerc