Convert Base64 to pdf

Asked

Viewed 930 times

1

I have in my application a function that converts the pdf to Base64 and saves in the database and then, I need to return this Base64 and show the contents of the original file.

    $('#form-job').submit(function(e) {
    e.preventDefault();
    console.log('aqui');
    var inputs = $(e.target).find('[name]').serializeArray();

    var reader = new FileReader(),
        file = $('#resume')[0];

    if (!file.files.length) {
        alert('no file uploaded');
        return false;
    }

    var url = "http://localhost:5000/api/curriculum";
    reader.onload = function () {
        var data = reader.result,
            base64 = data.replace(/^[^,]*,/, '');

        inputs.push({name:'resume', value: base64});                        

        $.ajax({
            url: url,
            type: "POST",
            dataType: "JSON",
            data: inputs,
            success: function (response) {
                $(".contato-quad-formulario-right-enviar").hide()
                $(".contato-quad-formulario-right-enviar-sucesso").show()
                $(".contato-quad-formulario-right, .contato-quad-formulario-left").fadeTo("slow", 0.33);
             }
        });
    };
    reader.readAsDataURL(file.files[0]);                
});

It’s a question of the company doing it this way, saving in Base64 and then showing the original content. Now that my problem comes up, I can in no way show the original content. How can I create a pdf from Base64 that is returned to me. If it helps I can return the value saved in the bank as buffer or in Base64 which is better ?

  • It would be more feasible a solution with the header (header), you are using PHP?

  • https://stackoverflow.com/questions/20080341/correct-php-headers-for-pdf-file-download

  • I am using Javascript with Bundle to save and Angularjs to show the pdf

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.