I want to achieve same thing in windows form using c#
i wrote the following code but it is not showing me Arabic character in pdf.
how to fix it?
private void toolStripButton1_Click(object sender, EventArgs e)
{
//this.Close();
try
{
string pdfpath = @"C:\Reports\";
if (!Directory.Exists(pdfpath))
{
Directory.CreateDirectory(pdfpath);
}
Document doc = new Document(PageSize.A4.Rotate());
PdfWriter.GetInstance(doc, new FileStream(pdfpath + "Arabic.pdf", FileMode.Create));
// PdfWriter.GetInstance(doc, new FileStream(pdfpath + "AttendanceStatus.pdf", FileMode.Create));
BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\Arial.ttf", BaseFont.IDENTITY_H, true);
doc.Open();
con = new SqlDbConnect();
con.SqlQuery("select logo,SystemName,Address,Phone,Email FROM tblSystem");
con.RdrEx();
while (con.Rdr.Read())
{
PdfPTable table1 = new PdfPTable(2);
table1.DefaultCell.Padding = 10f;
table1.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
table1.DefaultCell.Border = 0;
table1.HorizontalAlignment = Element.ALIGN_CENTER;
table1.TotalWidth = 500f;
table1.LockedWidth = true;
float[] widths1 = new float[] { 0.7f, 3f };
table1.SetWidths(widths1);
Byte[] bytes = (Byte[])con.Rdr[0];
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(bytes);
image.ScaleAbsolute(90f, 70f);
PdfPCell bottom1 = new PdfPCell((image));
bottom1.Padding = 5f;
bottom1.BackgroundColor = iTextSharp.text.Color.WHITE;
bottom1.Border = 0;
bottom1.HorizontalAlignment = 1;
table1.AddCell(bottom1);
PdfPTable nested1 = new PdfPTable(1);
float[] width = new float[] { 0.1f };
nested1.SetWidths(width);
nested1.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
nested1.DefaultCell.Padding = 7f;
nested1.DefaultCell.HorizontalAlignment = 1;
nested1.DefaultCell.Border = 0;
nested1.AddCell(new Phrase(con.Rdr[1].ToString(), FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 15)));
nested1.AddCell(new Phrase(con.Rdr[2].ToString(), FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 14)));
nested1.AddCell(new Phrase("Email: " + con.Rdr[4].ToString() + "\t Phone No: " + con.Rdr[3].ToString(), FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12)));
// nested1.AddCell(new Phrase("Phone No: " + con.Rdr[3].ToString(), FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 14)));
PdfPCell nesthousing1 = new PdfPCell(nested1);
nesthousing1.Colspan = 2;
nesthousing1.Padding = 0f;
nesthousing1.Border = 0;
table1.AddCell(nesthousing1);
doc.Add(table1);
Paragraph p = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(1.0F, 100.0F, iTextSharp.text.Color.BLACK, Element.ALIGN_LEFT, 1)));
doc.Add(p);
}
con.conClose();
PdfPTable tableb = new PdfPTable(8);
tableb.TotalWidth = 780f;
tableb.LockedWidth = true;
float[] widthsss = new float[] { 0.1f, 0.08f, 0.05f, 0.04f, 0.1f, 0.05f, 0.05f, 0.05f };
tableb.SetWidths(widthsss);
tableb.DefaultCell.Padding = 3f;
tableb.HorizontalAlignment = Element.ALIGN_CENTER;
tableb.SpacingAfter = 25f;
PdfPCell headerb = new PdfPCell(new Phrase("Product Details", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 14)));
headerb.Colspan = 8;
headerb.Padding = 10;
headerb.Indent = 10;
headerb.HorizontalAlignment = 1;
tableb.AddCell(headerb);
tableb.AddCell(new Phrase("Vendor", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12)));
tableb.AddCell(new Phrase("Store", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12)));
tableb.AddCell(new Phrase("Location", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12)));
tableb.AddCell(new Phrase("Unit", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12)));
tableb.AddCell(new Phrase("Product", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12)));
tableb.AddCell(new Phrase("Code", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12)));
tableb.AddCell(new Phrase("Qty", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12)));
tableb.AddCell(new Phrase("Price", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12)));
con = new SqlDbConnect();
con.SqlQuery(@"select VendorName,StoreType,LocName,U_Name,ItemName,ItemCode,Qty,Price from tblStores as s
inner join tblVendor as v on s.VendorID=v.VendorID
inner join tblStoreType as vt on s.StoreTypeID=vt.StoreTypeID
inner join tblLocation as vl on s.LocID=vl.LocID
inner join tblUnit as vu on s.UnitID=vu.UnitID order by StoresID desc;");
con.RdrEx();
while (con.Rdr.Read())
{
tableb.AddCell(new Phrase(con.Rdr[0].ToString(), FontFactory.GetFont("Calibri", 8)));
tableb.AddCell(new Phrase(con.Rdr[1].ToString(), FontFactory.GetFont("Calibri", 8)));
tableb.AddCell(new Phrase(con.Rdr[2].ToString(), FontFactory.GetFont("Calibri", 8)));
tableb.AddCell(new Phrase(con.Rdr[3].ToString(), FontFactory.GetFont("Calibri", 8)));
tableb.AddCell(new Phrase(con.Rdr[4].ToString(), FontFactory.GetFont("Calibri", 8)));
tableb.AddCell(new Phrase(con.Rdr[5].ToString(), FontFactory.GetFont("Calibri", 8)));
tableb.AddCell(new Phrase(con.Rdr[6].ToString(), FontFactory.GetFont("Calibri", 8)));
tableb.AddCell(new Phrase(con.Rdr[7].ToString(), FontFactory.GetFont("Calibri", 8)));
//tableb.AddCell(new Phrase(con.Rdr[8].ToString(), FontFactory.GetFont("Calibri", 8)));
}
doc.Add(tableb);
doc.Close();
MessageBox.Show("Product List Generated Successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}