使用PdfSharp.dll在vb.net中隐藏Pdf到Tiff文件

时间:2010-11-02 10:05:29

标签: vb.net visual-studio-2010

我正在使用Pdfsharp.dll将tiff图像转换为vb.net中的pdf文件,并且当我在我的机器上运行时它是成功的,当我从其他机器使用它时,它显示错误,如“原始字符串包含无效”值> 255的字符。“,请任何人帮我修复错误, 我使用PdfSharp.dll库和以下代码

    Dim objDoc As PdfDocument
    Dim objPdfPage As PdfPage
    Dim objTiffImg As Image
    Dim objXImg As XImage
    Dim iPageCount As Integer
    Dim objXgr As XGraphics
    Dim sPdfFile As String = Nothing
    Dim objDir As DirectoryInfo
    Dim objFile As FileInfo()
    Dim objFileInfo As FileInfo

    Try
        objTiffImageSpliter = New TiffImageSplitter()
        objDoc = New PdfDocument
        iPageCount = objTiffImageSpliter.GetPageCount(sFileName)

        For iCount As Integer = 0 To iPageCount - 1
            objPdfPage = New PdfPage
            objTiffImg = objTiffImageSpliter.getTiffImage(sFileName, iCount)
            objXImg = XImage.FromGdiPlusImage(objTiffImg)
            'objPdfPage.Height = objXImg.PointWidth
            'objPdfPage.Width = objXImg.PointHeight
            objDoc.Pages.Add(objPdfPage)
            objXgr = XGraphics.FromPdfPage(objDoc.Pages(iCount))
            objXgr.DrawImage(objXImg, 10, 10)
        Next
        sPdfFile = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\MY_FaxFile\"

        If System.IO.Directory.Exists(sPdfFile) Then
            objDir = New DirectoryInfo(sPdfFile)
            objFile = objDir.GetFiles()

            For Each objFileInfo In objFile
                objFileInfo.Delete()
            Next

            sPdfFile &= "MyFax.pdf"
        Else
            System.IO.Directory.CreateDirectory(sPdfFile)
            sPdfFile &= "MyFax.pdf"
        End If

       objDoc.Save(sPdfFile)   ' This Line shows the Error.
        objDoc.Close()
    Catch ex As Exception
        MsgBox(ex.ToString)
        sPdfFile = Nothing
    End Try

    Return sPdfFile

1 个答案:

答案 0 :(得分:0)

我不熟悉这个库,但根据你的代码和错误信息,我猜你的App Data文件夹包含非ASCII字符,并且PdfSharp库不支持文件名中的非ASCII字符。