到的ReportViewer DIV /图像/对象中的PDF [英] ReportViewer to PDF inside div/image/object

查看:136
本文介绍了到的ReportViewer DIV /图像/对象中的PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直在寻找过去几天中并没有能够找到我要找的,我希望我没有错过它。

我有我放在一起检索工资信息的ASP.NET(4.0)的网站。目前我使用的ReportViewer,但由于跨浏览器的支持,这是行不通的100%。我已经把它设置为自动呈现RV成PDF,把它变成字节。

我有code到
A)打开PDF作为一个独立的文件
B)在新窗口中打开PDF

我想做到的是开放的同一页面内的PDF,一个DIV /表格/图像/其他对象中......而这正是我难倒。 VB code我现在有低于...

 昏暗字节字节()        昏暗的警告作为警告()
        昏暗streamIds作为字符串()
        昏暗mime类型为String =无
        昏暗的编码作为字符串=无
        昏暗的推广作为字符串=无
        昏暗的文件名的String =PayDetail        字节= rvPayroll.LocalReport.Render(PDF,没什么,mime类型,编码,扩展,streamIds,警告)        *****自动询问用户保存/打开PDF
        将Response.Buffer = TRUE
        Response.Clear()
        'Response.ContentType = mime类型
        Response.AddHeader(内容处置,内联;文件名=&安培;文件名和放大器;&AMP。扩展名)
        'Response.BinaryWrite(字节)
        Response.Flush()        *****打开PDF AS新网页
        Response.BufferOutput = TRUE
        Response.ClearContent()
        Response.ClearHeaders()
        'Response.ContentType = mime类型
        Response.AddHeader(内容长度,bytes.Length.ToString)
        Response.AddHeader(内容处置,内联;文件名= PayDetail.pdf)
        'Response.ContentType =applicatin / PDF
        'Response.BinaryWrite(字节)
        Response.Flush()
        Response.Clear()

我试图打开PDF成图像和显示器,但没有收到任何在图像框。试过用:

 昏暗base64String的String = Convert.ToBase64String(字节,0,bytes.Length)        Image1.ImageUrl =数据:图像/ PNG; BASE64,与& base64String        Image1.Visible = TRUE


解决方案

首先,创建一个通用处理器所谓GeneratePDF.ashx。注意:我没有写低于code和我不是一个VB.NET程序员,所以我不能保证它会工作。

 生成字节,也许是基于参数的Request.QueryString
`写入字节输出
将Response.Buffer = TRUE
Response.Clear()
Response.ContentType =应用程序/ PDF
Response.AddHeader(内容处置,内联;文件名=&安培;文件名和放大器;&AMP。扩展名)
Response.BinaryWrite(字节)
Response.Flush()

那么,我们的页面上,我们使用来自以下链接的若干技术问题探讨之一嵌入PDF,确保给指向我们的通用处理程序的URL,并通过产生通过查询字符串中的PDF所需的任何参数。

 <嵌入的src =?GeneratePDF.ashx参数1 =航空自卫队和放大器;参数2 = QWERWIDTH =500HEIGHT =375类型=应用/ PDF/>

以上code改编自推荐方式HTML中嵌入PDF?

Been searching for the past couple of days and haven't been able to find what I'm looking for, hopefully I haven't missed it.

I have an ASP.NET (4.0) site that I'm putting together to retrieve payroll information. Currently I'm using the reportviewer, but because of cross-browser support it doesn't work 100%. I already have it set up to automatically render the RV into a PDF, turning it into bytes.

I have code to A) Open the PDF as a standalone document B) Open the PDF in a new window

What I want to accomplish is open the PDF within the same page, within a div/table/image/other object... And that's where I'm stumped. VB code I currently have is below...

        Dim bytes As Byte()

        Dim warnings As Warning()
        Dim streamIds As String()
        Dim mimeType As String = Nothing
        Dim encoding As String = Nothing
        Dim extension As String = Nothing
        Dim filename As String = "PayDetail"

        bytes = rvPayroll.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamIds, warnings)

        ' ***** AUTOMATICALLY ASK THE USER TO SAVE/OPEN PDF
        'Response.Buffer = True
        'Response.Clear()
        'Response.ContentType = mimeType
        'Response.AddHeader("content-disposition", "inline; filename=" & filename & "." & extension)
        'Response.BinaryWrite(bytes)
        'Response.Flush()

        ' ***** OPEN PDF AS NEW WEB PAGE
        'Response.BufferOutput = True
        'Response.ClearContent()
        'Response.ClearHeaders()
        'Response.ContentType = mimeType
        'Response.AddHeader("Content-Length", bytes.Length.ToString)
        'Response.AddHeader("content-disposition", "inline;filename=PayDetail.pdf")
        'Response.ContentType = "applicatin/pdf"
        'Response.BinaryWrite(bytes)
        'Response.Flush()
        'Response.Clear()

I have tried turning the PDF into an image and display, but received nothing in the image box. Tried that using:

        Dim base64String As String = Convert.ToBase64String(bytes, 0, bytes.Length)

        Image1.ImageUrl = "data:image/png;base64," & base64String

        Image1.Visible = True

解决方案

First, create a Generic Handler called GeneratePDF.ashx. Note I didn't write the below code and I'm not a VB.NET programmer, so I can't guarantee it'll work.

'generate bytes, perhaps based on Request.QueryString parameters
`write bytes to output
Response.Buffer = True
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "inline; filename=" & filename & "." & extension)
Response.BinaryWrite(bytes)
Response.Flush()

Then on our page, we use one of the techiques from the below link to embed the PDF, making sure to give the URL that points to our generic handler, and passing any parameters needed to generate the PDF via query string.

<embed src="GeneratePDF.ashx?parameter1=asdf&parameter2=qwer" width="500" height="375" type="application/pdf" />

Above code adapted from Recommended way to embed PDF in HTML?

这篇关于到的ReportViewer DIV /图像/对象中的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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