kompellamurthy wrote:
I want the code for convert a pdf page to a bit map.
PDFSharp can not render pdf files. You can use the PDFLibNet.dll which can be downloaded from "http://code.google.com/p/pdfviewer-win32/downloads/list". Here's a piece of code that will save the rasterized images to a subfolder:
Code:
Private Sub RasterizePDFToPNGs(ByVal SourcePDFPath As String)
Dim DestFile As String = IO.Path.GetFileNameWithoutExtension(SourcePDFPath)
Dim DestFolder As String = IO.Path.Combine(IO.Path.GetDirectoryName(SourcePDFPath), DestFile)
If System.IO.Directory.Exists(DestFolder) = False Then
System.IO.Directory.CreateDirectory(DestFolder)
End If
Dim SourcePDF As New PDFLibNet.PDFWrapper()
SourcePDF.LoadPDF(SourcePDFPath)
SourcePDF.RenderDPI = 300
For i As Integer = 1 To SourcePDF.PageCount
SourcePDF.CurrentPage = i
Dim pic As New PictureBox()
SourcePDF.RenderPage(pic.Handle)
Dim SinglePageBMP As New Bitmap(SourcePDF.PageWidth, SourcePDF.PageHeight)
Dim g As Graphics = Graphics.FromImage(SinglePageBMP)
Dim bounds As New Rectangle(0, 0, SourcePDF.PageWidth, SourcePDF.PageHeight)
SourcePDF.ClientBounds = bounds
SourcePDF.CurrentX = 0
SourcePDF.CurrentY = 0
SourcePDF.DrawPageHDC(g.GetHdc)
g.ReleaseHdc()
Dim DestinationPath As String = IO.Path.Combine(DestFolder, DestFile & " " & Format(i, "0000") & ".png")
SinglePageBMP.Save(DestinationPath, Drawing.Imaging.ImageFormat.Png)
System.Threading.Thread.Sleep(100)
Next
End Sub