Closed SimonG5 closed 1 year ago
Hi @SimonG5,
could you please provide a sample PDF file for this issue?
I tested your code above with this test file Wikimedia_Commons_web.pdf (7.88 MB) and the generated JPG image was fine.
Both PDF files render just fine on my machine. Can you please confirm if the JPG files are correct by saving and opening them in an image viewer?
IAsyncEnumerable<SKBitmap> images = Conversion.ToImagesAsync(data,null,100);
await foreach (SKBitmap image in images)
{
var encoded = image.Encode(SKEncodedImageFormat.Jpeg, 100);
imageList.Add(Convert.ToBase64String(encoded.ToArray()));
using var output = new System.IO.FileStream(System.IO.Path.Combine(System.Environment.CurrentDirectory, "output.jpg"), System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
encoded.SaveTo(output);
output.Close();
}
return new OkObjectResult(imageList);
Saving the image generated this blank pictures.
Which runtime are you using? .NET 6? Are you running Windows 11 on x64 or ARM64? Are you using PDFtoImage 2.1.2? Are the PDFium binaries (from the NuGet package bblanchon.PDFium.Win32) on version 105.0.5187?
Have you tried other encoders like SKEncodedImageFormat.Png
or SKEncodedImageFormat.Bmp
?
Just asking a bunch of things for troubleshooting. :-)
I ended up figuring out that my base64 converter on the front end was at fault. This can be marked as resolved, the library worked as intended. Thank you for your fast help!
Glad to hear that!
@sungaila
var base64Images = new List<string>();
var sKBitmaps = PDFtoImage.Conversion.ToImagesAsync(signeFileRequest.File, null, dpi: 100);
await foreach (var sKBitmap in sKBitmaps)
{
using var sKData = sKBitmap.Encode(SkiaSharp.SKEncodedImageFormat.Jpeg, 70);
base64Images.Add(Convert.ToBase64String(sKData.ToArray()));
}
It always generates the same base64 for all the pages, if I save the images everything is correct... any ideas?
@angelru Are you sure the Base64 are identical? In my test case the first 100 characters are equal but they differ after that.
@sungaila you are right, I looked very quickly, thanks for this wonderful library
@sungaila Do the height and width of the images correspond to those of the pdf pages?
When you upload pdf files over 3kb the returned image turns blank. Can this be some buffer issue? `
the variable data is a base64 string. Operating os is windows 11.