Hi,
I have certificate that will download to pdf. but in pdf document font style is taking Arial.
Below is my code.
Please let me know where i am wrong?
protected void btnpdf_Click(object sender, EventArgs e)
{
Document doc = new Document(PageSize.A4, 88f, 88f, 10f, 10f);
//Font Normalfont = FontFactory.GetFont("Arial", 12, Font.NORMAL, BaseColor.BLACK);
using (System.IO.MemoryStream memorystream = new System.IO.MemoryStream())
{
PdfWriter writer = PdfWriter.GetInstance(doc, memorystream);
Phrase phrase = null;
PdfPCell cell = null;
PdfPTable table = null;
doc.Open();
table = new PdfPTable(1);
table.TotalWidth = 400f;
table.LockedWidth = true;
table.SetWidths(new float[] { 1f });
phrase = new Phrase();
phrase.Add(new Chunk("COMPLETION OF TRAINING\n\n", FontFactory.GetFont("Colonna MT", 16, Font.BOLD, BaseColor.BLUE)));
phrase.Add(new Chunk("This Certifies That\n\n", FontFactory.GetFont("Algerian", 14, Font.BOLD, BaseColor.BLACK)));
phrase.Add(new Chunk(lblname.Text + "\n\n", FontFactory.GetFont("Cambria", 14, Font.BOLD, BaseColor.RED)));
phrase.Add(new Chunk("Has successfully attended and completed\n\n", FontFactory.GetFont("Agency FB", 14, Font.BOLD, BaseColor.BLACK)));
phrase.Add(new Chunk("INDUCTION TRAINING", FontFactory.GetFont("Gabriola", 14, Font.BOLD, BaseColor.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.VerticalAlignment = PdfPCell.ALIGN_CENTER;
table.AddCell(cell);
doc.Add(table);
PdfContentByte content = writer.DirectContent;
Rectangle rectangle = new Rectangle(doc.PageSize);
rectangle.Left += doc.LeftMargin;
rectangle.Right -= doc.RightMargin;
rectangle.Top -= doc.TopMargin;
rectangle.Bottom += doc.BottomMargin;
content.SetColorStroke(BaseColor.YELLOW);
content.Rectangle(rectangle.Left, rectangle.Bottom, rectangle.Width, rectangle.Height);
content.Stroke();
doc.Close();
byte[] bytes = memorystream.ToArray();
memorystream.Close();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-Disposition", "attachment; filename=InductionCertificate.pdf");
Response.ContentType = "application/pdf";
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
Response.Close();
}
}
private static PdfPCell PhraseCell(Phrase phrase, int align)
{
PdfPCell cell = new PdfPCell(phrase);
cell.BorderColor = BaseColor.WHITE;
cell.VerticalAlignment = PdfPCell.ALIGN_TOP;
cell.HorizontalAlignment = align;
cell.PaddingBottom = 2f;
cell.PaddingTop = 0f;
return cell;
}
}
Priya BmPosted May 6, 2015, 3:15 AM
doc.Add(new Paragraph("COMPLETION OF TRAINING\n\n", fdefault));
When i try above code i am getting font as "Arial" instead I should get "Gabriola". How to get "Gabriola" font
Nanhe SiddiquePosted May 6, 2015, 1:51 AM
Font fdefault = FontFactory.GetFont("Arial", 10, Font.NORMAL, BaseColor.BLACK);
doc.Add(new Paragraph("ASP.NET Forums", fdefault ));
Shailesh UkePosted May 6, 2015, 1:26 AM
Hi Priya ,
Use these code
Font fon = FontFactory.GetFont("ARIAL", 14); //Here you can give any font name
PdfWriter.GetInstance(pdfDoc,System.Web.HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
Dipankar BiswasPosted May 6, 2015, 1:24 AM
see this link.. Working with font
http://www.mikesdotnetting.com/article/81/itextsharp-working-with-fonts
Thanks..