2014-11-18 13 views
5

Ho visto tutto quel contenuto, non ho visto il contenuto del modo in cui utilizzare '--replace'. Come usare "--replace" in wkhtmltopdf. Per favore mi dia un esempio, Thanks :)Come utilizzare "--replace" in wkhtmltopdf

+0

Hai mai capito questo. Se lo hai fatto, dovresti pubblicare la risposta. –

risposta

0

Diciamo che avere un my_footer.html piè di pagina, che contiene quanto segue:.

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <script> 
     function substitutePdfVariables() { 

      function getParameterByName(name) { 
       var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search); 
       return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); 
      } 

      function substitute(name) { 
       var value = getParameterByName(name); 
       var elements = document.getElementsByClassName(name); 

       for (var i = 0; elements && i < elements.length; i++) { 
        elements[i].textContent = value; 
       } 
      } 

      ['username'/*, 'topage', 'page',.. etc and any variable you would want to replace */] 
       .forEach(function(param) { 
        substitute(param); 
       }); 
     } 
    </script> 
    </head> 
    <body onload="substitutePdfVariables()"> 
    <span class="username"></span> 
    </body> 
</html> 

si può sostituire "nomeutente" con un certo valore:

wkhtmltopdf my_super_html.html --footer-html my_footer.html --replace "username" "Veaer" 

Si noti che ho usato javascript per sostituire la variabile denominata con il mio valore.