0
그래서 iTextSharp를 사용하여 기존 PDF 파일을 편집하려고했습니다. 나는 아래의 코드를 사용하여 그렇게 할 수 있었다. 기존 pdf를 편집하고 iTextSharp 및 MVC를 사용하여 다운로드하십시오.
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);
}
}
나는 다운로드를 위해 개정 된 PDF 파일을 보낼 것 MVC 응용 프로그램에이 통합하기 위해 노력하고있어,하지만 난 정신 블록으로 실행했습니다. 어떤 도움을 주시면 감사하겠습니다. 라인
using (PdfStamper stamper = new PdfStamper(reader, new FileStream(pathout, FileMode.Create)))
에서
이제 편집 한 PDF를 디스크에 저장했습니다. 다음에 무엇을하고 싶니? 다운로드를 보내려면 무엇을 의미합니까? –
내가 생각하고있는 것은 파일을 저장하는 대신 메서드를 수정하여 mvc 컨트롤러에서 다운로드 할 때 보낼 수있는 지점을 반환해야합니다. 이렇게하면 파일을 디스크에 저장하는 번거 로움을 덜 수 있습니다. – Xerc