2012-03-23 44 views

回答

1

iTextSharp應該處理該問題。第一圖像上的退出這裏

例如http://www.vbforums.com/showthread.php?t=530736

編輯:

從線程通過stanav

Public Shared Function ExtractImages(ByVal sourcePdf As String) As List(Of Image) 
    Dim imgList As New List(Of Image) 

    Dim raf As iTextSharp.text.pdf.RandomAccessFileOrArray = Nothing 
    Dim reader As iTextSharp.text.pdf.PdfReader = Nothing 
    Dim pdfObj As iTextSharp.text.pdf.PdfObject = Nothing 
    Dim pdfStrem As iTextSharp.text.pdf.PdfStream = Nothing 

    Try 
     raf = New iTextSharp.text.pdf.RandomAccessFileOrArray(sourcePdf) 
     reader = New iTextSharp.text.pdf.PdfReader(raf, Nothing) 

     For i As Integer = 0 To reader.XrefSize - 1 
      pdfObj = reader.GetPdfObject(i) 
      If Not IsNothing(pdfObj) AndAlso pdfObj.IsStream() Then 
       pdfStrem = DirectCast(pdfObj, iTextSharp.text.pdf.PdfStream) 
       Dim subtype As iTextSharp.text.pdf.PdfObject = pdfStrem.Get(iTextSharp.text.pdf.PdfName.SUBTYPE) 
       If Not IsNothing(subtype) AndAlso subtype.ToString = iTextSharp.text.pdf.PdfName.IMAGE.ToString Then 
        Dim bytes() As Byte = iTextSharp.text.pdf.PdfReader.GetStreamBytesRaw(CType(pdfStrem, iTextSharp.text.pdf.PRStream)) 
        If Not IsNothing(bytes) Then 
         Try 
          Using memStream As New System.IO.MemoryStream(bytes) 
           memStream.Position = 0 
           Dim img As Image = Image.FromStream(memStream) 
           imgList.Add(img) 
          End Using 
         Catch ex As Exception 
          'Most likely the image is in an unsupported format 
          'Do nothing 
          'You can add your own code to handle this exception if you want to 
         End Try 
        End If 
       End If 
      End If 
     Next 
     reader.Close() 
    Catch ex As Exception 
     MessageBox.Show(ex.Message) 
    End Try 
    Return imgList 
End Function 
+1

當你重定向到其他網頁(特別是線程)時要小心,因爲它們可能會在某個時候被刪除,你的答案將是無意義。你可以在回答中加入一些代碼,並把鏈接作爲參考:) – 2012-03-23 17:24:35

+0

tyvm huMpty的提示! – 2012-03-23 19:29:22

+0

什麼是我的意思是「對於我整數= 0到reader.XrefSize - 1」 – dhyabi 2012-03-23 19:37:18

0

你大概柵格化PDF的網頁複製的代碼。如果查找獲取圖像等,您將發現可以在PDF上執行的其他操作。有已發佈方式的list。我用ABCpdf很容易做到這一點。

0

您是否處於網絡環境或本地環境?它製造了巨大的差異。你想要的是將PDF光柵化成圖像。這很容易通過GhostDoc或類似工具在本地環境中執行。他們都使用虛擬打印機驅動程序來光柵化PDF。這種方法在Web環境中不適用,在這種環境中,您可能需要使用某些商業產品,因爲編寫自己的柵格化引擎是一項艱鉅的任務。

+0

我的意思是動態獲取圖像在asp.net中的c#程序或網頁的運行時 – dhyabi 2012-03-23 18:20:46

相關問題