Skip to content

Instantly share code, notes, and snippets.

@yemrekeskin
Created July 17, 2018 13:27
Show Gist options
  • Save yemrekeskin/b684a601b031006943ec6a10c9169f66 to your computer and use it in GitHub Desktop.
Save yemrekeskin/b684a601b031006943ec6a10c9169f66 to your computer and use it in GitHub Desktop.
public void Deneme(string filename)
{
// variables
var pathin = Path.Combine(
Directory.GetCurrentDirectory(),"wwwroot",
filename);
string pathout = Path.Combine(
Directory.GetCurrentDirectory(),"wwwroot/exported",
filename);
var ImagePath = Path.Combine(
Directory.GetCurrentDirectory(),"wwwroot",
"nova-logo.png");
//create a document object
//var doc = new Document(PageSize.A4);
//create PdfReader object to read from the existing document
PdfReader reader = new PdfReader(pathin);
//select two pages from the original document
reader.SelectPages("1-4");
//create PdfStamper object to write to get the pages from reader
PdfStamper stamper = new PdfStamper(reader,new FileStream(pathout,FileMode.Create));
// PdfContentByte from stamper to add content to the pages under the original content
//PdfContentByte pbunder = stamper.GetUnderContent(1);
//add image from a file
var pages = reader.NumberOfPages;
for(int i = 0; i < pages; i++) {
Image logo = Image.GetInstance(ImagePath);
//logo.ScalePercent(24f);
logo.Alignment = Element.ALIGN_CENTER;
logo.Alignment = Element.ALIGN_RIGHT;
//logo.SetAbsolutePosition(72,72);
//logo.SetAbsolutePosition(0,0);
logo.SetAbsolutePosition(reader.GetPageSize(i + 1).Width - 36f - 72f,reader.GetPageSize(i + 1).Height - 36f - 216.6f);
PdfContentByte pbunder = stamper.GetUnderContent(i + 1);
//add the image under the original content
//pbunder.AddImage(logo,logo.Width / 2,0,0,logo.Height / 2,0,0);
pbunder.AddImage(logo);
}
//close the stamper
stamper.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment