PDF下载后重定向到另一页

时间:2018-01-06 06:24:27

标签: c#

我有一个aspx(比如1.aspx)页面,首先我下载一个pdf文件,然后我想重定向到一些2.aspx页面。代码是这样的:

protected void buttSubmit_Click(object sender, EventArgs e)//Submit button to generate PDF
    {            
            if (intInvoID > 0)
            {
               UpdateInvoice();          
            }
            else
            {
                SaveInvoice();      
            }

            GenearatePDf(strheader, htrFooter, strContact, strExihibition, strPaymentDetails, strNotes);
            Response.AddHeader("Refresh", "12;URL=~/expo_crm/invoice/View_Invoices.aspx");

        }
    }

在这里,我无法重定向到View_Invoices.aspx。我尝试使用Response.header.But它不工作。

private void GenearatePDf(string strheader, string strFooter, string strContact, string strExihibition, string strPaymentDetails, string strNotes)
    {
             Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Invoice_" + txtCompanyName.Text.Trim() + ".pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();

            StringReader srHtmlText = new StringReader(sbHtmlText.ToString());
            Document pdfDocument = new Document(PageSize.A4, 40f, 40f, 15f, 2f);

            iTextSharp.text.html.simpleparser.HTMLWorker htmlparser = new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDocument);

            PdfWriter pdfDoc1 = PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
            var page = new ITextEvents();
            page.email = txtExpogrEmail.Text.Trim();
            pdfDoc1.PageEvent = page;



            pdfDocument.Open();
            pdfDocument.Add(ph1);
            pdfDocument.Add(tblBlank);
            pdfDocument.Add(tblAddInfo);

            pdfDocument.Add(tblCon);
            pdfDocument.Add(tblExhibition);
            pdfDocument.Add(tblNotes);
            pdfDocument.Add(iHeader);

            pdfDocument.Add(jpg);
            pdfDocument.Add(jpg1);

            htmlparser.Parse(srHtmlText);
            pdfDocument.Close();
            Response.Write(pdfDocument);
            //Response.End();}

1 个答案:

答案 0 :(得分:0)

可能是Refresh标题仅在您提供HTML文档时才有效。每this question,它等同于<meta http-equiv="refresh" url="..." />头标记。哪个只能出现在html文档中。