简体   繁体   中英

Send entire html table to tcpdf

This question is more of how to logically approach this obstacle instead of correcting code.

I have a very large application which is based on a 'Wizard'. Users input their data, continue on, data is saved, etc.

In the end, the user needs to be able to print a PDF of all this collected data from the Wizard process. I don't want to use the data from the database, but capture the data 'currently' in the Wizard.

I've been able to make a hidden form on the page, jquery creates new hidden inputs with small strings of data. Then when the user clicks 'print' the data is sent via post and is used in the pdf... but I need a way to send large amounts of data.

So, to make my life easier, is it possible to send an entire specified div or table to TCPDF to use as an htmlcell ?

PS jQuery, HTML, PHP are at my disposal.

I don't know this methode is correct or not.But it works..Send data through ajax as an array to server

Create pdf . Save pdf server side folder and open the pdf in another window

**// Post data to server

$.ajax({

    type:"POST",             
    url:"//path",

    data:"&arrDataArray="+arrDataArray,
    success:function(Results){

        //if preview then open the pdf in a new tab
        if(Results=='PREVIEW'){

            highLightPrintSettingsTab(strCurrentTab);
            $(".busyLoading").hide();
            window.open("../pdffiles/example.pdf","_blank");


        }

} });

Here is what I ended up doing. Works like charm.

function submitData(url, method, data) {
        var $form = $('<form></form>')
        .attr('action', url)
        .attr('method', method)
        .attr('target', '_blank')
        .appendTo('body');

        for (var i in data) {
            if (!data.hasOwnProperty(i)) continue;
            $('<input type="hidden"/>')
            .attr('name', i)
            .val(JSON.stringify(data[i]))
            .appendTo($form);
        }
            $form.submit();
    }
    });

Where 'data' will be the array(s) you wish to send to wherever, in my case the controller for tcpdf. {multi, data} for plural.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM