Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I've a pdf base64 string and I want to convert that into a image bytes, but while converting the image quality is getting compromised and the content is getting blury.

What I have tried:

C#
public byte[] ConvertPdfToImg(string soapResponse)
 {
     try
     {
         string base64 = "";
         byte[] imageBytes;
         ImageSaveOptions imageOptions;
         byte[] pdfBytes = Convert.FromBase64String(soapResponse);

         ComponentInfo.SetLicense("FREE-LIMITED-KEY");

         using (GemBox.Pdf.PdfDocument pdfDocument = GemBox.Pdf.PdfDocument.Load(new MemoryStream(pdfBytes))) //.Load(new MemoryStream(pdfBytes)))                
         {
             // Create image save options.
             imageOptions = new ImageSaveOptions(ImageSaveFormat.Jpeg)
             {
                 PageNumber = 0, // Select the first PDF page.
                 Width = 700, // Set the image width and keep the aspect ratio.
                 Height = 1000 // set the image height
             };
             //pdfDocument.Save(outputPath, imageOptions);                    

             // Save the image to a MemoryStream.
             using (MemoryStream ms = new MemoryStream())
             {
                 pdfDocument.Save(ms, imageOptions);
                 imageBytes = ms.ToArray(); // Get the byte array of the image.
                 //base64 = Convert.ToBase64String(imageBytes);

                 //File.WriteAllText(@"C:\Users\999348\Downloads\base64.txt", base64);
             }

         }
         return imageBytes;
     }
     catch (Exception ex)
     {
         ex.ToString();
     }
     return null;
 }
Posted
Updated 26-Mar-24 23:06pm
v2

1 solution

You are using a free version of a paid-for product: you need to contact the manufacturers (C# / VB.NET PDF component - GemBox.Pdf[^]) to find out if the free version has quality restrictions as well as page count restrictions.

We don;t provide tech support for paid for components: that's up to the creators (and a demonstration of their support quality if you decide to upgrade to the paid version - if their support is cr@p before you buy, how likely is it that it'll improve when they've already got your money?)
 
Share this answer
 
Comments
Shahbaz435 27-Mar-24 5:11am    
I need alternative of this paid library I don't want this paid library
Richard Deeming 27-Mar-24 5:25am    
Shahbaz435 27-Mar-24 5:28am    
I'm not saving the file on physical location I've pdf base64 string and I want to convert into image bytes
Richard Deeming 27-Mar-24 5:29am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900