English 中文(简体)
在ASP.NET的具体页面上提交PDF文件
原标题:Present a PDF Document on a Specific Page in ASP.NET
  • 时间:2012-05-22 23:49:37
  •  标签:
  • asp.net
  • pdf

我用以下ASP.NET代码打开PDF文件

Response.BufferOutput = true;
Response.Clear();
Response.ContentType = "application/pdf";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(documentURL);

using (HttpWebResponse responseDDRINT = (HttpWebResponse)request.GetResponse())
{
    using (Stream stream = responseDDRINT.GetResponseStream())
    {
        int bufferSize = 1024;
        byte[] buffer = new byte[bufferSize];
        int bytesRead;

        while ((bytesRead = stream.Read(buffer, 0, bufferSize)) > 0)
        {
            Response.OutputStream.Write(buffer, 0, bytesRead);
        }

        Response.Flush();                        
    }
}

我的问题是,是否有人知道如何从特定页面开始展示PDF。 例如,如果PDF文件为15页,我们希望它以第10页打开,而不是第1页打开,而以第1页开头。

我用“#page=”打开参数进行了实验, 添加了这个页眉, 但它什么也没做 。

Response.AddHeader("content-disposition", "inline; filename=test.pdf#page=3");
问题回答

You ll have to manipulate the PDF file on the fly.
Use something like http://pdfsharp.com/PDFsharp/ to stream out a copy of the file starting at a certain page.

  1. Current versions of Adobe ready no longer support the page syntax, but they do support the bookmark syntax.
  2. Why don t you make your document reachable through a regular link or through an HTTPHandler?

您可以使用 PDF 操作库, 如< a href=> http://sourceforge.net/ projects/ itextsharp/" rel=" nofollow noreferrer" > ItextSharp 完成您的工作。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签