1

I want to convert pdf file from image (Base64ToImage) in c# desktop application.

Here is my Base64ToImage code,

public Image Base64ToImage(string base64String)
{
    if (base64String != "")
    {
        // Convert Base64 String to byte[]
        byte[] imageBytes = Convert.FromBase64String(base64String);
        MemoryStream ms = new MemoryStream(imageBytes, 0,
          imageBytes.Length);

        // Convert byte[] to Image
        ms.Write(imageBytes, 0, imageBytes.Length);
        Image image = Image.FromStream(ms, true);
        return image;
    }
    else
    {
        return null;
    }
}

Now, from this code in picturebox getting the image

Here is the sample code of fetch the image and upload in picturebox

pictureBox1.Image = Base64ToImage(dtSelStock.Rows[0]["DesignImage"].ToString());

Now, from here my question was there i.e. how can I convert pdf file from image which contains picturebox1.image?

karan
  • 482
  • 1
  • 8
  • 30
  • 1
    You need a PDF library. – SLaks May 10 '19 at 15:06
  • @SLaks can you show me code syntax? – karan May 10 '19 at 15:07
  • @elgonzo for your kind information library is used for the namespace but by only namespace program is not excute thats why I am asking regarding syntax. Understand what I am telling you if not then please dont comment. – karan May 10 '19 at 15:13
  • Sorry if my comment was a bit snarky, but your response to SLaks' comment asking about "show me code syntax" does not make sense, at all... –  May 10 '19 at 15:18
  • @elgonzo just read comment carefully. I didnt tell to show the code. I just tell to show the syntax of converting pdf from image. Now, syntax meaning is that how to get the flow of that code. Not by library done this solution. Bcos that I also know that from **itextsharp.dll** (library) is used to convert pdf from image. But after that we want to do code and that syntax I am asking. – karan May 10 '19 at 15:22
  • you certainly didnt do much googling prior to posting your question. This should be flagged as a duplicate. https://stackoverflow.com/questions/10125117/convert-pdf-file-pages-to-images-with-itextsharp – Kevbo May 10 '19 at 15:31
  • @Kevbo this question is not duplicate. I want to convert pdf file from basetoimage not from image path. Please read question carefully. – karan May 10 '19 at 16:00
  • Where did the base64string come from? Did you just take the saved pdf file and read it into a string? Thats never going to work – Kevbo May 10 '19 at 16:43
  • @Kevbo base64 is the fn is used to converting byte(binary) to image (bcos in database byte is stored not image or image path), now when fetching from database, from this fn image is getting and display on the picture box toolbar. Now I want to create pdf of that image which is in picture box. – karan May 10 '19 at 16:50
  • You havent explained how you saved the pdf in the database. What process did you use to convert the pdf document into a binary format when you saved it? You will need to reverse that process and get it back into a pdf document. then take the document and create an image from that. This would be the direction i would take – Kevbo May 10 '19 at 17:00

0 Answers0