Created
April 11, 2021 14:17
-
-
Save allaniftrue/36122e4273770d21cf07ed08b69a33f3 to your computer and use it in GitHub Desktop.
Dompdf API response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const b64ToBlob = (b64Data, contentType = '', sliceSize = 512) => { | |
const byteCharacters = atob(b64Data); | |
const byteArrays = []; | |
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) { | |
const slice = byteCharacters.slice(offset, offset + sliceSize); | |
const byteNumbers = new Array(slice.length); | |
for (let i = 0; i < slice.length; i++) { | |
byteNumbers[i] = slice.charCodeAt(i); | |
} | |
const byteArray = new Uint8Array(byteNumbers); | |
byteArrays.push(byteArray); | |
} | |
const blob = new Blob(byteArrays, { type: contentType }); | |
return blob; | |
} | |
handleDownload = async (row, event) => { | |
await axios.get(`feature/${feature.id}`/pdf) | |
.then(response => { | |
const blob = b64ToBlob(response.data.pdf, 'application/pdf') | |
const blobUrl = URL.createObjectURL(blob); | |
window.open(blobUrl) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function pdf($id) | |
{ | |
//... | |
$pdf = PDF::loadView('pdf.payroll'); | |
return response()->json([ | |
'pdf' => base64_encode($pdf->output()) | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment