Generate multiple PDFS via Itextsharp

Asked

Viewed 131 times

2

I am developing an application that builds pdf’s dynamically through the Itextsharp library.

It is working and providing the download correctly, but would like to generate a larger amount of documents. And bump into Response.End(), when he mounts the first PDF and arrives at Response.End it simply stops running and downloads.

I would like him to continue assembling more documents and after completion, download all others.

Follows the code :

   // Definição da Margem do PDF
    Document pdfDoc = new Document(PageSize.A4, -20f, -20f, 5f, 0f);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    HTMLWorker obj = new HTMLWorker(pdfDoc);
    MemoryStream ms = new MemoryStream();
    PdfWriter writer = PdfWriter.GetInstance(pdfDoc, ms);

    pdfDoc.Open();
    string htmlDisplayText = WBarCode(SEQ_NUM.Text);
    StringReader se = new StringReader(htmlDisplayText);
     // criação do QRcode
    var paramQR = new Dictionary<EncodeHintType, object>();
    paramQR.Add(EncodeHintType.CHARACTER_SET, 
    CharacterSetECI.GetCharacterSetECIByName("UTF-8"));
    BarcodeQRCode qrCodigo = new BarcodeQRCode(SEQ_NUM.Text, 82, 82,       
    paramQR);
    iTextSharp.text.Image imgQRCode = qrCodigo.GetImage();
    PdfPTable table = new PdfPTable(10);

    .
    .
    .
    pdfDoc.Add(table);
    //exibição da imagem do código de barras.
    obj.Parse(se);

    pdfDoc.Close();
    Response.Clear();
    // * Especifica o MIMETYPE

    Response.ContentType = "application/pdf";

    Response.AppendHeader("Content-Disposition", "attachment; 
    filename="Nome_do_arquivo.pdf");

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    // * Libera o documento
    Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
    Response.BinaryWrite(ms.GetBuffer());

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

    // Fechamento do arquivo
    Response.End();

1 answer

0

You cannot send multiple files via HTTP Request/Response. You will need to make multiple requests or "package" your files at .zip, .rar, .cab and etc.

  • I understood, but how could I make several requests without stopping at "Response.End()" ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.