2010-11-02 49 views
1

我正在使用Pdfsharp.dll将tiff图像转换为vb.net中的pdf文件,并且当我在我的机器上运行时,它是成功的,当我使用它时其他机器,这表明类似错误“原始字符串包含无效字符值> 255”,请任何一个可以帮助我解决错误, 我使用PdfSharp.dll库和下面的代码PDF到TIFF文件隐藏在vb.net中使用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 
+0

您是否尝试排除无效文件名称(sPdfFile)的可能性? – Prutswonder 2010-11-02 10:10:36

+0

嗨Prutswonder谢谢你的回复, – 2010-11-02 12:13:38

+0

我不清楚无效的文件名,你可以请exlain .. – 2010-11-02 12:15:15

回答

0

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

+0

我使用路径“C:\ Documents and Settings \ senthilkumar \ Application Data \ My_FaxFile \ MyFax.pdf,它不包含non_ASCII – 2010-11-02 15:32:55