I have an issue with certain single page PDFs not converting correctly. They end up black with kind of lines all over them. A few control PDFs render fine with the same code. Something in the PDF? I build a simple test. The 6359.PDF fails while the rest work. I'll attach the images and results. Here is the code:
Convert1PagePDF("D:\PDFRenderProblem\6359.PDF", "D:\PDFRenderProblem\6359.BMP")Convert1PagePDF(<span style="color: rgb(163, 21, 21);">"D:\PDFRenderProblem\cameronmoll_bio.pdf"</span>, <span style="color: rgb(163, 21, 21);">"D:\PDFRenderProblem\cameronmoll_bio.BMP"</span>) Convert1PagePDF(<span style="color: rgb(163, 21, 21);">"D:\PDFRenderProblem\viewpdf.pdf"</span>, <span style="color: rgb(163, 21, 21);">"D:\PDFRenderProblem\viewpdf.BMP"</span>)
Sub Convert1PagePDF(imageFile As String, outputFile As String)
Dim a As Byte() = My.Resources.Aspose_Total
Dim licPDF As Aspose.Pdf.License = New Aspose.Pdf.License()
Dim memLicense As New MemoryStream(a)
licPDF.SetLicense(memLicense)<span style="color: blue;">Dim</span> SourceBinaryData <span style="color: blue;">As</span> <span style="color: blue;">Byte</span>() SourceBinaryData = System.IO.<span style="color: rgb(43, 145, 175);">File</span>.ReadAllBytes(imageFile) <span style="color: blue;">Dim</span> ms <span style="color: blue;">As</span> <span style="color: blue;">New</span> <span style="color: rgb(43, 145, 175);">MemoryStream</span>(SourceBinaryData) <span style="color: blue;">Dim</span> convertPdf <span style="color: blue;">As</span> Aspose.Pdf.Facades.<span style="color: rgb(43, 145, 175);">PdfConverter</span> = <span style="color: blue;">New</span> Aspose.Pdf.Facades.<span style="color: rgb(43, 145, 175);">PdfConverter</span>() convertPdf.BindPdf(ms) <span style="color: green;">'open document</span> <span style="color: blue;">Dim</span> pdfDocument <span style="color: blue;">As</span> <span style="color: blue;">New</span> Aspose.Pdf.<span style="color: rgb(43, 145, 175);">Document</span>(ms) <span style="color: green;">'get page collection</span> <span style="color: blue;">Dim</span> pageCollection <span style="color: blue;">As</span> Aspose.Pdf.<span style="color: rgb(43, 145, 175);">PageCollection</span> = pdfDocument.Pages <span style="color: blue;">Dim</span> resolution <span style="color: blue;">As</span> <span style="color: blue;">Integer</span> = 0 <span style="color: blue;">If</span> (pageCollection.Count > 0) <span style="color: blue;">Then</span> <span style="color: blue;">Try</span> <span style="color: blue;">Dim</span> pdfPage <span style="color: blue;">As</span> Aspose.Pdf.<span style="color: rgb(43, 145, 175);">Page</span> = pageCollection(1) convertPdf.Resolution = <span style="color: blue;">New</span> Aspose.Pdf.Devices.<span style="color: rgb(43, 145, 175);">Resolution</span>(GetResolution(pdfPage.ArtBox.Width)) <span style="color: blue;">Catch</span> ex <span style="color: blue;">As</span> <span style="color: rgb(43, 145, 175);">Exception</span> convertPdf.Resolution = <span style="color: blue;">New</span> Aspose.Pdf.Devices.<span style="color: rgb(43, 145, 175);">Resolution</span>(72) <span style="color: blue;">End</span> <span style="color: blue;">Try</span> <span style="color: blue;">End</span> <span style="color: blue;">If</span> convertPdf.StartPage = 1 convertPdf.EndPage = 1 convertPdf.DoConvert() <span style="color: blue;">Dim</span> b <span style="color: blue;">As</span> <span style="color: blue;">Byte</span>() = <span style="color: blue;">Nothing</span> <span style="color: blue;">If</span> convertPdf.HasNextImage() <span style="color: blue;">Then</span> <span style="color: blue;">Dim</span> OutputMS <span style="color: blue;">As</span> <span style="color: blue;">New</span> <span style="color: rgb(43, 145, 175);">MemoryStream</span>() convertPdf.GetNextImage(OutputMS, <span style="color: rgb(43, 145, 175);">ImageFormat</span>.Bmp) <span style="color: green;">'b = GetOptimizedImage(OutputMS, TargetFormat)</span> <span style="color: blue;">Dim</span> image <span style="color: blue;">As</span> <span style="color: blue;">New</span> <span style="color: rgb(43, 145, 175);">Bitmap</span>(OutputMS) image.Save(outputFile) <span style="color: green;">'assume this is a BMP</span> OutputMS.Dispose() <span style="color: blue;">End</span> <span style="color: blue;">If</span> ms.Dispose() convertPdf.Close() <span style="color: blue;">End</span> <span style="color: blue;">Sub</span>
Function GetResolution(ByVal width As Double) As Integer
width = width / 72 'Convert in inch
If (width < 8.5) Then
Return 816 / width ’ (8.5 x 96dpi)/width
Else
Return 96
End If
End Function
Any ideas why this happens?