jsPDF image keeps displaying in wrong order on wrong page - jspdf

I am using jsPDF to create a PDF download.
Below is my code, which works perfectly to display all the bits of info I need so far.
I want everything to display on the PDF in the order I have the code:
Banner
Logo
Job Title
Main Content
Everything sits exactly where it should except for the Banner.
It keeps displaying below all of the content.
In the output PDF I can see the space at the top where it should sit, but it always goes to the last page of the document, after all other content. On the page it displays, it sits in the top left corner and is the correct width and height, so it is doing that correctly, but is just on the wrong page.
What have I stuffed up here? Or how can i force it to sit on page 1?
Thanks in advance for any assistance!
function demoFromHTML() {
var doc = new jsPDF('p', 'mm', 'a4');
var lMargin=20; //left margin in mm
var rMargin=20; //right margin in mm
var pdfInMM=210; // width of A4 in mm
var source = document.getElementById('text-7');
// Banner
html2canvas(jQuery("#top-banner"), {
useCORS : true,
onrendered: function(canvas) {
var banner = canvas.toDataURL('image/png');
doc.addImage(banner, 'PNG', 0, 0, 210, 100);
console.log(banner);
setTimeout(function () {
doc.save('"<?php echo ( get_the_title() );?>"');
}, 0);
}
})
// Logo
var logo = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAC+CAYAAADDYv00AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAGhlJREFUeNrsnc2V28aygMu+3psZGI5AWL6dcCPQePd2giMQHYGgCChFQCkCjiIgJwJKEZDevR3HEfgNjsBjakzOoLur+gf8vnNwfDWXJIDq6vrrPxEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACA3PkPIgAAAENmD9f/PFz1w/W/J3/7P0Sjyw+IAAAi0zxc1XA95stw7RFT0fTO+/XDdXOhnWVo408P1/uH6x6RAQCUkaHNH67Vw/X3yGs7fGeG+Ipz5GuHdj62dY3orjdDrwYF6K9fTiLAZuT398PVR4VfT/69KVQG90NWs0Glr4r24Xo16P3sUZb7+eH6mD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scK8QNAACgTyXj10U/xmeGOwDA5KHkDil4M/Jzt2cCAVc2iBsAcOgANowdP/+s4ND3iBsAcOgANs58jGO+P5Oh+6zNZYY7AODQAQx4NfJz57ZTZA06AAAOHTLK0Mdwd+ZvLzzut0fkAAAAujTivnf7KT7bvgIAAIAyY/du3174vs9RkwAAVwEld4iJz97tR3zGz/eIHABw6AD6NCM/twkIBk5hhjsA4NABEjnzSw6dGe4AADh0KDw7983Q94gdAHDoALq8HPm5uwt//8Xxfvc4dADAoQPoMzbDvpShV473+4LIAQCHDqDvzMeOgX8JDAhw6ACAQwdInJ3v5Vup/Byuk+K+InYAwKED6FI5OPRzNB73JEMHABw6gDKhE+J8lqzh0AEAhw6QKEO/VG53HT/fIHIAwKEDpHPol7Jq11PWyM4BAIcOoIxLds2EOAAAgExpJPyoU9dT1irEDgBk6AB54eqc2SEOAHDoAEYZekyHvkHkAIBDB0jHXikguEOUAIBDB0jHpUzc9VAWMnQAwKEDJKZ2cPSXsnyWrAEADh0gMc1IJ3+JW0QIAABgQyvjl5vtzjh4l+VqNeIGAACwy7pdnHI3fK/fTGbr8L01ogYAALCjFveNYXyuFlEDAADYYu3Md4gYAADAHpfSuc91g4gBAADsWRo6c8bOAQAAItEaOnRmtgMAAERiZuTMF4gWAAAgLtpl9524n5MOAAAAgVTKDr1BpAAAAGnohFI7AADAJAgtvS8RIQAAQNlOncwcAAAgMxr5toZ87FrzBpEBAFzmB0QAiakGZ93/9+XJ3/cP11f5diTqHjEBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACUzv8LMAC5publ4dAlHAAAAABJRU5ErkJggg==';
doc.addImage(logo, 'PNG', 10, 100, 50, 18);
// Job title
doc.setTextColor(0,0,0);
doc.fromHTML(
jQuery('.job_listing-title').get(0), // [Refer Exact code tutorial][2]HTML string or DOM elem ref.
10, // x coord
125, // y coord
{
'width': 190,
});
// Main content
doc.fromHTML(
jQuery('#main').get(0), // [Refer Exact code tutorial][2]HTML string or DOM elem ref.
10, // x coord
135, // y coord
{
'width': 190,
});
}

After posting, I realised how simple the answer was.
The issue was occurring because I was firing the doc.save inside the html2canvas, prior to the logo, job title or main content. Instead I needed to move all of the other content under the banner, but before the doc.save.
The below now functions correctly and outputs all items in the correct order and positions.
function demoFromHTML() {
var doc = new jsPDF('p', 'mm', 'a4');
var lMargin=20; //left margin in mm
var rMargin=20; //right margin in mm
var pdfInMM=210; // width of A4 in mm
var source = document.getElementById('text-7');
html2canvas(jQuery("#top-banner"), {
useCORS : true,
onrendered: function(canvas) {
var banner = canvas.toDataURL('image/png');
// Banner
doc.addImage(banner, 'PNG', 0, 0, 210, 100);
// Logo
var logo = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAC+CAYAAADDYv00AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAGhlJREFUeNrsnc2V28aygMu+3psZGI5AWL6dcCPQePd2giMQHYGgCChFQCkCjiIgJwJKEZDevR3HEfgNjsBjakzOoLur+gf8vnNwfDWXJIDq6vrrPxEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACA3PkPIgAAAENmD9f/PFz1w/W/J3/7P0Sjyw+IAAAi0zxc1XA95stw7RFT0fTO+/XDdXOhnWVo408P1/uH6x6RAQCUkaHNH67Vw/X3yGs7fGeG+Ipz5GuHdj62dY3orjdDrwYF6K9fTiLAZuT398PVR4VfT/69KVQG90NWs0Glr4r24Xo16P3sUZb7+eH6mDjT7XX07fCcvvS6/W7I4iBvuqG9fdv5VzL164n65kPkd3CM/lyvPlpcyLdSUY7ZQfNEBLwb5ATT7w/bEbp8CHSmocZds1+uydazrsCsldoYJmy0FoOT+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AAOHTLK0Mdwd+ZvLzzut0fkAAAAujTivnf7KT7bvgIAAIAyY/du3174vs9RkwAAVwEld4iJz97tR3zGz/eIHABw6AD6NCM/twkIBk5hhjsA4NABEjnzSw6dGe4AADh0KDw7983Q94gdAHDoALq8HPm5uwt//8Xxfvc4dADAoQPoMzbDvpShV473+4LIAQCHDqDvzMeOgX8JDAhw6ACAQwdInJ3v5Vup/Byuk+K+InYAwKED6FI5OPRzNB73JEMHABw6gDKhE+J8lqzh0AEAhw6QKEO/VG53HT/fIHIAwKEDpHPol7Jq11PWyM4BAIcOoIxLds2EOAAAgExpJPyoU9dT1irEDgBk6AB54eqc2SEOAHDoAEYZekyHvkHkAIBDB0jHXikguEOUAIBDB0jHpUzc9VAWMnQAwKEDJKZ2cPSXsnyWrAEADh0gMc1IJ3+JW0QIAABgQyvjl5vtzjh4l+VqNeIGAACwy7pdnHI3fK/fTGbr8L01ogYAALCjFveNYXyuFlEDAADYYu3Md4gYAADAHpfSuc91g4gBAADsWRo6c8bOAQAAItEaOnRmtgMAAERiZuTMF4gWAAAgLtpl9524n5MOAAAAgVTKDr1BpAAAAGnohFI7AADAJAgtvS8RIQAAQNlOncwcAAAgMxr5toZ87FrzBpEBAFzmB0QAiakGZ93/9+XJ3/cP11f5diTqHjEBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACUzv8LMAC5publ4dAlHAAAAABJRU5ErkJggg==';
doc.addImage(logo, 'PNG', 10, 100, 50, 18);
// Job title
doc.setTextColor(0,0,0);
doc.fromHTML(
jQuery('.job_listing-title').get(0), // [Refer Exact code tutorial][2]HTML string or DOM elem ref.
10, // x coord
125, // y coord
{
'width': 190,
});
// Main content
doc.fromHTML(
jQuery('#main').get(0), // [Refer Exact code tutorial][2]HTML string or DOM elem ref.
10, // x coord
135, // y coord
{
'width': 190,
});
console.log(banner);
setTimeout(function () {
doc.save('"<?php echo ( get_the_title() );?>"');
}, 0);
}
})
}

Related

How to detect the height of a table in js Autotable

I am trying to dynamically get the height of a table in a PDF that I created using jsPDF and js Autotable. I want to add a line of text under the table, but since the table height changes, I can't put a specific Y value for the text line.
My current table script:
let col = ['Header 1', 'Header 2', 'Header 3']
let rows = arrayForTable;
let getTableWidth = 150;
let pageWidth = doc.internal.pageSize.width;
let tableMargin = (pageWidth - getTableWidth) / 2;
let height = 0;
doc.autoTable(col, rows, {
margin: {top: 20, right: tableMargin, left: tableMargin},
startY: 70,
styles: {
halign: 'center',
overflow: 'linebreak',
cellWidth: 'wrap',
valign: 'middle'
},
columnStyles: {
0: {cellWidth: 50},
1: {cellWidth: 50},
2: {cellWidth: 50},
},
headStyles: {
fillColor: [163, 32, 32]
},
didParseCell: function(data) {
if (data.row.index === rows.length - 1) {
data.cell.styles.fillColor = [63, 63, 64];
data.cell.styles.fontStyle = 'bold';
data.cell.styles.textColor = [255, 255, 255];
}
height = data.table.height
}
});
console.log(height)
The console prints undefined. Anyone know how to dynamically add a line of text under this table without having to designate a static Y value like this:
doc.text(25, 40, exampleText);
The table height changes every time because of different data being shown.
I am using jsPDF AutoTable plugin v3.5.6.
Get the cursor position on Y axis using
didDrawPage
which will be precisely after the table.
This worked for me in Angular 2:
let yPos = 0;
pdf.autoTable({
...
didDrawPage: function(data) {
yPos = data.cursor.y;
}
}
jspdf version:
"jspdf": "^2.3.1",
"jspdf-autotable": "^3.5.14",
Source:
Table height is always 0 #604
From what I understood, you want to add the text under the table. Instead of trying to read the table height, you can read the last cell Y position. What you need to do is like this
let height = 0;
....
didParseCell: function(data) {
...
height = data.cursor.y + data.row.height;
}
....
then you can adjust the position of the text you want to add, for the example I want to add 10 gap between the table and the text
doc.text("exampleText", 25, height + 10);

yAxis resizer to change svgrenderer position also highcharts

I have a chart with some indicators below it. Each indicator area consists
of a svg renderer button. so when I use resize property to drag and resize
the panes, the series resized perfectly but the button remains in its same
position, Can we move the button with the resizer?
Here I created a sample link to regenerate
https://jsfiddle.net/q0ybpnvx/2/
Any help will be appreciated. I am having great trouble. Thank you
You can add and position the custom button in render event:
chart: {
events: {
render: function() {
var chart = this;
if (chart.customBtn) {
chart.customBtn.attr({
y: chart.yAxis[1].top,
});
} else {
chart.customBtn = chart.renderer.button(
'sometext',
5,
chart.yAxis[1].top,
function() {
console.log('some task')
}).add()
}
}
}
},
Live demo: https://jsfiddle.net/BlackLabel/b7vq4ecy/
API Reference:
https://api.highcharts.com/highcharts/chart.events.render
https://api.highcharts.com/class-reference/Highcharts.SVGElement#attr
I was able to do something by manually changing the x/y attributes of my svgRenderer label, the same should apply to buttons.
I'm in angular and have a listener for screen resizing:
Also Note that you can change the entire SVGRenderer label with the attr.text property.
this.chart = Highcharts.chart(.....);
// I used a helper method to create the label
this.chart.myLabel = this.labelCreationHelperMethod(this.chart, data);
this.windowEventService.resize$.subscribe(dimensions => {
if(dimensions.x < 500) { //this would be your charts resize breakpoint
// here I was using a specific chart series property to tell where to put my x coordinate,
// you can traverse through the chart object to find a similar number,
// or just use a hardcoded number
this.chart.myLabel.attr({ y: 15, x: this.chart.series[0].points[0].plotX + 20 });
} else {
this.chart.myLabel.attr({ y: 100, x: this.chart.series[0].points[0].plotX + 50 });
}
}
//Returns the label object that we keep a reference to in the chart object.
labelCreationHelperMethod() {
const y = screen.width > 500 ? 100 : 15; 
const x = screen.width > 500 ? this.chart.series[0].points[0].plotX + 50 :
this.chart.series[0].points[0].plotX + 20
// your label
const label = `<div style="color: blue"...> My Label Stuff</div>`
return chart.renderer.label(label, x, y, 'callout', offset + chart.plotLeft, chart.plotTop + 80, true)
.attr({
fill: '#e8e8e8',
padding: 15,
r: 5,
zIndex: 6
})
.add();
}

Add content before and after table (jsPDF autotable)

i have a question to jsPDF autotable.
My Code:
$('#printBtn').on('click', function() {
var pdf = new jsPDF('p', 'pt', 'a4');
var res = pdf.autoTableHtmlToJson(document.getElementById("tablePrint"));
pdf.autoTable(res.columns, res.data, {
theme : 'plain',
styles: {
fontSize: 12
},
showHeader: 'never',
createdCell: function(cell, data) {
var tdElement = cell.raw;
if (tdElement.classList.contains('hrow')) {
cell.styles.fontStyle = 'bold';
}
}
});
pdf.save("test.pdf");
});
I want add Text before and after the Table from a div.
I have found this Code Snippet in jsPDF autotable examples:
var before = "text before";
pdf.text(before, 14, 30);
This code works good. I have insert that before pdf.autoTable(...});.
But i dont know what the number 14 and 30 for?
Then i have the code insert after the pdf.autoTable function call and the Text printed on the last page of pdf but on the top of the page, not on the end, why?
Sorry for my bad englisch.
Thanks for help.
If what you want is to add something before you must first move the table that you are adding with autotable, you achieve this by adding a startY: 150 attribute within doc.autotable:
pdf.autoTable(res.columns, res.data, {
theme : 'plain',
styles: {
fontSize: 12
},
startY: 150,
showHeader: 'never',
createdCell: function(cell, data) {
var tdElement = cell.raw;
if (tdElement.classList.contains('hrow')) {
cell.styles.fontStyle = 'bold';
}
}
});
150 is the value in pixels you want to move. Above this you can place the text you want with the code you placed.
var before = "text before";
pdf.text(before, 14, 30);
Now the values of 14 (Value in Y) and 30 (Value in Y) are the values that you want the text to move in pixels.
In order for you to add text after the table you must first obtain in which number of pixels your table ended and from there enter the text you want.
let finalY = pdf.previousAutoTable.finalY; //this gives you the value of the end-y-axis-position of the previous autotable.
pdf.text("Text to be shown relative to the table", 12, finalY + 10); //you use the variable and add the number of pixels you want it to move.
Here's my stab at an answer:
So this is your Autotable's function call:
var pdf = new jsPDF('p', 'pt', 'a4');
Since jsPDF Autotables is based on jsPDF, you'll have to go here:
pt is a unit of measurement called points, so 14 and 30 are points. At the first position, 14, moves elements left and right. The second position, 30, moves elements down and up. I'm guessing they're like pixels(px). Seems like you have to move your text to your desired locations by using points.
An idea that helped me is to placing a Table with no content on the position where you would like to add the new table.
autoTable(doc, {
body: [],
startY: finalY + bias
});

jspdf first PDF page is blank

Im trying to get my jspdf to not save a blank page PDF. I been trying many examples, but nothing works :(. My table content is saved correct, with a image on the second page of the PDF, but my first page is blank.
var pdf = new jsPDF('o', 'pt', 'a6');
//pdf.autoTable(this.columns, this.data);
//var width = pdf.internal.pageSize.width;
//var height = pdf.internal.pageSize.height;
pdf.addPage('1800','900');
pdf.addImage(imgData, 'PNG', 120, 40, 120, 100);
pdf.setTextColor(0,0,0);
pdf.text(120, 20, 'BOOKINGS');
pdf.setFontSize(22);
// 'o', 'pt', 'a4'
// 'p', 'pt', 'letter'
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = jQuery('.dataTables_wrapper')[0];
// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
margins = {
top: 120,
bottom: 0,
left: 0,
width: 2000
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, { // y coord
'width': margins.width, // max width of content on PDF
'elementHandlers': specialElementHandlers
},
function (dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save('bookings.pdf');
}, margins);
}
The first page is blank because adding a page is the first call you make after calling the jsPDF constructor. The constructor does already create a (first) blank page. To get rid of the additional empty page at the start of the document, either delete the first page calling doc.deletePage(1), or do not add a page after the constructor is being called.

Label View eventlistener not working in Table View

I am creating Array of LabelView in my application during the run time and adding it to a TableView. But click EventListener not working for LabelView, Here is my sample code
var picRow = Titanium.UI.createTableViewRow();
var photoContainer = Ti.UI.createView({
top:0,
width:300,
left:15,
right:5,
height:200
})
picRow.add(photoContainer);
var shareTable = Ti.UI.createTableView({
data:[picRow],
top:10,
left:0,
right:0,
height:250,
separatorColor: '#ccc',
backgroundColor:'transparent'
});
win.add(shareTable);
var pushleft = 5;
var pushtop = 5;
var images = [];
for (var i = 0; i < imageArray.length; i++){
images[i] = Ti.UI.createLabel({
backgroundImage: imageArray[i].image, // path to image at applicationDataDirectory
width: 70 ,
height: 70,
"tickOption":false,
"index":i,
"picId":imageArray[i].picId,
left: pushleft + 25, // logic for positioning
top: pushtop + 5
});
pushleft = pushleft + 80;
pushtop = pushtop + 50;
photoContainer.add(images[i]);
images[i].addEventListener('click', function(e) {
alert(e);
});
}
Here I am not getting any alert while clicking on the label view. Also I am not getting any error. Anyone help me to solve this issue. Thanks in Advance. I am using Titanium 1.7.5 and ios
it is a best practice to put the eventlistener on the whole row and then look at the click event object to determine which object received the click.
so for example you would look for the picId of the object, if it existed, you would know that a label was clicked

Resources