相关疑难解决方法(0)

iTextSharp生成PDF:如何将pdf发送到客户端并添加提示?

我使用iTextSharp生成了一个pdf,当它创建时,它会自动保存在我的代码中提供的位置,而不是在客户端的服务器上,当然也没有告诉用户任何东西.

我需要将它发送给客户端,我需要提示一个对话框询问用户他想要保存他的pdf的位置.

我该怎么办?

这是我的pdf代码:

using (MemoryStream myMemoryStream = new MemoryStream())
{
    Document document = new Document();
    PdfWriter PDFWriter = PdfWriter.GetInstance(document, myMemoryStream);

    document.AddHeader("header1", "HEADER1");


    document.Open();

      //..........

    document.Close();

    byte[] content = myMemoryStream.ToArray();

    // Write out PDF from memory stream.
    using (FileStream fs =      File.Create(HttpContext.Current.Server.MapPath("~\\report.pdf")))
    {
        fs.Write(content, 0, (int)content.Length);
    }
Run Code Online (Sandbox Code Playgroud)

编辑

这是我想要http://examples.extjs.eu/?ex=download的结果示例

感谢您的回复,我修改了我的代码:

HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AppendHeader( "Content-Disposition", "attachment; filename=test.pdf");


using (MemoryStream myMemoryStream = new MemoryStream())
{    
Document document = new Document();    
PdfWriter PDFWriter = PdfWriter.GetInstance(document, myMemoryStream);

document.AddHeader("Content-Disposition", "attachment; filename=wissalReport.pdf");

document.Open(); …
Run Code Online (Sandbox Code Playgroud)

c# pdf extjs prompt itextsharp

6
推荐指数
2
解决办法
3万
查看次数

如何在合并时删除空格

我有一些代码需要3个不同的PDF字节数组并合并它们.这段代码效果很好.问题(有些人)认为每个PDF都被认为是一个完整的页面(如果打印),即使它上面只有4英寸的内容,因此垂直留下7英寸的空白区域.然后将中间文档放入其中,并且可以在其末尾处具有或不具有垂直空白空间.然后页脚也会放在自己的页面上.

这是代码:

byte[] Bytes = rv.LocalReport.Render("PDF", null, out MimeType, out Encoding, out Extension, out StreamIDs, out Warnings);
List<byte[]> MergeSets = // This is filled prior to this code

// Append any other pages to this primary letter
if (MergeSets.Count > 0) {
  MemoryStream ms = new MemoryStream();
  Document document = new Document();
  PdfCopy copy = new PdfCopy(document, ms);
  document.Open();
  PdfImportedPage page;
  PdfReader reader = new PdfReader(Bytes); // read the generated primary Letter
  int pages = reader.NumberOfPages;

  for (int i = …
Run Code Online (Sandbox Code Playgroud)

c# pdf itextsharp

4
推荐指数
1
解决办法
2041
查看次数

标签 统计

c# ×2

itextsharp ×2

pdf ×2

extjs ×1

prompt ×1