Dim page As New iTextSharp.text.Rectangle(683, 850)
        Dim doc As New iTextSharp.text.Document(page, 50, 50, 50, 50)
        Dim filename As String = "software-logo"        Dim fs As New FileStream("D:\DSSBDebt\Develop\IVWeb\App_Report\ZIP\software-logo.pdf", FileMode.Open)
        Dim bytPdfData As [Byte]() = New [Byte](fs.Length) {}
        Dim strRead As BinaryReader = New BinaryReader(fs)
        strRead.Read(bytPdfData, 0, bytPdfData.Length - 1)
        Dim mspdfData As MemoryStream = New MemoryStream(bytPdfData)
        Dim writer As PdfWriter = PdfWriter.GetInstance(doc, mspdfData)        PdfWriter.GetInstance(doc, fs)        doc.Open()        Response.Clear()
        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = "application/pdf"
        Response.Charset = String.Empty
        Response.Cache.SetCacheability(System.Web.HttpCacheability.Public)
        Response.AddHeader("Content-Disposition", "inline; filename=" + filename.Replace(" ", "").Replace(":", "-") + ".pdf")
        Response.OutputStream.Write(bytPdfData, 0, bytPdfData.Length)
        Response.OutputStream.Flush()
        Response.OutputStream.Close()
        Dim script As String
        script = ("this.print({bUI: true,bSilent: true,bShrinkToFit: false});")
        writer.ViewerPreferences = PdfWriter.HideWindowUI
        writer.AddJavaScript(script.ToString())        fs.Flush()
        fs.Close()

解决方案 »

  1.   

    觉得应该是你读的那个pdf文件地方可能有问题。
    没读出来东西吧
      

  2.   

    路径没问题的啊,如果路径有问题,肯定在这句就出错了:
    Dim fs As New FileStream("D:\DSSBDebt\Develop\IVWeb\App_Report\ZIP\software-logo.pdf", FileMode.Open)问题是现在程序正常走完了,但是打印出来的是空白页啊!!
      

  3.   

    打印PDF
      

  4.   

    Dim fs As New FileStream(@"D:\DSSBDebt\Develop\IVWeb\App_Report\ZIP\software-logo.pdf", FileMode.Open)
      

  5.   

    vb里面支持这种写法吗?谢谢各位的回复!
    我把itextsharp的 VB.NET 的案例下下来看了,都是先建一个pdf文件,向里面写入打印的javascript之后,打开该pdf会自动提示用户是否打印的信息。代码如下:
    Console.WriteLine("Chapter 11 example 6: javascript")
    Dim document As Document = New Document(PageSize.A4, 50, 50, 50, 50)
    Try
                    Dim writer As PdfWriter = PdfWriter.GetInstance(document, New FileStream("Chap1106.pdf", FileMode.Create))
    document.Open
    Dim jAction As PdfAction = PdfAction.JavaScript("this.print(true);" & Microsoft.VisualBasic.Chr(13) & "", writer)
    writer.AddJavaScript(jAction)
                    document.Add(New Paragraph("Page 1"))
                    Console.Read()
    Catch de As Exception
    Console.Error.WriteLine(de.Message)
    Console.Error.WriteLine(de.StackTrace)
    End Try
    document.Close因为我已经有了pdf文件不需要新建,将下面这两行注释掉了。
                    'document.Add(New Paragraph("Page 1"))
    'document.Close
    这样写入了javascript之后,打开pdf文件会报“开启此文件时出错。文件已损坏且无法修复”的错。现在我的问题是,怎么把打印pdf的javascript写入已有的pdf之中。
    麻烦有这方面的经验的XDJM看看啊!没有这方面经验的进来捧捧场啊!!!
      

  6.   

    用StreamReader读取pdf文件,然后写入另一个pdf里
    具体怎么用的你查下网站
      

  7.   


    已经正在往这个方向考虑了,能将javascript写入到新生成的pdf里面。现在正在调模板比率来控制打印的边框。谢谢!!!