We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert Pdf to image - image size is not readable

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();

Hi Nathyia,


Thanks for your inquriy. We will appreciate it if you please share your sample input and output documents here, so we will look into it and will guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Hi,


Here i have attached the sample files like pdf and generated image files.
When we are zooming the image looks good but while printing it on the Onenote it prints the actual size.

Regards,
Nathiya

Hi Nathyia,


Thanks for sharing the resource files.

When viewing the resultant images in Microsoft Image and Fax viewer, the files are displayed at default zoom level and when using MS Paint to view the image file, the file contents are displayed at larger zoom level. In case I have not properly understood your problem or you have any further query, please feel free to contact.