Many Changes
This commit is contained in:
@@ -1,26 +1,6 @@
|
||||
import {PDFDocument, StandardFonts, rgb} from "pdf-lib"
|
||||
|
||||
let headerData = {
|
||||
sender: "Federspiel Technology UG haftungsbeschränkt, Am Schwarzen Brack 14 26452 Sande",
|
||||
recipient: {
|
||||
name: "NOA Service GmbH",
|
||||
contact: "Lena Kramer",
|
||||
special: "Hinterm Haus",
|
||||
address: "Oldenburger Str. 52",
|
||||
city: "26340 Zetel"
|
||||
},
|
||||
info: {
|
||||
invoiceNumber: "RE23-1409",
|
||||
customerNumber: "10069",
|
||||
invoiceDate: "15.09.2023",
|
||||
dateOfPerformance: "31.08.2023",
|
||||
contactPerson: "Florian Federspiel",
|
||||
tel: "015755769509",
|
||||
email: "f.federspiel@federspiel.tech"
|
||||
},
|
||||
title: "Rechnung-Nr. RE23-1409",
|
||||
description: "BV: Stubbendränk 23, 26340 Zetel"
|
||||
}
|
||||
|
||||
|
||||
const getCoordinatesForPDFLib = (x ,y, page) => {
|
||||
/*
|
||||
@@ -45,7 +25,7 @@ const getCoordinatesForPDFLib = (x ,y, page) => {
|
||||
|
||||
|
||||
|
||||
export const useCreatePdf = async (invoiceData) => {
|
||||
export const useCreatePdf = async (invoiceData,backgroundSourceBuffer) => {
|
||||
|
||||
const uri = ref("test")
|
||||
const genPDF = async () => {
|
||||
@@ -57,11 +37,13 @@ export const useCreatePdf = async (invoiceData) => {
|
||||
let pages = []
|
||||
let pageCounter = 1
|
||||
|
||||
const backgroundPdfSourceBuffer = await fetch("/Briefpapier.pdf").then((res) => res.arrayBuffer())
|
||||
const backgroudPdf = await PDFDocument.load(backgroundPdfSourceBuffer)
|
||||
|
||||
|
||||
//const backgroundPdfSourceBuffer = await fetch("/Briefpapier.pdf").then((res) => res.arrayBuffer())
|
||||
const backgroudPdf = await PDFDocument.load(backgroundSourceBuffer)
|
||||
|
||||
const firstPageBackground = await pdfDoc.embedPage(backgroudPdf.getPages()[0])
|
||||
const secondPageBackground = await pdfDoc.embedPage(backgroudPdf.getPages()[1])
|
||||
const secondPageBackground = await pdfDoc.embedPage(backgroudPdf.getPages()[backgroudPdf.getPages().length > 1 ? 1 : 0])
|
||||
|
||||
//console.log("TEST")
|
||||
const page1 = pdfDoc.addPage()
|
||||
@@ -142,40 +124,124 @@ export const useCreatePdf = async (invoiceData) => {
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
pages[pageCounter - 1].drawText(invoiceData.recipient.contact, {
|
||||
...getCoordinatesForPDFLib(21,60, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
pages[pageCounter - 1].drawText(invoiceData.recipient.special, {
|
||||
...getCoordinatesForPDFLib(21,65, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
if(invoiceData.recipient.contact && !invoiceData.recipient.special) {
|
||||
pages[pageCounter - 1].drawText(invoiceData.recipient.contact, {
|
||||
...getCoordinatesForPDFLib(21,60, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
pages[pageCounter - 1].drawText(invoiceData.recipient.street, {
|
||||
...getCoordinatesForPDFLib(21,65, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
pages[pageCounter - 1].drawText(`${invoiceData.recipient.zip} ${invoiceData.recipient.city}`, {
|
||||
...getCoordinatesForPDFLib(21,70, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
} else if(invoiceData.recipient.contact && invoiceData.recipient.special) {
|
||||
pages[pageCounter - 1].drawText(invoiceData.recipient.contact, {
|
||||
...getCoordinatesForPDFLib(21,60, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
pages[pageCounter - 1].drawText(invoiceData.recipient.special, {
|
||||
...getCoordinatesForPDFLib(21,65, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.recipient.street, {
|
||||
...getCoordinatesForPDFLib(21,70, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
pages[pageCounter - 1].drawText(`${invoiceData.recipient.zip} ${invoiceData.recipient.city}`, {
|
||||
...getCoordinatesForPDFLib(21,75, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
} else if(!invoiceData.recipient.contact && !invoiceData.recipient.special) {
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.recipient.street, {
|
||||
...getCoordinatesForPDFLib(21,60, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
pages[pageCounter - 1].drawText(`${invoiceData.recipient.zip} ${invoiceData.recipient.city}`, {
|
||||
...getCoordinatesForPDFLib(21,65, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
} else {
|
||||
pages[pageCounter - 1].drawText(invoiceData.recipient.contact, {
|
||||
...getCoordinatesForPDFLib(21,60, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
pages[pageCounter - 1].drawText(invoiceData.recipient.special, {
|
||||
...getCoordinatesForPDFLib(21,65, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.recipient.street, {
|
||||
...getCoordinatesForPDFLib(21,70, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
pages[pageCounter - 1].drawText(`${invoiceData.recipient.zip} ${invoiceData.recipient.city}`, {
|
||||
...getCoordinatesForPDFLib(21,75, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.recipient.street, {
|
||||
...getCoordinatesForPDFLib(21,70, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
pages[pageCounter - 1].drawText(`${invoiceData.recipient.zip} ${invoiceData.recipient.city}`, {
|
||||
...getCoordinatesForPDFLib(21,75, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -198,7 +264,7 @@ export const useCreatePdf = async (invoiceData) => {
|
||||
opacity: 1
|
||||
})*/
|
||||
|
||||
pages[pageCounter - 1].drawText("Rechnungsnummer", {
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.documentNumberTitle, {
|
||||
...getCoordinatesForPDFLib(126,55, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
@@ -207,9 +273,9 @@ export const useCreatePdf = async (invoiceData) => {
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.documentNumber, {
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.documentNumber ? invoiceData.info.documentNumber : "XXXX", {
|
||||
y: getCoordinatesForPDFLib(126,55, page1).y,
|
||||
x: getCoordinatesForPDFLib(126,55,page1).x + 210 - font.widthOfTextAtSize(headerData.info.invoiceNumber,10),
|
||||
x: getCoordinatesForPDFLib(126,55,page1).x + 210 - font.widthOfTextAtSize(invoiceData.info.documentNumber ? invoiceData.info.documentNumber : "XXXX",10),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
@@ -227,7 +293,7 @@ export const useCreatePdf = async (invoiceData) => {
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.customerNumber, {
|
||||
y: getCoordinatesForPDFLib(126,60, page1).y,
|
||||
x: getCoordinatesForPDFLib(126,60,page1).x + 210 - font.widthOfTextAtSize(headerData.info.customerNumber,10),
|
||||
x: getCoordinatesForPDFLib(126,60,page1).x + 210 - font.widthOfTextAtSize(invoiceData.info.customerNumber,10),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
@@ -246,15 +312,7 @@ export const useCreatePdf = async (invoiceData) => {
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.documentDate, {
|
||||
y: getCoordinatesForPDFLib(126,65, page1).y,
|
||||
x: getCoordinatesForPDFLib(126,65,page1).x + 210 - font.widthOfTextAtSize(headerData.info.invoiceDate,10),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
pages[pageCounter - 1].drawText("Lieferdatum", {
|
||||
...getCoordinatesForPDFLib(126,70, page1),
|
||||
x: getCoordinatesForPDFLib(126,65,page1).x + 210 - font.widthOfTextAtSize(invoiceData.info.documentDate,10),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
@@ -262,15 +320,28 @@ export const useCreatePdf = async (invoiceData) => {
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.deliveryDate, {
|
||||
y: getCoordinatesForPDFLib(126,70, page1).y,
|
||||
x: getCoordinatesForPDFLib(126,70,page1).x + 210 - font.widthOfTextAtSize(invoiceData.info.deliveryDate,10),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
if(invoiceData.info.deliveryDateType !== "Kein Lieferdatum anzeigen") {
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.deliveryDateType, {
|
||||
...getCoordinatesForPDFLib(126,70, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.deliveryDate, {
|
||||
y: getCoordinatesForPDFLib(126,70, page1).y,
|
||||
x: getCoordinatesForPDFLib(126,70,page1).x + 210 - font.widthOfTextAtSize(invoiceData.info.deliveryDate,10),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
pages[pageCounter - 1].drawText("Ansprechpartner", {
|
||||
...getCoordinatesForPDFLib(126,75, page1),
|
||||
@@ -291,43 +362,86 @@ export const useCreatePdf = async (invoiceData) => {
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
pages[pageCounter - 1].drawText("Telefon", {
|
||||
...getCoordinatesForPDFLib(126,80, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
if(invoiceData.info.contactTel && invoiceData.info.contactEMail) {
|
||||
pages[pageCounter - 1].drawText("Telefon", {
|
||||
...getCoordinatesForPDFLib(126,80, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.contactTel, {
|
||||
y: getCoordinatesForPDFLib(126,80, page1).y,
|
||||
x: getCoordinatesForPDFLib(126,80,page1).x + 210 - font.widthOfTextAtSize(invoiceData.info.contactTel,10),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
pages[pageCounter - 1].drawText("E-Mail", {
|
||||
...getCoordinatesForPDFLib(126,85, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.contactEMail, {
|
||||
y: getCoordinatesForPDFLib(126,85, page1).y,
|
||||
x: getCoordinatesForPDFLib(126,85,page1).x + 210 - font.widthOfTextAtSize(invoiceData.info.contactEMail,10),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
} else if(invoiceData.info.contactTel && !invoiceData.info.contactEMail) {
|
||||
pages[pageCounter - 1].drawText("Telefon", {
|
||||
...getCoordinatesForPDFLib(126,80, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.contactTel, {
|
||||
y: getCoordinatesForPDFLib(126,80, page1).y,
|
||||
x: getCoordinatesForPDFLib(126,80,page1).x + 210 - font.widthOfTextAtSize(invoiceData.info.contactTel,10),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
} else if(!invoiceData.info.contactTel && invoiceData.info.contactEMail) {
|
||||
pages[pageCounter - 1].drawText("E-Mail", {
|
||||
...getCoordinatesForPDFLib(126,80, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.contactEMail, {
|
||||
y: getCoordinatesForPDFLib(126,80, page1).y,
|
||||
x: getCoordinatesForPDFLib(126,80,page1).x + 210 - font.widthOfTextAtSize(invoiceData.info.contactEMail,10),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
}
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.contactTel, {
|
||||
y: getCoordinatesForPDFLib(126,80, page1).y,
|
||||
x: getCoordinatesForPDFLib(126,80,page1).x + 210 - font.widthOfTextAtSize(invoiceData.info.contactTel,10),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
pages[pageCounter - 1].drawText("E-Mail", {
|
||||
...getCoordinatesForPDFLib(126,85, page1),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.info.contactEMail, {
|
||||
y: getCoordinatesForPDFLib(126,85, page1).y,
|
||||
x: getCoordinatesForPDFLib(126,85,page1).x + 210 - font.widthOfTextAtSize(invoiceData.info.contactEMail,10),
|
||||
size:10,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:10,
|
||||
opacity: 1,
|
||||
maxWidth: 240
|
||||
})
|
||||
/*pages[pageCounter - 1].drawText("Projekt:", {
|
||||
...getCoordinatesForPDFLib(126,90, page1),
|
||||
size:10,
|
||||
@@ -382,14 +496,17 @@ export const useCreatePdf = async (invoiceData) => {
|
||||
opacity: 1
|
||||
})*/
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.description, {
|
||||
...getCoordinatesForPDFLib(20,112, page1),
|
||||
size:13,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:15,
|
||||
opacity: 1,
|
||||
maxWidth: 500
|
||||
})
|
||||
if(invoiceData.description) {
|
||||
pages[pageCounter - 1].drawText(invoiceData.description, {
|
||||
...getCoordinatesForPDFLib(20,112, page1),
|
||||
size:13,
|
||||
color:rgb(0,0,0),
|
||||
lineHeight:15,
|
||||
opacity: 1,
|
||||
maxWidth: 500
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
pages[pageCounter - 1].drawText(invoiceData.startText,{
|
||||
...getCoordinatesForPDFLib(20,119, page1),
|
||||
|
||||
Reference in New Issue
Block a user