Convert a data url to png


This Content is from Stack Overflow. Question asked by Cyrus Yabut

I want to get the data url from my db server then convert it to base64 png and put it in the pdf file using itext sharp.I don’t know if I’m missing something in my code, it keeps getting error in converting dataurl to png, it says “the input doesn’t contain valid base64 string as it contains non-base 64 character, more than two padding characters, or an illegal character among the padding characters.”

im using javascript to convert the img to dataurl, then post the string in the db.

        $(function () {

            var canvas = document.querySelector('#signature');
            var pad = new SignaturePad(canvas);

            $('#accept').click(function () {

                var data = pad.toDataURL();

                $('#savetarget').attr('src', data);



then this is the code in the controller

 string base64 = client.Data; /// (client is my db source, data is where i store the string in db)
                byte[] imageByte = Convert.FromBase64String(base64);
                var encoded = Convert.ToBase64String(imageByte);
                Image penk = Image.GetInstance(encoded);

Thanks for the time and effort reading, i appreciate any help.


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?