首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AxAcroPdf控制-重新加载PDF的问题

AxAcroPdf控制-重新加载PDF的问题
EN

Stack Overflow用户
提问于 2013-08-20 15:22:02
回答 1查看 3.3K关注 0票数 1

在我的Windows应用程序中使用axAcroPdfLib.AxAcroPDF控件时,我无法重新加载相同的图像。图像最初使用LoadFile()方法加载。

  1. 在保存对PDF的更改后,在相同的路径上再次使用LoadFile()方法时,控件变为空白(未显示PDF )。
  2. 如果我将控件的src属性设置为路径,则会收到一条消息,说明该文件不以'%PDF-‘开头。但确实如此。我用Word打开它,它显然以%PDF-开始。它也不腐败也不上锁。
  3. 我甚至尝试关闭、处理或将其设置为空,然后像第一次加载时那样完全重新实例化它--没有效果。窗口关闭并显示为空白控件。
  4. 通过上述方法加载不同的文件具有相同的效果-空白。

使用Windows 7 64位,VS 2010,VB.NET.

代码在下面。现在,我只是想给它划一条简单的界线。

代码语言:javascript
复制
Private Sub _btnBarCode_Click(ByVal sender As Object, ByVal e As EventArgs) Handles _btnBarCode.Click
    Dim pdfReader As iTextSharp.text.pdf.PdfReader = Nothing

    Try
        pdfReader = New iTextSharp.text.pdf.PdfReader(File.ReadAllBytes(_path))

        Using fs As New FileStream(_path, FileMode.Create, FileAccess.Write)
            Using pdfStamper = New iTextSharp.text.pdf.PdfStamper(pdfReader, fs)
                Dim pdfPage As iTextSharp.text.pdf.PdfContentByte = pdfStamper.GetOverContent(1)

                Using barCodeForm As New FBarCode
                    barCodeForm.Barcode = _barCode
                    If (barCodeForm.ShowDialog(Me) = DialogResult.OK) Then

                        Dim screenBarCode As Point = barCodeForm.Location
                        Dim clientBarCode As Point = Point.op_Subtraction(PointToClient(screenBarCode), New Point(0, 50)) '_pdfControl.Location '_imgView.Location
                        clientBarCode = New Point(10, 50)

                        Dim barcodeImg As New Bitmap(200, 50)
                        Using gc As Graphics = Graphics.FromImage(barcodeImg)
                            gc.DrawLine(Pens.Red, New Point(10, 10), New Point(20, 20))
                            'barCodeForm._barCode.DrawBarCode(gc, clientBarCode)
                        End Using

                        Dim convert As ImageConverter = New ImageConverter()
                        Dim bmpBytes As Byte() = DirectCast(convert.ConvertTo(barcodeImg, GetType(Byte())), Byte())
                        Dim thisImage As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(bmpBytes)
                        thisImage.SetAbsolutePosition(clientBarCode.X, clientBarCode.Y)
                        thisImage.SetDpi(72, 72)

                        pdfPage.AddImage(thisImage)

                        rdrAdobePdf.LoadFile(_path) 'Blank pdf
                        'rdrAdobePdf.src = _path '"Does not begin with '%PDF-' (even though it does)

                        'Me.Close()
                        '_myParent.ResetPdfViewer()
                        'ReloadPdfViewer(Me.Barcode)

                    End If
                End Using
            End Using
        End Using

    Catch ex As Exception
        MessageBox.Show(ex.Message, "An error occurred.")
        Return
    Finally
        If Not pdfReader Is Nothing Then pdfReader.Close()
    End Try

End Sub

有什么想法吗?这里有什么问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-21 21:12:21

通过从单击方法中获取重新加载代码解决了问题。将其放入另一个单击方法解决了问题--不确定原因。我使用的代码只运行.LoadFile,然后运行Form.Show()Form.Activate()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18338924

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档