I created a project that allows converting HTML to PDF. I'm using phantom-render-stream to convert the HTML to PDF. My problem now, I failed to pass an object value to HTML. Below is my code.
app.js
var username = "AAA";
var pets = [
{id: 1, name: "cat"},
{id: 2, name: "dog"},
{id: 3, name: "sugar glider"}
];
var address = {
line1: "Street A123",
town: "Edinburgh",
country: "Scotland"
};
render('http://localhost:8888/createForm.html?username='+username+'&pets='+pets+'&address='+address
.pipe(fs.createWriteStream('customer.pdf'));
In createForm.html, I used an AngularJS to get and view the value to PDF.
createForm.html
<script>
var app = angular.module('myApp', []);
app.config(function($locationProvider){
$locationProvider.html5Mode(true);
});
app.controller('getDataCtrl', function($scope, $location) {
var url = decodeURIComponent( $location.url() );
var value = $location.search();
$scope.username = value.username;
$scope.pets = value.pets;
$scope.address = value.address;
})
</script>
<body>
<div ng-app="onePayForm" ng-controller="getDataCtrl">
<p>{{username}}</p>
<p>{{pets[0].name}}</p>
<p>{{address.line1}}</p>
</div>
</body>
After successfully converting HTML to PDF, I opened the pdf file to see the result. Only username appears in pdf, the rest shows like this {{pets[0].name}} {{address.line1}}.