Tenho a rotina abaixo. Obeserve que eu tenho fonteTitulo1 e fonteTitulo2. O fonteTitulo2 recebe um subtitulo. Esse cara deve estar alinhado no centro da página e não à esquerda como hoje está. Como eu faço? O código abaixo, está correto? Eu recebi esse código
e fiz minjhas adaptações para ele funcionar com título e subtítulo. Alguém pode me ajudar com isso? Não conheço iTextSharp.
protected void btnSalvar_Click(object sender, EventArgs e)
{
RadChart radChart11;
RadChart radChart22;
int codUsuario = 123;
bl.periodoMes = Request.QueryString["Mes"].ToString();
bl.Execute(codUsuario);
radChart11 = criaChart1(bl);
this.Panel1.Controls.Add(radChart11);
radChart22 = criaChart2(bl);
this.Panel1.Controls.Add(radChart22);
System.IO.MemoryStream ms1 = new System.IO.MemoryStream();
System.IO.MemoryStream ms2 = new System.IO.MemoryStream();
radChart11.Save(ms1, System.Drawing.Imaging.ImageFormat.Png);
radChart22.Save(ms2, System.Drawing.Imaging.ImageFormat.Png);
this.Page.Response.Clear();
this.Page.Response.ClearHeaders();
int opcao = 2; // 1-download de imagem, 2-download de pdf
if (opcao == 1)
{
this.Page.Response.AddHeader("Content-disposition", "attachment; filename=Chart.png");
this.Page.Response.AddHeader("Content-type", "image/png");
this.Page.Response.BinaryWrite(ms1.ToArray());
}
else if (opcao == 2)
{
this.Page.Response.AddHeader("Content-type", "application/pdf");
Document pdfDoc = new Document(PageSize.A4.Rotate(), 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
iTextSharp.text.Image img1 = iTextSharp.text.Image.GetInstance(ms1.ToArray());
iTextSharp.text.Image img2 = iTextSharp.text.Image.GetInstance(ms2.ToArray());
Font fonteTitulo1 = FontFactory.GetFont("Verdana", 12, iTextSharp.text.Font.BOLD);
fonteTitulo1.SetColor(255, 0, 0);
Font fonteTitulo2 = FontFactory.GetFont("Verdana", 10, iTextSharp.text.Element.ALIGN_CENTER);
fonteTitulo2.SetColor(0, 0, 0);
Chunk titulo1 = new Chunk("DESEMPENHO POR PERIODO", fonteTitulo1);
Phrase phrase1 = new Phrase(titulo1);
Chunk stitulo1 = new Chunk("\n"+lblTitulo1.Text, fonteTitulo2);
Phrase phrase2 = new Phrase(stitulo1.);
Paragraph p = new Paragraph();
p.Add(phrase1);
p.Add(phrase2);
pdfDoc.Add(p);
Font subTitulo2 = FontFactory.GetFont("Verdana", 10, iTextSharp.text.Font.BOLD);
fonteTitulo1.SetColor(255, 0, 0);
Chunk stitulo2 = new Chunk(lblTitulo2.Text, subTitulo2);
Phrase phrase3 = new Phrase(stitulo2);
Paragraph p2 = new Paragraph();
p.Add(phrase3);
pdfDoc.Add(p2);
img1.ScaleToFit(pdfDoc.PageSize.Width - 40f, pdfDoc.PageSize.Height);
img1.Alignment = Element.ALIGN_CENTER;
pdfDoc.Add(img1);
img2.ScaleToFit(pdfDoc.PageSize.Width - 40f, pdfDoc.PageSize.Height);
img2.Alignment = Element.ALIGN_CENTER;
pdfDoc.Add(img2);
pdfDoc.Close();
Response.Write(pdfDoc.ToString());
}
this.Page.Response.End();
}