Added createPdf
This commit is contained in:
parent
6dd982d5fd
commit
fd004980ab
2 changed files with 79 additions and 0 deletions
77
src/utils/functions/createPdf.ts
Normal file
77
src/utils/functions/createPdf.ts
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
import jsPDF from 'jspdf'
|
||||
|
||||
export default () => {
|
||||
const doc = new jsPDF({
|
||||
orientation: 'p',
|
||||
unit: 'mm',
|
||||
format: 'letter',
|
||||
})
|
||||
|
||||
const lungsod = new Image()
|
||||
lungsod.src = 'src/assets/images/lungsod2.png'
|
||||
|
||||
const ocbo = new Image()
|
||||
ocbo.src = 'src/assets/images/ocbologo.png'
|
||||
|
||||
// const lungsodItem = document.getElementById('lungsod')
|
||||
// const lungsodSrc = lungsodItem?.getAttribute('src')
|
||||
// const lungsodLink = document.createElement('a')
|
||||
// lungsodLink.href = lungsodSrc ?? ''
|
||||
|
||||
// const ocboItem = document.getElementById('ocbo')
|
||||
// const ocboSrc = ocboItem?.getAttribute('src')
|
||||
// const ocboLink = document.createElement('a')
|
||||
// ocboLink.href = ocboSrc ?? ''
|
||||
|
||||
const getTextWidth = (text: string, fontSize: number) => {
|
||||
doc.setFontSize(fontSize)
|
||||
return doc.getStringUnitWidth(text) * fontSize * 0.35
|
||||
}
|
||||
|
||||
const pageWidth = doc.internal.pageSize.getWidth()
|
||||
|
||||
const republicText = 'Republic of the Philippines'
|
||||
const republicTextWidth = getTextWidth(republicText, 10)
|
||||
const officeText = 'OFFICE OF THE CITY BUILDING OFFICIAL'
|
||||
const officeTextWidth = getTextWidth(officeText, 11)
|
||||
const cityText = 'City of Davao'
|
||||
const cityTextWidth = getTextWidth(cityText, 10)
|
||||
|
||||
const republicTextX = (pageWidth - republicTextWidth) / 2
|
||||
const officeTextX = (pageWidth - officeTextWidth) / 2
|
||||
const cityTextX = (pageWidth - cityTextWidth) / 2
|
||||
|
||||
doc.setFont('helvetica', 'normal')
|
||||
doc.setFontSize(10)
|
||||
doc.text(republicText, republicTextX, 14)
|
||||
doc.setFont('helvetica', 'bold')
|
||||
doc.setFontSize(11)
|
||||
doc.text(officeText, officeTextX, 19)
|
||||
doc.setFont('helvetica', 'normal')
|
||||
doc.setFontSize(10)
|
||||
doc.text(cityText, cityTextX, 24)
|
||||
|
||||
doc.addImage(lungsod, 'PNG', 12, 8, 20, 20, 'lungsod', 'NONE', 0)
|
||||
doc.addImage(ocbo, 'PNG', pageWidth - 36, 8, 20, 20, 'ocbo', 'NONE', 0)
|
||||
|
||||
// doc.setLineWidth(0.9)
|
||||
// doc.line(10, 34, pageWidth - 10, 34)
|
||||
|
||||
const opText = 'ORDER OF PAYMENT'
|
||||
const opTextWidth = getTextWidth(opText, 10)
|
||||
const opTextX = (pageWidth - opTextWidth) / 2
|
||||
|
||||
doc.setFont('helvetica', 'bold')
|
||||
doc.setFontSize(10)
|
||||
doc.text(opText, opTextX, 34)
|
||||
|
||||
const divisionText = 'ELECTRICAL PERMIT'
|
||||
const divisionTextWidth = getTextWidth(divisionText, 9)
|
||||
const divisionTextX = (pageWidth - divisionTextWidth) / 2
|
||||
|
||||
doc.setFont('helvetica', 'normal')
|
||||
doc.setFontSize(9)
|
||||
doc.text(divisionText, divisionTextX, 39)
|
||||
|
||||
doc.save('Sample')
|
||||
}
|
||||
|
|
@ -1 +1,3 @@
|
|||
export { default as checkConnection } from './checkConnection'
|
||||
export { default as createPdf } from './createPdf'
|
||||
// export { default as generateFavicon } from './generateFavicon'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue