2010-11-02 47 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