Archit Shrivastava

Archit Shrivastava

  • NA
  • 416
  • 117.3k

repeat background image in pdf

Sep 10 2018 12:50 AM
i am creating a pdf document which contains stringbuilder table and image.
 
i set image as document background and set table over the image .now my question is
how to repeat background image on same page .here my code sample
 
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance("C:\\Users\\Archit\\Downloads\\itbp.jpg");
iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(PageSize.A4, 10F, 10F, 10F, 0F);
jpg.ScaleToFit(615, 175);
jpg.Alignment = iTextSharp.text.Image.UNDERLYING;
jpg.SetAbsolutePosition(10, 658);
StringBuilder sb = new StringBuilder();
sb.Append("<table background = 'file:///C:/Users/Archit/Downloads/itbp.jpg' width=100% height= 100% border=1>");
foreach (DataGridViewRow row in dgv_preview.Rows)
{
bool isSelected = Convert.ToBoolean(row.Cells["checkBoxColumn"].Value);
if (isSelected)
{
DateTime dob = DateTime.Parse(row.Cells["dob"].Value.ToString());
DateTime date = DateTime.Now;
int ab = Convert.ToInt32(row.Cells["ID"].Value);
Zen.Barcode.CodeQrBarcodeDraw brcode = Zen.Barcode.BarcodeDrawFactory.CodeQr;
sb.Append("<tr>" +
"<td width= 49% ><table width=100% border =1>" +
"<tr><td height=\'150%\' colspan=3>Header</td></tr>" +
"<tr><td width=29% rowspan=5><img src= C:\\Users\\Archit\\Downloads\\a1.png width = 70 height =50></td><td width=23% height=10 colspan = 2>ssss</td></tr>" +
"<tr><td ></td><td><span style='font-family: arial; font-size: 10pt;'>" + row.Cells["REGT NO"].Value.ToString() + "</span></td> </tr>" +
"<tr><td></td><td><span style='font-family: arial; font-size: 10pt;'>" + row.Cells["RANK"].Value.ToString() + "</span></td></tr>" +
"<tr><td height=12></td><td><span style='font-family: arial; font-size: 10pt;'>" + row.Cells["NAME"].Value.ToString() + "</span></td></tr>" +
"<tr><td height=10></td><td><span style='font-family: arial; font-size: 10pt;'>" + row.Cells["Aadharno"].Value.ToString() + "</span></td></tr>" +
"<tr><td height=44><img src= D:\\HOLDER_SIGN\\sign.jpg width = 50 height =30 valign='top'></td><td colspan=2>" +
"<table border=1 width=100%><tr><td width=36% rowspan=2></td> <td width=21% height=0><span style='font-family: arial; font-size: 8pt;'>" + row.Cells["CARD NO"].Value.ToString() + "</span></td>" +
"<td width=43% rowspan=2><img src= D:\\HOLDER_SIGN\\sign.jpg width = 50 height =30 ></td></tr>" +
"<tr><td height=10><span style='font-family: arial; font-size: 8pt;'>" + row.Cells["bloodgroup"].Value.ToString() + "</span></td></tr>" +
"<tr><td height=10 colspan=3></td></tr>" +
"</table></td><td ></td></tr></table></td>" +
"<td width=1></td>" +
"<td width=49% >" +
"<table border=1 width=100% ><tr><td width=34% height=10>***</td><td width=40% height=10><span style='font: Kruti Dev 010; font-size: 6pt;'>" + row.Cells["location_h"].Value.ToString() + "</span></td><td width=26% rowspan=3>" + brcode.Draw("read 200000 faliure " + (ab * 1.5).ToString(), 16) + "</td></tr>" +
"<tr><td height=10></td><td height=10><span style='font-family: arial; font-size: 6pt;'>" + row.Cells["idmark"].Value.ToString() + "</span></td></tr>" +
"<tr><td height=20 colspan=2>" +
"<table border=1 width=100%><tr><td height=13></td><td height=13><span style='font-family: arial; font-size: 6pt;'>" + dob.ToString("dd/MM/yyyy") + "</span></td><td height=13></td><td height=13><span style='font-family: arial; font-size: 6pt;'>" + date.ToString("dd/MM/yyyy") + "</span></td></tr>" +
"<tr><td height=12></td><td height=12><span style='font-family: arial; font-size: 6pt;'>" + row.Cells["eye"].Value.ToString() + "</span></td><td height=12></td><td height=12><span style='font-family: arial; font-size: 6pt;'>" + row.Cells["height"].Value.ToString() + "</span></td></tr>" +
"</table>" +
"</td></tr>" +
"<tr><td height=25></td><td colspan=2><span style='font-family: arial; font-size: 6pt;'>" + row.Cells["Location"].Value.ToString() + "</span></td></tr>" +
"<tr><td height=56 colspan=3>35</td></tr></table></td>");
sb.Append("</tr>");
}
}
sb.Append("</table>");
StringReader sr = new StringReader(sb.ToString());
string path = "C:\\Users\\Archit\\Desktop\\test.pdf";
StringWriter sw = new StringWriter();
var output = new FileStream(path, FileMode.Create);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, output);
pdfDoc.Open();
pdfDoc.Add(jpg);
htmlparser.Parse(sr);
pdfDoc.Close();