Hi,
Is there any way to create the thumbnail of PDF document? Is there any ready-made function available?
Thumbnail of PDF Document
Hello,
The Amyuni PDF Creator.NET includes a control which will allow you to display PDF documents as thumbnails.
However if wish to draw a PDF document as a small thumbnail and display on your own control, then you can use the DrawCurrentPage() method.
This is detail in the documentation provided with the product.
Hope this helps?
The Amyuni PDF Creator.NET includes a control which will allow you to display PDF documents as thumbnails.
However if wish to draw a PDF document as a small thumbnail and display on your own control, then you can use the DrawCurrentPage() method.
This is detail in the documentation provided with the product.
Hope this helps?
-
- Posts: 19
- Joined: Fri Jan 12 2007
Thumbnail of pdf document
Hi..I am trying to get a Thumbnail image for the first page of a pdf document. As per your suggestion I have worked out the following code in VB.NET, but it is not working...I am getting a blank image file..any suggestions as to why is this so...and how can I fix it.....
acPDFCreatorLib.Initialize()
Dim file1 As System.IO.FileStream = New System.IO.FileStream("sopan2.pdf", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
If PdfCreator.Document.Open(file1, "") = True Then
PdfCreator.Document.CurrentPage = PdfCreator.Document.GetPage(1)
img = New Bitmap(250, 400)
Dim g As Graphics = Graphics.FromImage(img)
Dim hdc As IntPtr = g.GetHdc()
PdfCreator.DrawCurrentPage(hdc, False)
file1.Close()
img.Save("test.jpg", system.Drawing.Imaging.ImageFormat.Jpeg)
MsgBox("Completed")
Else
MsgBox("Unable to open file")
End If
acPDFCreatorLib.Terminate()
Your quick reply would be highly appreciated.
Thanks n Rgds
acPDFCreatorLib.Initialize()
Dim file1 As System.IO.FileStream = New System.IO.FileStream("sopan2.pdf", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
If PdfCreator.Document.Open(file1, "") = True Then
PdfCreator.Document.CurrentPage = PdfCreator.Document.GetPage(1)
img = New Bitmap(250, 400)
Dim g As Graphics = Graphics.FromImage(img)
Dim hdc As IntPtr = g.GetHdc()
PdfCreator.DrawCurrentPage(hdc, False)
file1.Close()
img.Save("test.jpg", system.Drawing.Imaging.ImageFormat.Jpeg)
MsgBox("Completed")
Else
MsgBox("Unable to open file")
End If
acPDFCreatorLib.Terminate()
Your quick reply would be highly appreciated.
Thanks n Rgds
Hello,
Below is a revised VB.net code that should help you:
Private Sub btnDrawCurrentPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDrawCurrentPage.Click
Dim img As Bitmap
acPDFCreatorLib.Initialize()
Dim file1 As System.IO.FileStream = New System.IO.FileStream("c:\temp\image.pdf", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
If PdfCreator.Document.Open(file1, "") = True Then
PdfCreator.Document.ZoomFactor = 40
PdfCreator.Document.CurrentPage = PdfCreator.Document.GetPage(1)
img = New Bitmap(200, 250)
Dim c As Graphics = Graphics.FromImage(img)
'//********
'clear color
c.Clear(Color.White)
Dim hdc As IntPtr = c.GetHdc()
PdfCreator.DrawCurrentPage(hdc, True)
file1.Close()
'CleanUp
c.ReleaseHdc(hdc)
img.Save("c:\temp\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
MsgBox("Completed")
Else
MsgBox("Unable to open file")
End If
'This call should only be once when you application
'ends
'acPDFCreatorLib.Terminate()
End Sub
Below is a revised VB.net code that should help you:
Private Sub btnDrawCurrentPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDrawCurrentPage.Click
Dim img As Bitmap
acPDFCreatorLib.Initialize()
Dim file1 As System.IO.FileStream = New System.IO.FileStream("c:\temp\image.pdf", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
If PdfCreator.Document.Open(file1, "") = True Then
PdfCreator.Document.ZoomFactor = 40
PdfCreator.Document.CurrentPage = PdfCreator.Document.GetPage(1)
img = New Bitmap(200, 250)
Dim c As Graphics = Graphics.FromImage(img)
'//********
'clear color
c.Clear(Color.White)
Dim hdc As IntPtr = c.GetHdc()
PdfCreator.DrawCurrentPage(hdc, True)
file1.Close()
'CleanUp
c.ReleaseHdc(hdc)
img.Save("c:\temp\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
MsgBox("Completed")
Else
MsgBox("Unable to open file")
End If
'This call should only be once when you application
'ends
'acPDFCreatorLib.Terminate()
End Sub
-
- Posts: 19
- Joined: Fri Jan 12 2007
Thumbnail of a pdf document
Thanks for your reply....
Now I want to implement the same using the PDF creator library, instead of the pdf creator control...I have worked out the following code..but I am getting a blank image....
Dim img As Image
Try
acPDFCreatorLib.Initialize()
Dim file1 As System.IO.FileStream = New System.IO.FileStream("sopan2.pdf", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
Dim doc As IacDocument = New IacDocument
If doc.Open(file1, "") = True Then
doc.CurrentPage = doc.GetPage(1)
img = New Bitmap(250, 400)
Dim g As Graphics = Graphics.FromImage(img)
Dim hdc As IntPtr = g.GetHdc()
doc.DrawCurrentPage(hdc.ToInt64, False)
Application.DoEvents()
g.ReleaseHdc(hdc)
img.Save("test2.jpg", system.Drawing.Imaging.ImageFormat.Jpeg)
MsgBox("Completed")
Else
MsgBox("Unable to open file")
End If
acPDFCreatorLib.Terminate()
end try
Thanks a ton for your help...
Now I want to implement the same using the PDF creator library, instead of the pdf creator control...I have worked out the following code..but I am getting a blank image....
Dim img As Image
Try
acPDFCreatorLib.Initialize()
Dim file1 As System.IO.FileStream = New System.IO.FileStream("sopan2.pdf", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
Dim doc As IacDocument = New IacDocument
If doc.Open(file1, "") = True Then
doc.CurrentPage = doc.GetPage(1)
img = New Bitmap(250, 400)
Dim g As Graphics = Graphics.FromImage(img)
Dim hdc As IntPtr = g.GetHdc()
doc.DrawCurrentPage(hdc.ToInt64, False)
Application.DoEvents()
g.ReleaseHdc(hdc)
img.Save("test2.jpg", system.Drawing.Imaging.ImageFormat.Jpeg)
MsgBox("Completed")
Else
MsgBox("Unable to open file")
End If
acPDFCreatorLib.Terminate()
end try
Thanks a ton for your help...
-
- Posts: 19
- Joined: Fri Jan 12 2007
Thumbnail of PDF document
hi...I have managed to get it done by using pdf creator library.Following is the code...
Dim file1 As System.IO.FileStream = New System.IO.FileStream("Sopan2.pdf", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
Dim doc As IacDocument = New IacDocument
doc.Open(file1, "")
doc.ZoomFactor = 40
doc.CurrentPage = doc.GetPage(1)
Dim pg As Amyuni.PDFCreator.IacPageFormat = doc.GetPageFormat()
Dim img As New Bitmap(CInt(pg.Width / 40), CInt(pg.Length / 40))
Dim g As Graphics = Graphics.FromImage(img)
g.Clear(Color.White)
Dim hdc As IntPtr = g.GetHdc()
doc.DrawCurrentPage(hdc.ToInt64, True)
Application.DoEvents()
g.ReleaseHdc(hdc)
file1.Close()
img.Save("test2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
Application.DoEvents()
MsgBox("Completed")
Now I am facing problems with the size of pdf pages...In my pdf files the size of each page varies...but Pageformat.length or pageformat.width doesnot give me the correct value.Hence I dont get the complete thumbnail image ....pls help....
Thanks n Rgds
Dim file1 As System.IO.FileStream = New System.IO.FileStream("Sopan2.pdf", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
Dim doc As IacDocument = New IacDocument
doc.Open(file1, "")
doc.ZoomFactor = 40
doc.CurrentPage = doc.GetPage(1)
Dim pg As Amyuni.PDFCreator.IacPageFormat = doc.GetPageFormat()
Dim img As New Bitmap(CInt(pg.Width / 40), CInt(pg.Length / 40))
Dim g As Graphics = Graphics.FromImage(img)
g.Clear(Color.White)
Dim hdc As IntPtr = g.GetHdc()
doc.DrawCurrentPage(hdc.ToInt64, True)
Application.DoEvents()
g.ReleaseHdc(hdc)
file1.Close()
img.Save("test2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
Application.DoEvents()
MsgBox("Completed")
Now I am facing problems with the size of pdf pages...In my pdf files the size of each page varies...but Pageformat.length or pageformat.width doesnot give me the correct value.Hence I dont get the complete thumbnail image ....pls help....
Thanks n Rgds