Fit text in PDF format with iTextSharp: ASP.NET and C #

1

I have the following pdf that I generate with iTextSharp

  

What I want is to pass the totals under the GridView something like:

var para = new Paragraph("Total de piezas" + TxtPiezas.Text);
            para.Alignment = 2; // se que esto recorre solo el texto, pero no se que otra propiedad me ayude a bajar el texto
            para.Font.Size = 12;
            pdfDoc.Add(para);

GridView Code:

 private void ExportarPDF()
{
    using (StringWriter sw = new StringWriter())
    {
        using (HtmlTextWriter hw = new HtmlTextWriter(sw))
        {
            GRILLA.RenderControl(hw);
            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);

            PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            Font LineBreak = FontFactory.GetFont("Arial", size: 16);
            iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(@"C:\alimenta1.png");
            Paragraph parrafo2 = new Paragraph(string.Format("              REPORTE VENTAS"), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 16));
            parrafo2.SpacingBefore = 200;
            parrafo2.SpacingAfter = 0;
            parrafo2.Alignment = 1; //0-Left, 1 middle,2 Right
            pdfDoc.Add(parrafo2);
            pdfDoc.Add(Chunk.NEWLINE);
            img.SetAbsolutePosition(0, 750);
            pdfDoc.Add(img);
            img.ScaleToFit(115f, 50F);
            var para = new Paragraph(Fecha.Text);
            para.Alignment = 2;
            para.Font.Size = 12;
            pdfDoc.Add(para);
            pdfDoc.Add(new Paragraph("\n", LineBreak));
            pdfDoc.Add(new Paragraph("Vendedor: " + Label1.Text));
            pdfDoc.Add(new Paragraph("\n\n", LineBreak));

            pdfDoc.Add(new Paragraph("Total de piezas: " + TotPiezas.Text));
            pdfDoc.Add(new Paragraph("Total de Kilos: " + TotKilos.Text));
            pdfDoc.Add(new Paragraph("Total de importe: " + TotImporte.Text));
            pdfDoc.Add(new Paragraph("\n\n", LineBreak));
            pdfDoc.Add(new Paragraph("\n\n", LineBreak));
            XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
            pdfDoc.Close();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Write(pdfDoc);
            Response.End();
        }
    }

}
    
asked by Elizabeth 17.07.2018 в 20:40
source

0 answers