Hi, for which GhostScript.dll did you download? I tried your solution but I cannot get my Ghostscript dll (gsdll32.dll) to be added as a reference to my project as it's not a valid assembly or COM element.
Hi, for which GhostScript.dll did you download? I tried your solution but I cannot get my Ghostscript dll (gsdll32.dll) to be added as a reference to my project as it's not a valid assembly or COM element.
Annoying as it is, you can't reference the Ghostscript dll in a VS project. It has to be manually copied to the bin dir.
You most likely want GhostScriptSharp, which is available through NuGet.
jitendra2coo...
Member
27 Points
54 Posts
how to open(convert) pdf file in to image format at run time
Aug 03, 2012 11:59 AM|LINK
I have a view button, when it is clicked, I want to open a pdf file into image format at run time. (in C#, VS 2005)
How to perform this?
Pls provide sample code or references if possible.
Is it possible to do this without using 3rd party dll?
Thanks in advace.
kedarrkulkar...
All-Star
34545 Points
5554 Posts
Re: how to open(convert) pdf file in to image format at run time
Aug 03, 2012 12:04 PM|LINK
u have to use third part dll.... most common is iTextSharp... u can get plenty of resources regarding creating pdf in asp.net using iTextSharp...
one of them is here
http://www.mikesdotnetting.com/Article/87/iTextSharp-Working-with-images
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
jitendra2coo...
Member
27 Points
54 Posts
Re: how to open(convert) pdf file in to image format at run time
Aug 06, 2012 05:54 AM|LINK
Thanks for your reply.
I am more interested to know converting pdf to image at run time. I go through iTextSharp API article, but couldn't find a solution.
kedarrkulkar...
All-Star
34545 Points
5554 Posts
Re: how to open(convert) pdf file in to image format at run time
Aug 06, 2012 03:28 PM|LINK
try this
http://www.codeproject.com/Articles/28609/Converting-Image-Files-to-PDF
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
jitendra2coo...
Member
27 Points
54 Posts
Re: how to open(convert) pdf file in to image format at run time
Aug 08, 2012 08:51 AM|LINK
Thanks for reply.
I got the solution from http://cyotek.com/blog/convert-a-pdf-into-a-series-of-images-using-csharp-and-ghostscript with some modification.
protected void hl_click(object sender, EventArgs e)
{
Bitmap bm = new Cyotek.GhostScript.PdfConversion.Pdf2Image(Server.MapPath("Files/Sample.pdf")).GetImage();
Response.ContentType = "image/jpeg" ;
bm.Save(Response.OutputStream, ImageFormat.Jpeg);
}
hl is hyperlink on Default.aspx.
//Function in Pdf2Image.cs
public Bitmap GetImage(int pageNumber)
{
Bitmap result=null;
string workFile;
if (pageNumber < 1 || pageNumber > this.PageCount)
throw new ArgumentException("Page number is out of bounds", "pageNumber");
//workFile = Path.GetTempFileName();
//workFile=Path.GetDirectoryName(this._pdfFileName)+"\\TempFile.tmp";
try
{
for (int i = 1; i <= this.PageCount; i++)
{
workFile = Path.GetDirectoryName(this._pdfFileName) + "\\TempFile" + i + ".tmp";
this.ConvertPdfPageToImage(workFile, i);
using (FileStream stream = new FileStream(workFile, FileMode.Open, FileAccess.Read))
result = new Bitmap(stream);
}
}
finally
{
//File.Delete(workFile);
}
I have a pdf file of 6(multiple) pages. To covert it into image file, I have done above modification in GetImage(int pageNumber) of Pdf2Image.cs file.
Now I get the 6 .tmp files. But I want to combine all into one and dispaly at runtime.
Can any one suggest how to do this?
Currently I can display only one page at a time.
jitendra2coo...
Member
27 Points
54 Posts
Re: how to open(convert) pdf file in to image format at run time
Aug 09, 2012 12:11 PM|LINK
I have a pdf file of 6(multiple) pages. After converting to image, I get Bitmap[] arrray.
Bitmap[] bm = new Cyotek.GhostScript.PdfConversion.Pdf2Image(Server.MapPath("Files/Sample.pdf")).GetImages();
But I want to combine all into one and dispaly at runtime.
Can any one suggest how to do this?
Currently I can display only one page at a time.
wadewalker25
Member
242 Points
111 Posts
Re: how to open(convert) pdf file in to image format at run time
Jan 03, 2013 05:15 PM|LINK
Hi, for which GhostScript.dll did you download? I tried your solution but I cannot get my Ghostscript dll (gsdll32.dll) to be added as a reference to my project as it's not a valid assembly or COM element.
rossisdead2
Participant
1313 Points
300 Posts
Re: how to open(convert) pdf file in to image format at run time
Jan 08, 2013 01:09 PM|LINK
Annoying as it is, you can't reference the Ghostscript dll in a VS project. It has to be manually copied to the bin dir.
You most likely want GhostScriptSharp, which is available through NuGet.