2
나는 Gmanny의 Pechkin Pdf 라이브러리를 사용하고 있으며 완벽하게 작동합니다. 여기 내 코드는 다음과 같습니다생성 된 PDF에 머리글과 바닥 글을 추가하는 방법
private void CreatePdfPechkin(string htmlString, string fileName)
{
//Transform the HTML into PDF
var pechkin = Factory.Create(new GlobalConfig()
.SetMargins(new Margins(100, 50, 100, 100))
.SetDocumentTitle("Test document")
.SetPaperSize(PaperKind.A4)
.SetCopyCount(1)
//.SetPaperOrientation(true)
// .SetOutputFile("F:/Personal/test.pdf")
);
ObjectConfig oc = new ObjectConfig();
oc.Footer.SetLeftText("[page]");
oc.Footer.SetTexts("[page]", "[date]", "[time]");
oc.Header.SetCenterText("TEST HEADER TEST1");
oc.Header.SetHtmlContent("<h1>TEST HEADER V2</h1>");
oc.SetAllowLocalContent(true);
//// create converter
//IPechkin ipechkin = new SynchronizedPechkin(pechkin);
// set it up using fluent notation
var pdf = pechkin.Convert(new ObjectConfig()
.SetLoadImages(true).SetZoomFactor(1.5)
.SetPrintBackground(true)
.SetScreenMediaType(true)
.SetCreateExternalLinks(true), htmlString);
//Return the PDF file
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename=test.pdf; size={0}", pdf.Length));
Response.BinaryWrite(pdf);
Response.Flush();
Response.End();
// byte[] pdf = new Pechkin.Synchronized.SynchronizedPechkin(
//new Pechkin.GlobalConfig()).Convert(
// new Pechkin.ObjectConfig()
// .SetLoadImages(true)
// .SetPrintBackground(true)
// .SetScreenMediaType(true)
// .SetCreateExternalLinks(true), htmlString);
// using (FileStream file = System.IO.File.Create(@"F:\Pankaj WorkSpace\"+ fileName))
// {
// file.Write(pdf, 0, pdf.Length);
// }
}
하지만 지금은 머리글, 바닥 글 및 페이지 번호를 추가하려면, 누군가가 그 작업을 수행하는 방법을 제안 할 수 있습니다? Object config를 통해 가능하지만 작동하지 않는다는 것을 알고 있습니다.
이미 말했듯이 PDF는 머리말 꼬리말이 없습니다. 그럼 전체 기능을 업데이트하시기 바랍니다. –
일반적인 예를 추가 한 후에 이전에 놓친 코드에서 실수를 실감했습니다. 수정 된 답변의 하단에있는 코드를 참조하십시오. – Nicholas
멍청이 남자 .. 감사합니다 .. 지금은 화요일에 전환 : –