Generate multiple PDFS via Itextsharp

2

I'm developing an application that bundles PDF's dynamically through the Itextsharp library.

It's working and making the download available correctly, but I'd like to generate more documents. And it does not Response.End() , when it mounts the first Pdf and arrives at Response.End it simply to execute and download.

I would like it to continue mounting more documents and after completion, download all the others.

Follow 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();
    
asked by anonymous 13.09.2018 / 15:29

1 answer

0

Multiple files can not be sent via HTTP Request / Response. You will need to make multiple requests or "pack" your files in .zip , .rar , .cab and so on.

    
13.09.2018 / 16:42