Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public void FillWarrantyCertificate(string blankWarrantyCertificatePath, string pdfDestinationPath, Application application)
PdfReader pdfReader = new PdfReader(blankWarrantyCertificatePath);
using (var ms = new MemoryStream())
using (var fs = new FileStream(blankWarrantyCertificatePath, FileMode.Open, FileAccess.Read))
pdfService.AddTextToPdf(ms, "abc", new Point(30, 30));
using (var fs = new FileStream(pdfDestinationPath, FileMode.CreateNew))
public void AddTextToPdf(MemoryStream pdfStream, string text, Point point)
pdfStream.Position = 0;
using (var ms = new MemoryStream())
using (PdfReader reader = new PdfReader(pdfStream))
using (PdfStamper stamper = new PdfStamper(reader, ms))
//select two pages from the original document
//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
iTextSharp.text.Font font = new iTextSharp.text.Font();
font.Size = 45;
//setting up the X and Y coordinates of the document
int x = point.X;
int y = point.Y;
y = (int)(pageSize.Height - y);
ColumnText.ShowTextAligned(pbover, Element.ALIGN_CENTER, new Phrase(text, font), x, y, 0);
pdfStream = new MemoryStream();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.