Tuesday, June 29, 2010

iTextSharp - read an existing pdf, resize it and then draw it on a new one


PdfReader reader = new PdfReader("In.PDF");
Document doc = new Document(PageSize.A4, 0, 0, 0, 0);
PdfWriter writer = PdfWriter.GetInstance(doc, 
new FileStream("Out.PDF",
FileMode.Create));
doc.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page = writer.GetImportedPage(reader, 1); //page #1
float Scale = 0.67f;
cb.AddTemplate(page, Scale, 0, 0, Scale, 0, 0);
doc.Close();

1 comment: