亲爱的我已经在vb.net和asp.net应用程序中创建了一个函数,其中
从前端(1) - ,用户选择页面中列出的多个文件名(通过复选框)(list.aspx)并单击导出按钮以在一个pdf中查看所有文档文件(2) - 系统从数据库中获取这些文件,(3) - 系统将它们转换为pdf文件格式并(4) - 系统将这些pdf文件合并到一个pdf文件中,(5) - 系统在iframe中理想地显示它。
当list.aspx页面中有人点击导出cv时,它会执行此代码
window.location.href = 'export-cvs.aspx?v=' + vid + '&a=' + appids.toString();
在export-cvs.aspx页面中执行以下代码
<object id="cvFrame" width="100%" height="500px" type="application/pdf" data="preview-bulk-cv.ashx?v=<%= Vacancy.ID%>&a=<%= Request("a") %>"></object>
主要代码位于preview-bulk-cv.ashx页面中,如下所示。
Public Class PDFMerge : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim vacancy = New Vacancy(context.Request("v"))
Dim sourceFiles = New List(Of String)()
For Each docPath As String In From row As DataRow In DB.GetData("query").Rows Select HttpContext.Current.Server.MapPath("~/documents") & "\" & Left(guid, 1) & "\" & Right(guid, 1) & "\" & guid & "." & System.IO.Path.GetExtension(row.Item("originalfilename")).ToLower().Substring(1)
cnt+=1
Dim epath As String = HttpContext.Current.Server.MapPath("~/Downloads") & "\" & Now.ToString("yyyy-MMM-dd-HHmmss") & "_" & cnt.Tostring & ".pdf"
Converter.ConvertDocument(docPath, epath)
If File.Exists(epath) Then
sourceFiles.Add(epath)
End If
Next
Dim OutputFileName As String = HttpContext.Current.Server.MapPath("~/Downloads") & "\" & vacancy.Title.Replace(" ", "_") & ".pdf"
PDFMerge.MergeFiles(OutputFileName, sourceFiles.ToArray)
Dim mPDFFile As FileStream = File.OpenRead(OutputFileName)
Dim mPDFFileBuffer(mPDFFile.Length - 1) As Byte
mPDFFile.Read(mPDFFileBuffer, 0, mPDFFileBuffer.Length)
mPDFFile.Close()
System.Diagnostics.Process.Start(OutputFileName)
context.Response.Clear()
context.Response.ContentType = "application/pdf"
context.Response.AddHeader("Content-Disposition", "attachment;filename=" & OutputFileName)
context.Response.AddHeader("Content-Length", mPDFFileBuffer.Length)
context.Response.OutputStream.Write(mPDFFileBuffer, 0, mPDFFileBuffer.Length)
mPDFFileBuffer = Nothing
context.Response.Flush()
context.Response.End()
End Sub
End Class
您可以在上面的代码中看到。我使用以下行打开最终的pdf文档。
System.Diagnostics.Process.Start(OutputFileName)
此代码在本地服务器中运行,但在Web服务器中不起作用。即在我在localhost上运行应用程序时打开pdf文件。但是当应用程序存储在Web服务器上并且web应用程序作为来自任何计算机的web应用程序运行时,pdf文件不会打开。我已经在网络服务器中检查了正确创建的文件在正确的文件夹中合并。
网络服务器是用windows构建的。它的Windows版本2008 r2和IIS版本7.5
我怎样才能让它发挥作用?
答案 0 :(得分:1)
我知道这个例子是C#,但这里有一个链接,演示了如何将PDF流式传输到浏览器。 http://support.microsoft.com/kb/306654
您也可以调查Response.WriteFile()以查看它是否符合您的需求。