Merge branch 'main' of https://github.com/dm1sh/timetable-generator into main
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import React from "react";
|
||||
import styles from "./styles/App.module.css";
|
||||
import { createDocument } from "./utils/pdf";
|
||||
|
||||
const App: React.FC = () => {
|
||||
return (
|
||||
<div>
|
||||
<h1 className={styles.title}>Hello, world</h1>
|
||||
<button onClick={() => createDocument(11, 18)}>Create</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
4
src/custom.d.ts
vendored
4
src/custom.d.ts
vendored
@@ -7,3 +7,7 @@ declare module "*.module.css" {
|
||||
const classes: { [key: string]: string };
|
||||
export default classes;
|
||||
}
|
||||
declare module "*.ttf" {
|
||||
const content: string;
|
||||
export default content;
|
||||
}
|
||||
|
BIN
src/fonts/PTSerif-Bold.ttf
Normal file
BIN
src/fonts/PTSerif-Bold.ttf
Normal file
Binary file not shown.
BIN
src/fonts/PTSerif-Regular.ttf
Normal file
BIN
src/fonts/PTSerif-Regular.ttf
Normal file
Binary file not shown.
@@ -2,6 +2,6 @@
|
||||
color: red;
|
||||
}
|
||||
/*just test sunlime merge*/
|
||||
body{
|
||||
background-color: blue;
|
||||
}
|
||||
body {
|
||||
background-color: blue;
|
||||
}
|
||||
|
114
src/utils/pdf.ts
Normal file
114
src/utils/pdf.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
import pdfMake from "pdfmake/build/pdfmake";
|
||||
import { TableCell, TDocumentDefinitions } from "pdfmake/interfaces";
|
||||
|
||||
import vfs from "./vfsFonts";
|
||||
|
||||
pdfMake.vfs = vfs;
|
||||
|
||||
pdfMake.fonts = {
|
||||
PTSerif: {
|
||||
normal: "PTSerifRegular.ttf",
|
||||
bold: "PTSerifBold.ttf",
|
||||
},
|
||||
};
|
||||
|
||||
const months = [
|
||||
"Января",
|
||||
"Февраля",
|
||||
"Марта",
|
||||
"Апреля",
|
||||
"Мая",
|
||||
"Июня",
|
||||
"Июля",
|
||||
"Августа",
|
||||
"Сентября",
|
||||
"Октября",
|
||||
"Ноября",
|
||||
"Декабря",
|
||||
];
|
||||
|
||||
const getDate = () => {
|
||||
const now = new Date();
|
||||
return `${now.getDate()} ${months[now.getDay()]} ${now.getFullYear()} года`;
|
||||
};
|
||||
|
||||
const getGroupNumber = (gen: number): number => {
|
||||
while (gen > 9) {
|
||||
gen -= 9;
|
||||
}
|
||||
|
||||
return gen;
|
||||
};
|
||||
|
||||
export const createDocument = (
|
||||
classNumber: number,
|
||||
generation: number
|
||||
): void => {
|
||||
const doc: TDocumentDefinitions = {
|
||||
content: [
|
||||
{
|
||||
text: "УТВЕРЖДЕН",
|
||||
style: "ral",
|
||||
},
|
||||
{
|
||||
text: "приказом БОУ «Югорский физико-математический лицей-интернат»",
|
||||
style: "ral",
|
||||
},
|
||||
{
|
||||
text: `№ от ${getDate()}`,
|
||||
style: "ral",
|
||||
margin: [0, 0, 0, 10],
|
||||
},
|
||||
{
|
||||
table: {
|
||||
widths: [
|
||||
"4.37%",
|
||||
"4.37%",
|
||||
"8.8%",
|
||||
"13.7%",
|
||||
"13.7%",
|
||||
"13.7%",
|
||||
"13.7%",
|
||||
"13.7%",
|
||||
"13.7%",
|
||||
],
|
||||
body: [
|
||||
[
|
||||
{ text: "Пара", rowSpan: 2, margin: [0, 10, 0, 0] },
|
||||
{ text: "Урок", rowSpan: 2, margin: [0, 10, 0, 0] },
|
||||
{ text: "Время", rowSpan: 2, margin: [0, 10, 0, 0] },
|
||||
...["А", "Б", "В"].flatMap<TableCell>(word => [
|
||||
{
|
||||
colSpan: 2,
|
||||
text: `${classNumber} «${word}» класс`,
|
||||
},
|
||||
{},
|
||||
]),
|
||||
],
|
||||
[
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
...[1, 2, 3, 4, 5, 6].map<TableCell>(groupIndex => ({
|
||||
text: `${getGroupNumber(generation)}${groupIndex} группа`,
|
||||
})),
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
defaultStyle: {
|
||||
font: "PTSerif",
|
||||
fontSize: 12,
|
||||
alignment: "center",
|
||||
},
|
||||
styles: {
|
||||
ral: {
|
||||
alignment: "right",
|
||||
},
|
||||
},
|
||||
pageOrientation: "landscape",
|
||||
};
|
||||
|
||||
pdfMake.createPdf(doc).download("test.pdf");
|
||||
};
|
12
src/utils/vfsFonts.ts
Normal file
12
src/utils/vfsFonts.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import regular from "../fonts/PTSerif-Regular.ttf";
|
||||
import bold from "../fonts/PTSerif-Bold.ttf";
|
||||
|
||||
import pdfFonts from "pdfmake/build/vfs_fonts";
|
||||
|
||||
pdfFonts.pdfMake.vfs["PTSerifRegular.ttf"] = regular.slice(
|
||||
regular.indexOf(",")
|
||||
);
|
||||
|
||||
pdfFonts.pdfMake.vfs["PTSerifBold.ttf"] = bold.slice(bold.indexOf(","));
|
||||
|
||||
export default pdfFonts.pdfMake.vfs;
|
Reference in New Issue
Block a user