PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Jul 20, 2024 7:33 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: PDF To Bmp
PostPosted: Thu Aug 11, 2011 12:44 pm 
Offline

Joined: Wed Jun 08, 2011 1:47 am
Posts: 4
Hi,

I want the code for convert a pdf page to a bit map. Please help me in this regard.

Thanks.


Top
 Profile  
Reply with quote  
 Post subject: Re: PDF To Bmp
PostPosted: Sun Aug 28, 2011 2:33 pm 
Offline

Joined: Sun Aug 28, 2011 2:23 pm
Posts: 2
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


Top
 Profile  
Reply with quote  
 Post subject: Re: PDF To Bmp
PostPosted: Mon Aug 29, 2011 2:56 am 
Offline

Joined: Wed Jun 08, 2011 1:47 am
Posts: 4
Thanks man.

Till now, I am doing the same conversion with other lib which is not free. This will really helped me. !!!

Thanks once again.

~<b>Kompella Murthy<b>.


Top
 Profile  
Reply with quote  
 Post subject: Re: PDF To Bmp
PostPosted: Mon Aug 29, 2011 6:02 am 
Offline

Joined: Wed Jun 08, 2011 1:47 am
Posts: 4
I am getting the an error icon displayed when i add the pdflibnet.dll as reference.

Can you please help in this regard.

Thanks
KompellaMurthy.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group