Skip to content

Commit

Permalink
Download to pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
Pim Otte committed May 15, 2019
1 parent 6a8ad54 commit 5fd416d
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 14 deletions.
165 changes: 165 additions & 0 deletions clerk-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clerk-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@discipl/abundance-service": "^0.4.1",
"@discipl/core-ephemeral": "^0.7.0",
"@discipl/paper-wallet": "^0.6.0",
"jspdf": "^1.5.3",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "^2.1.8",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"DEFAULT_EPHEMERAL_ENDPOINT" : "http://localhost:3232",
"DEFAULT_EPHEMERAL_ENDPOINT" : "http://localhost:3000",
"DEFAULT_EPHEMERAL_WEBSOCKET_ENDPOINT" : "ws://localhost:3233",
"PRODUCT_NEED" : "BRP_UITTREKSEL_NEED",
"SOURCE_ARGUMENT" : "BSN",
Expand Down
20 changes: 18 additions & 2 deletions clerk-frontend/src/need-wizard/DeliveryStep.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import * as paperWallet from '@discipl/paper-wallet'
import CONFIGURATION from '../configuration/clerk-frontend-config.json'
import * as jsPDF from 'jspdf'

let template = CONFIGURATION.EXPORT_TYPES['@discipl/paper-wallet'].template

Expand All @@ -16,9 +17,9 @@ class ConfirmStep extends Component {
this.canvasRef = React.createRef()
}

deliveryChanged(link,vc) {
deliveryChanged(canvas) {
if (this.props.deliveryChanged) {
this.props.deliveryChanged(link,vc)
this.props.deliveryChanged(canvas)
}
}

Expand All @@ -29,10 +30,25 @@ class ConfirmStep extends Component {

console.log("Issued")

let pdf = new jsPDF({
orientation: 'p',
unit: 'pt',
format: [595.28, 841.89]
})

this.canvasRef.current.width = template.canvasWidth
this.canvasRef.current.height = template.canvasHeight

await paperWallet.toCanvas(vc, template, this.canvasRef.current)

let imageData = this.canvasRef.current.toDataURL('image/png')




pdf.addImage(imageData, 'png', 0, 0, template.canvasWidth, template.canvasHeight)

this.deliveryChanged(pdf)
}

render() {
Expand Down
12 changes: 4 additions & 8 deletions clerk-frontend/src/need-wizard/NeedWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import NeedStep from './NeedStep'
import ConfirmStep from './ConfirmStep'
import DeliveryStep from './DeliveryStep'


const MAX_STEP = 3;

class NeedWizard extends Component {
Expand Down Expand Up @@ -47,11 +48,7 @@ class NeedWizard extends Component {

_download(type) {
if(type === 'paperWallet') {
let a = document.createElement('a');
document.body.appendChild(a);
a.download = this.state.personalDid+'.png';
a.href = this.state.canvas.toDataURL('image/png')
a.click()
this.state.pdf.save('uittreksel.pdf')
} else {
window.alert('Download option ('+type+') not supported...')
}
Expand Down Expand Up @@ -113,11 +110,10 @@ class NeedWizard extends Component {
})
}

deliveryChanged(attestationLink, canvas) {
deliveryChanged( pdf) {
this.setState({
...this.state,
'attestationLink': attestationLink,
'canvas': canvas
'pdf': pdf
})
}

Expand Down
2 changes: 1 addition & 1 deletion docker-compose-travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ services:
mock-nlx:
build: mock-nlx/
ports:
- 4080:4080
- 80:80
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"EPHEMERAL_ENDPOINT" : "http://localhost:3232",
"EPHEMERAL_WEBSOCKET_ENDPOINT" : "ws://localhost:3233",
"NLX_OUTWAY_ENDPOINT" : "http://mock-nlx:4080",
"NLX_OUTWAY_ENDPOINT" : "http://mock-nlx:80",
"NLX_CERT": "/certs/org.crt",
"NLX_KEY": "/certs/org.key",
"LOG_LEVEL": "info",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"EPHEMERAL_ENDPOINT" : "http://localhost:3232",
"EPHEMERAL_WEBSOCKET_ENDPOINT" : "ws://localhost:3233",
"NLX_OUTWAY_ENDPOINT" : "http://localhost:4080",
"NLX_OUTWAY_ENDPOINT" : "http://localhost:80",
"NLX_CERT": "/certs/org.crt",
"NLX_KEY": "/certs/org.key",
"LOG_LEVEL": "info",
Expand Down

0 comments on commit 5fd416d

Please sign in to comment.