In my angular app i display JSON data in a table with pagination using ngx-pagination
i want to export my table in pdf format I used a couple of npm packages that take a screenshot off the HTML page and convert it to a pdf to export, the only problem is not all the data is being displayed because of the pagination and number of items per page, is there a work around this?
Here is the code I used :
<table
class="
table
is-hoverable is-striped is-fullwidth
content-table
#userTable
"
id="htmlData"
>
<thead>
<tr>
<th>{{ "DataSource.RecordID" | translate }}</th>
<th colspan="6">{{ "DataSource.Details" | translate }}</th>
</tr>
</thead>
<tbody>
<tr
*ngFor="
let row of FilteredMatchTransactions
| paginate: { itemsPerPage: itemsPerPage, currentPage: p };
let i = index
"
>
<td>
{{ "DataSource.SessionID" | translate }} :
{{ row.SESSION_ID }}
</td>
<td>
{{ "DataSource.ExternalStan" | translate }} :
{{ row.EXTERNAL_STAN }}
</td>
<td>
PAN :
{{ row.CARD_NUMBER }}
</td>
<td>
{{ "DataSource.Amount" | translate }} :
{{ row.TRANSACTION_AMOUNT.split(" ")[0] }}
</td>
<td>
{{ "DataSource.Currency" | translate }} :
{{ row.TRANSACTION_AMOUNT.split(" ")[1] }}
</td>
<td>
Terminal :
{{ row.TERMINAL_ID }}
</td>
<td>
{{ "DataSource.TransactionDate" | translate }} :
{{ row.TRANSACTION_DATE }}
</td>
</tr>
</tbody>
</table>
ts :
import jsPDF from 'jspdf';
import html2canvas from 'html2canvas';
....
....
public downloadPDF(): void {
let DATA = document.getElementById('htmlData');
console.log(DATA);
html2canvas(DATA).then((canvas) => {
let fileWidth = 208;
let fileHeight = (canvas.height * fileWidth) / canvas.width;
const FILEURI = canvas.toDataURL('image/png');
let PDF = new jsPDF('p', 'mm', 'a4');
let position = 0;
PDF.addImage(FILEURI, 'PNG', 0, position, fileWidth, fileHeight);
PDF.save('angular-demo.pdf');
});
}