Custom Page Number in TCPDF - tcpdf

i'm using TCPDF to generate my pdf. I have no idea for reset starting page number. I mean, i will generate report that starting page numer 3 (not 1) in footer, but the second page increment by 2 (3,5,6,7 etc)
Here is my code :
$_SESSION["hal"] = $_POST["hal"];
$_SESSION["f"] = $_POST["f"];
class MYPDF extends TCPDF {
// Page footer
public function Footer() {
// Position at 25 mm from bottom
$this->SetY(-25);
// Set font
$this->SetFont('helvetica', 'b', 8);
// Page number
$this->Cell(0, 15,$_SESSION["f"]." ". $_SESSION["hal"], 'T', false, 'R', 0, '', 0, false, 'T', 'M');
$_SESSION["hal"]++;
}
}
Can someone help please..

Done..
$_SESSION["hal"] = $_POST["hal"];
$_SESSION["f"] = $_POST["f"];
class MYPDF extends TCPDF {
// Page footer
public function Footer() {
// Position at 25 mm from bottom
$this->SetY(-25);
// Set font
$this->SetFont('helvetica', 'b', 8);
// Page number
//i add var to store current page
$halaman = $this->PageNo();
$this->Cell(0, 15,$_SESSION["f"]." ". ($halaman+$_SESSION["hal"]), 'T', false, 'R', 0, '', 0, false, 'T', 'M');
}
}

a other way is to use Page Groups. Better with no need of SESSION.
To start the Group:
$this->startPageGroup();
and to print:
$w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : '';
if (empty($this->pagegroups)) {
$pagenumtxt = $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
} else {
$pagenumtxt = $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');

Related

How to detect height jsPDF-AutoTable

I am using jspdf autotable plugin (jspdf.plugin.autotable.js and jspdf.min.js)
to make table grid view in PDF document.
this is my code bellow:
var listpaket2 = '<?php echo json_encode($new_array_list_paket_min_15_persen); ?>'
var columns = ["Nama Balai","Kode Satker","Kode PPK","Nama "];
var rows = jQuery.parseJSON(listpaket2); //listpaket2 contains dynamic big data, it is about 5000 rows of record
doc.autoTable(columns, rows, {
styles: {fillColor: [100, 255, 255]},
columnStyles: {
id: {fillColor: 255}
},
addPageContent: function(data) {
}
});
alert(doc.height)
when I am doing alert(doc.height)I got "undefined". that is not as my expectation.
How to detect table height when table contains big data?
You can set the new table height each time a cell was drawn, using the provided hooks like this:
var height = 0;
doc.autoTable(columns, rows, {
styles: {fillColor: [100, 255, 255]},
columnStyles: {
id: {fillColor: 255}
},
addPageContent: function(data) {},
createdCell: function (cell, data) {
height = data.table.height
}
});
alert(height)
Now the above implementation works up to v2.3.5, v3 was pre-release only 4 days ago (at time of writing), then this hook will be removed. At this time it looks like you can use the new hook : didParseCell like this:
var height = 0;
doc.autoTable(columns, rows, {
styles: {fillColor: [100, 255, 255]},
columnStyles: {
id: {fillColor: 255}
},
didParseCell: function (HookData) {
height = HookData.table.height
}
});
alert(height)
Note that addPageContent will also be removed in v3. Other things might still change, check your implementation if you decide to upgrade.
Use the didDrawPage hook passing a function like below to get the ending height of the table.
autoTable(doc, {
...,
didDrawPage: (d) => console.log(d.cursor.y),
};
Trying to set the height within the didParseCell hook did not work. You can capture the data from that hook and get the height after the table finishes.
let height = 0;
let tableMeta = null;
doc.autoTable(columns, rows, {
styles: {fillColor: [100, 255, 255]},
columnStyles: {
id: {fillColor: 255}
},
didParseCell: (data) => {
if (!tableMeta) {
tableMeta = data.table;
height = data.table.height; // <- doesn't work, sets height to 0
}
}
});
// Calculate the table height
height = tableMeta.finalY - tableMeta.pageStartY;
// Or the final Y position after drawing the table if that's what you need
height = tableMeta.height;
alert(height);

How to use Google app script to automatically border line below When Value Changes

I want to add a border line below the row whenever column C value changes.
I haven’t touched macro for a long time, this is a script I put together but it doesn’t work as expected. Anyone know where the problem is? Thanks!
function underline() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getActiveSheet();
for (var i = 1; i < 10; i++) {
if (sheet.getRange(spreadsheet.getCurrentCell().getRow() + i, 3) != sheet.getRange(spreadsheet.getCurrentCell().getRow() + i+1, 3)) {
sheet.getRange(spreadsheet.getCurrentCell().getRow() + i, 1, 1, sheet.getMaxColumns()).activate();
spreadsheet.getActiveRangeList().setBorder(null, null, true, null, null, null, '#000000', SpreadsheetApp.BorderStyle.SOLID);
}
}
};
Your original code is a bit convoluted, doing a lot with a single if statement. I took the liberty to separate the complicated bit into a distinct function, findOriginal(cell). The following code adds one line:
function findOriginal(cell) { //offsets given cell until finds new content
while (cell.getValue() == cell.offset(1,0).getValue()) cell = cell.offset(1,0);
return cell;
}
function underline() {
var spreadsheet = SpreadsheetApp.getActive(),
cell = spreadsheet.getSelection().getCurrentCell();
cell = findOriginal(cell);
var sheet = spreadsheet.getActiveSheet();
sheet.getRange(cell.getRow(), 1, 1, sheet.getLastColumn()) // setting the range to border
.setBorder(null, null, true, null, null, null,
'#000000', SpreadsheetApp.BorderStyle.SOLID); // you wrote this line
};

Highcharts missing information in scatterplot CSV/XLS export

When exporting scatter plot / bubble chart data as CSV or XLS, it is missing key information, see for example: http://jsfiddle.net/11fum86u/
This is the data (extract):
series: [{
data: [
{ x: 95, y: 95, z: 13.8, name: 'BE', country: 'Belgium' },
And the axis titles are in the tooltip (but perhaps needs to be defined elsewhere):
tooltip: {
pointFormat: '<tr><th colspan="2"><h3>{point.country}</h3></th></tr>' +
'<tr><th>Fat intake:</th><td>{point.x}g</td></tr>' +
'<tr><th>Sugar intake:</th><td>{point.y}g</td></tr>' +
'<tr><th>Obesity (adults):</th><td>{point.z}%</td></tr>',
What is missing in the default export is (i) labels for y and z axis, and (ii) the names of the bubbles (in this example, country codes/names)
I was wondering how I might be able to add this information to the export.
Actually there's no z axis in bubble charts. It's quite confusing, because all points have z property. This property serves to compute the bubble size so no additional axis is needed, because everything is in 2d. zAxis is used in 3d charts.
Please refer to this live working example: http://jsfiddle.net/kkulig/udtr0emL/
You can handle first row labels via columnHeaderFormatter (http://api.highcharts.com/highcharts/exporting.csv.columnHeaderFormatter):
exporting: {
csv: {
columnHeaderFormatter: function(item, key, keyLength) {
if (item.axisTitle) {
return item.axisTitle.textStr; // x axis label
} else if (key === 'y') {
return item.yAxis.axisTitle.textStr; // y axis label
} else if (key === 'z') {
return 'Obesity (adults)'; // z axis label
}
}
}
}
To add another column (countries) added following pieces of code in these three core functions:
1. Highcharts.Chart.prototype.getDataRows
// add original point reference
rows[key].point = point;
2. Highcharts.Chart.prototype.getCSV
// Add point name and header
csv += itemDelimiter;
var point = row['point'];
if (point) {
csv += point.name
} else {
csv += "Country"
}
3. Highcharts.Chart.prototype.getTable (for XLS)
var point = row['point'],
val;
if (point) {
val = point.name;
} else {
val = "Country";
}
html += '<' + tag + ' class="text">' +
(val === undefined ? '' : val) + '</' + tag + '>';
All functions are available in export-data.src.js in this directory: https://github.com/highcharts/highcharts/tree/b4b4221b19a3a50d9ed613b6f50b12f0afcc7d06/js/modules

Separate panes / or style maximum gridlines in Highstock

I built a widget with multiple y Axes very similar to the official sample here: http://www.highcharts.com/stock/demo/candlestick-and-volume
I'm trying to have some sort of visual separation between the chart panes, either by
applying a special style to the maximum grid line for each pane, or
adding a horizontal line in the whitespace between the panes
The only approach i got working is using PlotLines, but I'd rather have a separator that's independent of zoom levels. Any ideas on how to achieve this?
Use Renderer to draw a path between y axes.
function drawSeparator() {
let separator = this.separator;
const options = this.options.chart.separator;
if (options && options.enabled) {
if (!separator) {
this.separator = separator = this.renderer.path({
d: 'M 0 0',
'stroke-width': options.width === undefined ? 1 : options.width,
stroke: options.color || 'black'
}).add();
}
const topAxisBottom = this.yAxis[0].top + this.yAxis[0].height;
const bottomAxisTop = this.yAxis[1].top;
const y = topAxisBottom + (bottomAxisTop - topAxisBottom) / 2;
separator.attr({
d: `M 0 ${y} L ${this.chartWidth} ${y}`
});
}
}
Call the method on load/redraw event
chart: {
events: {
load: drawSeparator,
redraw: drawSeparator
},
separator: {
enabled: true,
width: 3,
color: 'blue'
}
},
You can modify the path's d attribute, the path starts from axis.left and stops on axis.left + axis.width
Live example and output
http://jsfiddle.net/L11uqxgq/

Showing or hiding a button based on contents of a field in a database

I am trying to show or hide a button based on the contents of a particular database field. I have the field defined as 'text', as the field may contain something like 1-1 or 1-20 or 0. If the field (arref1) is not equal to 0 then I want to show my button. Otherwise hide the button. Here is what I have so far but it dosen't work:
var resultRule = db.execute('SELECT arref1 FROM genrules WHERE title="'+client+'"');
if (resultRule!='0') {
var appliedRule1 = Ti.UI.createButton({
title:' Applied Rule ' + rows.fieldByName('arref1') + '',
bottom:120,
left: 80,
width: 'auto',
height:40,
borderRadius:5,
textAlign: 'center',
color:'#FFFFFF',
backgroundColor:'#7b4336',
backgroundSelectedColor:'#cc9933',
backgroundImage: 'NONE',
font:{fontSize:'20dp'}
});
win.add(appliedRule1);
appliedRule1.addEventListener('click',function(e)
{
var win = Ti.UI.createWindow({
url: 'appliedruledetail.js',
title:' Applied Rule' + rows.fieldByName('arref1') + ''
});
var client = '' + rows.fieldByName('genrule') + '' ;
win.client = client;
Ti.UI.currentTab.open(win);
}
);
} else{};
db.execute returns a Titanium.DB.ResultSet (which is an object) not a string.
Here is how you use a result set:
// Get the row with execute, returns a resultSet
var row = db.execute('SELECT * FROM genrules WHERE title="'+client+'"');
// Make sure its a valid row
if (row.isValidRow()){
// Now get the field from the current row
if(row.fieldByName('arref1') != '0') {
// Add your button here
}
}
row.close(); // Close the result set since were done with it
I heavily borrowed from this example in the documentation

Resources