如何获取保存对话框以保存生成的pdf [英] How to get save dialog box to save the generated pdf

查看:83
本文介绍了如何获取保存对话框以保存生成的pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



创建pdf时如何获取保存对话框(使用该保存对话框的用户可以提及生成的pdf的保存位置).
谢谢.

Hi,

how to get the save dialog box when the pdf is created (using that save dialog box user can mention their save location of generated pdf).
Thankyou.

推荐答案

hi friend,
if u take any link button in design page assume it is like "LinkButtonDownloadPdf" if u click this link it wl show one "save dialogue box" for that the code is below, try it....

protected void LinkButtonDownloadPdf_Click(object sender, EventArgs e)
{
        Response.ContentType = "Application/pdf";
        Response.AppendHeader("Content-Disposition", "attachment; filename=scan.pdf");
        Response.TransmitFile(Server.MapPath("scan.pdf"));
        Response.End(); 
}

here "scan.pdf" is pdf file name...

Thanks...


您好,您可以尝试以下代码:
Hello, you can try below code:
private void BtnSave_Click(object sender, EventArgs e)
{
    if (this.pdfDocumentViewer1.PageCount > 0)
    {
        SaveFileDialog dialog = new SaveFileDialog();
        dialog.Filter = "PDF document (*.pdf)|*.pdf";
        DialogResult result = dialog.ShowDialog();
        string fileName = dialog.FileName;
        if (result == DialogResult.OK)
        {
            pdfDocumentViewer1.SaveToFile(fileName);
            MessageBox.Show("You have saved this PdfDocuemnt as:\n" + fileName, "Spire.PdfViewer Demo", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
private void BtnSaveStream_Click(object sender, EventArgs e)
{
    if (this.pdfDocumentViewer1.PageCount > 0)
    {
        SaveFileDialog dialog = new SaveFileDialog();
        dialog.Filter = "PDF document (*.pdf)|*.pdf";
        DialogResult result = dialog.ShowDialog();
        string fileName = dialog.FileName;
        if (result == DialogResult.OK)
        {
            MemoryStream stream = new MemoryStream();
            pdfDocumentViewer1.SaveToFile(stream);
            byte[] fileBytes = stream.ToArray();
            FileStream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
            fileStream.Write(fileBytes, 0, fileBytes.Length);
            fileStream.Flush();
            fileStream.Close();
            stream.Close();
            MessageBox.Show("You have first saved this PDF docuemnt as memory stream,\nthen write the memory stream in a file :\n" + fileName, "Spire.PdfViewer Demo", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
}


这篇关于如何获取保存对话框以保存生成的pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆