I have several PDF files I am trying to convert to PNG. Many of them work but many do not. I am calling PdfConverter.GetNextImage and getting a Parameter Not Valid Error. I will attach a code sample below. The file TestPDF.pdf does not work but the other one does. Any ideas why? An update to this - I tried the Aspose.Pdf.Devices.PngDevice method found on your website and I am getting the same exact issue.
converter = New PdfConverter()
converter.BindPdf(tempFilePath)
converter.DoConvert()
Dim height As Integer = converter.Document.Pages(1).Rect.Height
Dim width As Integer = converter.Document.Pages(1).Rect.Width
Dim percent As Decimal
If height > 400 Then
percent = 400 / height
height = height * percent
width = width * percent
End If
If width > 400 Then
percent = 400 / width
height = height * percent
width = width * percent
End If
If converter.HasNextImage() Then
Try
converter.GetNextImage(u.EndsWith(tempFolderPath) & thumbnailFileName, ImageFormat.Png, width, height)
'Pass back a link to the created PNG file for use in the project files list.
item("PDFLink") = u.EndsWith(u.GetAppSetting("PublicSiteAddress"), "/") & tempShortPath & "/" & thumbnailFileName
Catch ex As Exception
'Failed the conversion so just move on.
'Pass back a link to the created PNG file for use in the project files list.
item("PDFLink") = ""
File.Delete(u.EndsWith(tempFolderPath) & thumbnailFileName)
End Try
End If
M731-48832-New-Build-Postcard_v03-ma.pdf (634.7 KB)
TestPDF.pdf (1.3 MB)
@geiger.greg
We have used below code snippet with 24.5 version of the API and could not notice any issues.
Document pdfDocument = new Document(dataDir + "TestPDF.pdf");
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
string tmpImgToInsert = DateTime.Now.Ticks + ".png";
using (FileStream imageStream = new FileStream(dataDir + tmpImgToInsert, FileMode.Create))
{
var pngDevice = new PngDevice(new Resolution(300))
{
RenderingOptions = new RenderingOptions()
{
UseFontHinting = true,
//OptimizeDimensions = true,
//InterpolationHighQuality = true,
//UseNewImagingEngine = true
}
};
pngDevice.Process(pdfDocument.Pages[pageCount], imageStream);
imageStream.Close();
}
}
638810529106690153.png (395.7 KB)
638810529019469898.jpg (255.9 KB)
Would you please try using the above code with the latest version of the API and if you still face any issues, please let us know.
I have version 24.01 of the API - I am not sure our license covers downloading a new version. Is there any chance you can try it with version 24.01 and see if it fails for you there? I added the UseFontHinting option and it still failed.
Dim pngDevice As New Aspose.Pdf.Devices.PngDevice(width, height)
pngDevice.RenderingOptions.UseFontHinting = True
Dim imageStream As New FileStream(u.EndsWith(tempFolderPath) & thumbnailFileName, FileMode.Create)
Try
pngDevice.Process(doc.Pages(1), imageStream)
imageStream.Close()
'Pass back a link to the created PNG file for use in the project files list.
item("PDFLink") = u.EndsWith(u.GetAppSetting("PublicSiteAddress"), "/") & tempShortPath & "/" & thumbnailFileName
Catch ex As Exception
'Failed the conversion so just move on.
'Pass back a link to the created PNG file for use in the project files list.
imageStream.Close()
item(“PDFLink”) = “”
File.Delete(u.EndsWith(tempFolderPath) & thumbnailFileName)
End Try
Update here - I tried it with resolution = 300 and it worked! I do want to downsize it a bit though and when I was using width and height that’s when it said the parameter was not valid. Do you know if there is any way I can size it down for storage savings as well as size?
Dim resolution As New Aspose.Pdf.Devices.Resolution(300)
Dim pngDevice As New Aspose.Pdf.Devices.PngDevice(resolution)
@geiger.greg
What are the exact values of the height and width that you are trying to convert with?
Here is the code I am trying to use that is giving the Parameter Not Valid error:
width = 311
height = 400
Dim resolution As New Aspose.Pdf.Devices.Resolution(150)
Dim pngDevice As New Aspose.Pdf.Devices.PngDevice(width, height, resolution)
pngDevice.RenderingOptions.UseFontHinting = True
pngDevice.Process(doc.Pages(1), u.EndsWith(tempFolderPath) & thumbnailFileName)
@geiger.greg
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-59770
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.