<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.5.0-beta4/html2canvas.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dom-to-image/2.6.0/dom-to-image.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script>
<mvc:View controllerName="fioriprojectapplication.controller.Home"
xmlns:mvc="sap.ui.core.mvc" displayBlock="true"
xmlns="sap.m">
<Page id="page" title="Employee Details">
<headerContent>
<Button text="Table capture by html2canvas" press="tablecapture" />
<Button text="Screen capture by domtoimage" press="screencapture" />
<Button text="Download PDF" press="downloadpdf"/>
</headerContent>
<content>
<Table width="60%" id ="table" class="tablecss" items="{localmodel>/employee}" >
<columns >
<Column >
<Text text="Name" />
</Column>
<Column >
<Text text="Role" />
</Column>
<Column>
<Text text="Age" />
</Column>
</columns>
<items>
<ColumnListItem >
<cells>
<Text text="{localmodel>name}" />
<Text text="{localmodel>role}" />
<Text text="{localmodel>age}" />
</cells>
</ColumnListItem>
</items>
</Table>
</content>
</Page>
</mvc:View>
tablecapture: function()
{
var bodyElement = this.getView().byId("table").getDomRef();
html2canvas(bodyElement).then(function(canvas)
{
var image = canvas.toDataURL('image/png');
var downloadLink = document.createElement('a');
downloadLink.href = image;
downloadLink.download = 'tablescreenshot.png';
downloadLink.style.display = 'none';
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
});
}
screencapture: function()
{
var node = document.body
domtoimage.toPng(node).then(function (dataUrl)
{
var downloadLink = document.createElement('a');
downloadLink.href =dataUrl;
downloadLink.download = 'fullscreenshot.png';
downloadLink.style.display = 'none';
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
})
.catch(function (error)
{
console.error('Error:', error);
});
}
downloadpdf: function()
{
domtoimage.toPng(document.body).then(function (dataUrl)
{
var doc = new jsPDF(
{
orientation:'landscape',
})
doc.addImage(dataUrl,'PNG',25,25,250,150)
doc.save('applicationview.pdf')
})
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
9 | |
7 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |