Hi,
I am trying to convert pdf to image. But the image size is small and hard to read.
Please find the code below.
Document pdfDocument = new Document(@“C:\669579.PDF”);
string newTempImageFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + “\Images”;
SetAsposePdfLicense();
// Select desirable page size
float newPageWidth = 1200f;
float newPageHeight = 1200f;
// Tune PdfPageEditor class
Aspose.Pdf.Facades.PdfPageEditor pdfEditor = new Aspose.Pdf.Facades.PdfPageEditor();
// Bind source PDF file
pdfEditor.BindPdf(pdfDocument);
// Set the page dimensions
pdfEditor.PageSize = new Aspose.Pdf.PageSize(newPageWidth, newPageHeight+100);
// Set vertical alignment for page as center aligned
pdfEditor.VerticalAlignmentType = Aspose.Pdf.VerticalAlignment.Center;
// Set Horizontal alignment for page as center aligned
pdfEditor.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
// This scales page content to fit width,
// comment it out or set Zoom to 1.0F if You don’t want to scale
// content and only want to change page’s size (i.e. crop it)
float zoom = Math.Max((float)newPageWidth / (float)pdfEditor.Document.Pages[1].Rect.Width,
(float)newPageHeight / (float)pdfEditor.Document.Pages[1].Rect.Height);
pdfEditor.Zoom = zoom;
// Create stream object to hold file with updated dimensions
MemoryStream output = new MemoryStream();
// Save file to stream object
pdfEditor.Save(output);
FileStream file = new FileStream(newTempImageFolder + “\file3.pdf”, FileMode.Create, FileAccess.Write);
output.WriteTo(file);
file.Close();
// Then reload scaled document and save it to HTML
Document exportDoc = new Document(output);
// create resolution object
Resolution resolution = new Resolution(300);
for (int pagecount = 1; pagecount <= exportDoc.Pages.Count; pagecount++)
{
string imagePath = newTempImageFolder +
“\image” + pagecount + “.jpg”;
using (FileStream imagestream = new FileStream(imagePath, FileMode.Create))
{
// create jpeg device with specified attributes (width, height, resolution, quality)
// where quality [0-100], 100 is maximum
JpegDevice jpegdevice = new JpegDevice(resolution, 100);
// convert a particular page and save the image to stream
jpegdevice.Process(exportDoc.Pages[pagecount], imagestream);
// close stream
imagestream.Close();
}
}
// Close the stream object
output.Close();