返回首页

。 您好所有,
我在我的ASP.NET Web应用程序有一个aspx页面称为"Export_Report.aspx的"
当我执行页的报告,我要生成了显示
perfectly.The报告包含大量文字,标签,位图图像,图表等信息现在,当我导出Microsoft Word文档中,我得到了,除了images.To克服这个问题,我决定将信息导出所有数据"PDF格式"document.And我公司开发的代码如下:

Public Sub exportpdf()

        Try

            Dim pdfBody As New StringBuilder

            pdfBody.Append("<html " & _

                                              "DDX xmlns='http://ns.adobe.com/DDX/1.0/'" & _

                                              "xmlns:xsi = 'http://www.w3.org/2001/XMLSchema-instance'" & _

                                              "xsi:schemaLocation='http://ns.adobe.com/DDX/1.0/ coldfusion_ddx.xsd' " & _

                                              "<head><title>Project NoteBook</title>")

            Dim dtCurrDate As Date

            If Not Session("CurrentClientDate") Is Nothing Then

                dtCurrDate = CDate(Session("CurrentClientDate"))

            Else

                dtCurrDate = Now()

            End If

            pdfBody.Append("<!--[if gte adobe 9]>" & _

                                "<xml>" & _

                                "<adobe:DocumentProperties><adobe:Author>Planstrat.</adobe:Author>" & _

                                "<adobe:LastAuthor>Planstrat.</adobe:LastAuthor>" & _

                                "<adobe:Created>" & dtCurrDate & "<adobe:Created>" & _

                                "<adobe:LastSaved>" & dtCurrDate & "</adobe:LastSaved>" & _

                                "</adobe:DocumentProperties>" & _

                                "</xml><![endif]--><!--[if gte adobe 9]><xml>" & _

                                "<w:WordDocument>" & _

                                "<w:View>Web</w:View>" & _

                                "<w:DocumentKind>DocumentLetter</w:DocumentKind>" & _

                                "<w:Zoom>100</w:Zoom>" & _

                                "<w:DoNotOptimizeForBrowser/>" & _

                                "</w:WordDocument>" & _

                                "</xml>" & _

                                "<![endif]-->")

 

            pdfBody.Append("<style>" & _

                                          "<!-- /* Style Definitions */" & _

                                    "p.pdfFooter, li.pdfFooter, div.pdfFooter" & _

                                    "{margin:0in;" & _

                                    "margin-bottom:.0001pt;" & _

                                    "pdf-pagination:widow-orphan;" & _

                                    "tab-stops:right 3.0in;" & _

                                    "font-size:10.0pt;}")

            pdfBody.Append("" & _

                                            "<!-- /* Style Definitions */" & _

                                            "p.pdfFooter1, li.pdfFooter1, div.pdfFooter1" & _

                                            "{margin:0in;" & _

                                            "margin-bottom:.0001pt;" & _

                                             "pdf-pagination:widow-orphan;" & _

                                            "tab-stops:center 3.0in right 6.0in;" & _

                                            "font-size:10.0pt;}")

 



            pdfBody.Append("@page Section1" & _

                                "   {size:8.5in 11.0in; " & _

                                "   margin:1.0in 1.25in 1.0in 1.25in ; " & _

                                "   pdf-header-margin:.5in; " & _

                                "   pdf-footer: f2;" & _

                                "  pdf-normal:f3;" & _

                                "   pdf-footer-margin:.5in; pdf-paper-sourceBlush | :O ;}" & _

                                " div.Section1" & _

                                "   {page:Section1;}" & _

                                "-->" & _

                                "</style>" & _

                                "<xml>" & _

                                "<adobe:shapelayout v:ext='edit'>" & _

                                "<adobe:idmap v:ext='edit' data='1'/>" & _

                                "</adobe:shapelayout></xml>" & _

                                "</head>")

 

            pdfBody.Append("<body lang=EN-US style='tab-interval:.5in'>" & _

                           "<div  class=Section1 align='center'>")

            pdfBody.Append(hidExportTable.Value())

            pdfBody.Append("</DDX></div></body></html>")

 

            'strBody.Append("<div style='mso-element:footer' id=f2>" & _

            '           "<p class=MsoFooter><span style='mso-field-code:"" Author ""'>" & _

            '           "<span style='mso-no-proof:yes'>Planstrat Inc.India.</span></span>" & _

            '           "<span style='mso-tab-count:1'></span>Page<span style='mso-field-code:"" PAGE ""'></span>" & _

            '           "<span style='mso-tab-count:1'></span>" & _

            '           "<!--[if supportFields]><span style='mso-element:field-begin'></span> DATE \@ &quot;dd/MM/yyyy&quot;" & _

            '           "<span style='mso-element:field-separator'></span>" & _

            '           "<![endif]--><!--[if supportFields]><span style='mso-element:field-end'></span>" & _

            '           "<![endif]--></p></div></body></html>")

 



            'Force this content to be downloaded

            'as a Word document with the name of your choice

            Response.AppendHeader("Content-Type", "application/adobe")

            Response.AppendHeader("Content-disposition", _

            "attachment; filename=" & Session("proj_name") & " Project Status " & Format(dtCurrDate, "MMM-dd-yyyy") & ".pdf")

            Response.Write(pdfBody.ToString())

            hidExportTable.Value = ""

 

        Catch ex As Exception

            Response.Write("<script>alert('" & ex.Message() & "');</script>")

        End Try

    End Sub

End Class

之后,我得到了导出"PDF"档,但同时开放,PDF文件,我得到以下错误消息:

";无法打开"工程Status.pdf"的,因为它是不支持的文件类型或者因为文件已损坏(例如发送电子邮件附件并没有被正确解码)"

因此,任何人都可以提出我的解决方案,或任何其他的方法来ovecome,或创建PDF文件一步一步的另一种方式。

帮我
提前感谢

yogesh

回答

评论会员: 时间:2