다음 코드는 스트림으로 pdf를 생성합니다. 이것은 잘 작동하지만 지금 다음 요구 사항이 있습니다.페이지 번호 추가 및 itext로 스트림에서 가로 A4 만들기
1) make page landscape : 다른 예제를 보면 문서 객체에 속성을 추가합니다. 하지만이 인스 트림을하고 있어요. 그러면이 속성을 어떻게 추가할까요?
2) 페이지 번호를 추가하십시오. 페이지 당 행 수가 x가되도록 그리드에 항목을 넣어야합니다. 페이지 바닥 글에 페이지 번호가 있습니다. Itext sharp로 어떻게 이런 종류의 기능을 습득 할 수 있습니까?
public static void Create(ICollection<Part> parts, string path)
{
PdfReader reader = new PdfReader(path);
var pageWidth = 500;
byte[] bytes;
using (MemoryStream ms = new MemoryStream())
{
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
PdfContentByte cb = stamper.GetOverContent(1);
//Flush the PdfStamper's buffer
stamper.Close();
//Get the raw bytes of the PDF
bytes = ms.ToArray();
var now = String.Format("{0:d-M-yyyy}", DateTime.Now);
var pdfName = string.Format("{0}_factory_worksheet", now).Replace("%", "").Replace(" ", "_");
var context = HttpContext.Current;
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("content-disposition", "attachment;filename=" + pdfName);
context.Response.Buffer = true;
context.Response.Clear();
context.Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
context.Response.OutputStream.Flush();
context.Response.End();
}
}
}
처음부터 PDF를 생성하지 않으므로 실제로 기존 부품에서 부품을 가져오고 있습니까? –