i am trying to get the first page of a document(doc, pdf) and save it as jpeg image in an asp.net using C#
Thanks in advance
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Krishna Rajput SinghRank #605 · 4K reputationPosted Jul 16, 2016, 7:28 AM EDT
Lakshan Bindra4 reputationPosted Jul 21, 2016, 7:56 AM EDT
http://support.leadtools.com/SupportPortal/CS/forums/33017/showpost.aspx
http://stackoverflow.com/questions/6866110/how-to-convert-doc-to-jpg-in-net
Rahul PrasadRank #2,557 · 546 reputationPosted Jul 21, 2016, 5:38 PM EDT
SaveAsImage(intpageIndex, PdfImageType type,booldocumentTextIsEastAsiaFont,intdpiX,intdpiY)Marvin ReidRank #1,963 · 746 reputationPosted Jan 2, 2024, 11:09 AM EST
You can use the RasterCodecs class to save just the first page of your images. This includes support to office formats such as DOCX, Excel, as well as PDF. By default loading and saving your file with this code will only save the first page to jpeg. You can use this code:
using (RasterCodecs codecs = new RasterCodecs()) { RasterImage image = codecs.Load(@"Path to file input"); codecs.Save(image, @"Path to output file", RasterImageFormat.Jpeg411, 8); }https://www.leadtools.com/help/sdk/tutorials/dotnet-console-load-and-save-images.html
Ali BenchaabanRank #925 · 2.2K reputationPosted Jan 2, 2024, 2:55 PM EST
Hello,
You can install the Spire.Doc library.
using Spire.Doc; using System.Drawing; public void ConvertToJpeg(string inputFilePath, string outputFilePath) { Document doc = new Document(); doc.LoadFromFile(inputFilePath); // Extract the first page as an image Image image = doc.SaveToImages(0, Spire.Doc.Documents.ImageType.Bitmap); image.Save(outputFilePath, System.Drawing.Imaging.ImageFormat.Jpeg); image.Dispose(); }You can call the
ConvertToJpegmethod in your ASP.NET application as follows:string inputFilePath = @"path\to\your\document.docx"; string outputFilePath = @"path\to\save\image.jpg"; ConvertToJpeg(inputFilePath, outputFilePath);Regards,