private void Printpdf()
{ //String sFileIn = args[0]; // command line parameter: input filename string sFileIn = @"c:\sample.pdf"; PdfReader reader = new PdfReader(sFileIn); using (MemoryStream ms = new MemoryStream()) { PdfStamper stamper = new PdfStamper(reader, ms); for (int i = 1; i <= reader.NumberOfPages; i++) { iTextSharp.text.Rectangle pageSize = reader.GetPageSizeWithRotation(i); PdfContentByte pdfPageContents = stamper.GetUnderContent(i); pdfPageContents.BeginText(); BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, Encoding.ASCII.EncodingName, false); pdfPageContents.SetFontAndSize(baseFont, 20); pdfPageContents.SetRGBColorFill(200, 200, 200); pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, sFileIn, pageSize.Width - 5, pageSize.Height - 25, 0); pdfPageContents.EndText(); } stamper.FormFlattening = true; stamper.Close(); FileStream fs = new FileStream("watermarked-output.pdf", FileMode.Create, FileAccess.ReadWrite); BinaryWriter bw = new BinaryWriter(fs); bw.Write(ms.ToArray()); bw.Close(); } }
0 意見:
張貼留言