Home > Software design >  Align the letterhead on top of PDF document using iTextSharp in C#
Align the letterhead on top of PDF document using iTextSharp in C#

Time:03-17

I have the following code

Document pdfDoc = new Document(PageSize.A4, 25, 25, 25, 10);
string pathfile = ConfigurationManager.AppSettings["Temp_SaveLocation"];
string fileName = "SomeName.pdf";
path = pathfile   fileName;
PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, new FileStream(path, FileMode.Create));
pdfDoc.Open();

Image imghead = Image.GetInstance(templateFolder   "Letterhead.png");

pdfDoc.Add(imghead);
pdfWriter.CloseStream = true;
pdfDoc.Close();

I am trying to properly align the letterhead on top of the PDF document so that it will look nice and fit properly

I tried imghead.ScaleAbsoluteWidth(pdfDoc.PageSize.Width); but still the letterhead appears cut off. I also tried setting the Width property, but there no aspect ratio, and because of that the letterhead looks odd

Is there any specific way to fit the letterhead properly on top of the PDF?

Thank you very much in advance

CodePudding user response:

Here is the answer I was looking for

imghead.ScaleToFit(150f, 150f);
  • Related