How to generate multiple PDF dynamically through Itextsharp

0

I am creating a method in C # in which the user enters a listing of data and application mounts a pdf document for each given information.

I'm using the iTextSharp library. In the first one it generates the PDF as expected, however when checking in the code it stops at Response.End() and prevents it from reading the other data to generate the next PDFs.

The question would be, how could you do to generate the PDFs uninterruptedly until all user input has been met?

Code:

protected void btn_pdf_Click(object sender, EventArgs e){          
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 40f, 0f);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    HTMLWorker obj = new HTMLWorker(pdfDoc);
    MemoryStream ms = new MemoryStream();
    PdfWriter writer = PdfWriter.GetInstance(pdfDoc, ms);
    pdfDoc.Open();
    pdfDoc.Add(table);

    pdfDoc.Close();
    Response.Clear();

    Response.OutputStream.Flush();
    Response.OutputStream.Close();

    Response.End(); // Nesse ponto ele para o loop
}
    
asked by anonymous 03.09.2018 / 21:10

1 answer

0

I do not know where loop is ... but you could do like this:

protected void btn_pdf_Click(object sender, EventArgs e)
{    
    do{      
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 40f, 0f);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        HTMLWorker obj = new HTMLWorker(pdfDoc);
        MemoryStream ms = new MemoryStream();
        PdfWriter writer = PdfWriter.GetInstance(pdfDoc, ms);
        pdfDoc.Open();
        pdfDoc.Add(table);

        pdfDoc.Close();
        Response.Clear();

        Response.OutputStream.Flush();
        Response.OutputStream.Close();

        Response.End(); // Nesse ponto ele para o loop
    }
    while(textBox.TextLength>0 && textBox2.TextLength>0)
}

If this is what I understand, this is what you will do while the fields are not all filled up.

PS : It's just a suggestion, since the question is not clear ...

    
03.09.2018 / 22:24