From 138b1dd2853ac643e1a7f015d5d84649fd275194 Mon Sep 17 00:00:00 2001 From: ln803631 Date: Fri, 13 Sep 2019 15:35:54 +0200 Subject: [PATCH 1/7] Add new directory --- NGCC/src/GenerateurPdf/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 NGCC/src/GenerateurPdf/.gitkeep diff --git a/NGCC/src/GenerateurPdf/.gitkeep b/NGCC/src/GenerateurPdf/.gitkeep new file mode 100644 index 0000000..e69de29 From 8c50b795ed3dfc76db2dd05fad4ebf2813e9ebf0 Mon Sep 17 00:00:00 2001 From: ln803631 Date: Fri, 13 Sep 2019 15:36:12 +0200 Subject: [PATCH 2/7] Upload New File --- NGCC/src/GenerateurPdf/SubjectGenerator.java | 138 +++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 NGCC/src/GenerateurPdf/SubjectGenerator.java diff --git a/NGCC/src/GenerateurPdf/SubjectGenerator.java b/NGCC/src/GenerateurPdf/SubjectGenerator.java new file mode 100644 index 0000000..1cd0be7 --- /dev/null +++ b/NGCC/src/GenerateurPdf/SubjectGenerator.java @@ -0,0 +1,138 @@ +package util; + +import java.awt.Color; +import java.io.IOException; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.PDPageContentStream; +import org.apache.pdfbox.pdmodel.common.PDRectangle; +import org.apache.pdfbox.pdmodel.font.PDFont; +import org.apache.pdfbox.pdmodel.font.PDType1Font; + +// infor concernant strok, fill, ... : https://stackoverflow.com/a/27959484 + +public class SubjectGenerator { + + private static void drawCircle(PDPageContentStream contentStream, int cx, int cy, int r) throws IOException { + // https://stackoverflow.com/a/42836210 + final float k = 0.552284749831f; + contentStream.moveTo(cx - r, cy); + contentStream.curveTo(cx - r, cy + (k * r), cx - (k * r), cy + r, cx, cy + r); + contentStream.curveTo(cx + (k * r), cy + r, cx + r, cy + (k * r), cx + r, cy); + contentStream.curveTo(cx + r, cy - (k * r), cx + (k * r), cy - r, cx, cy - r); + contentStream.curveTo(cx - (k * r), cy - r, cx - r, cy - (k * r), cx - r, cy); + contentStream.fill(); + } + + public static PDDocument generateMarks(PDDocument pdDocument) { + for (PDPage page : pdDocument.getPages()) { + try { + PDPageContentStream pdPageContentStream = new PDPageContentStream(pdDocument, page); + PDFont font = PDType1Font.TIMES_ROMAN; + + int height = (int) page.getMediaBox().getHeight(); + int width = (int) page.getMediaBox().getWidth(); + + // Set a Color for the marks + pdPageContentStream.setNonStrokingColor(Color.BLACK); + pdPageContentStream.setNonStrokingColor(0, 0, 0); // black text + pdPageContentStream.setFont(font, 9); + + // generate circle marks in corners + SubjectGenerator.drawCircle(pdPageContentStream, 20, height - 30, 5); // top left + SubjectGenerator.drawCircle(pdPageContentStream, width - 20, height - 30, 5); // top right + SubjectGenerator.drawCircle(pdPageContentStream, 20, 30, 5); // bottom left + SubjectGenerator.drawCircle(pdPageContentStream, width - 20, 30, 5); // bottom right + + pdPageContentStream.setLineWidth(0.6f); // largeur du contour des rectangles + + // generate rectangles id (?) + for (int i = 0; i < 12; i++) { + // draw first range of rectangles + pdPageContentStream.addRect(170 + (9 * i), height - 15, 9, 9); + // + 9 * i = position du ieme carre + // draw second range of rectangles + pdPageContentStream.addRect(170 + (9 * i), height - 27, 9, 9); + // + 9 * i = position du ieme carre + } + + // generate rectangles numero etudiant + for (int i = 0; i <= 9; i++) { + // draw first range of rectangles + pdPageContentStream.addRect(80 + (22 * i), height - 107, 11, 11); + // write first range of numbers + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset(80 + (22 * i) + 12, height - 105); + pdPageContentStream.showText(String.valueOf(i)); + pdPageContentStream.endText(); + // draw second range of rectangles + pdPageContentStream.addRect(80 + (22 * i), height - 124, 11, 11); + // write second range of numbers + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset(80 + (22 * i) + 12, height - 122); + pdPageContentStream.showText(String.valueOf(i)); + pdPageContentStream.endText(); + } + + pdPageContentStream.setFont(font, 10); + // generate rectangle nom + pdPageContentStream.addRect(width - 238, height - 196, 155, 50); // RECT + // text + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset(width - 236, height - 156); + pdPageContentStream.showText("Ecrivez votre Nom"); + pdPageContentStream.endText(); + // dot lines + pdPageContentStream.moveTo(width - 233, height - 175); + for (int i = (width - 233); i <= (width - 90); i += 3) { + pdPageContentStream.lineTo(i, height - 175); + pdPageContentStream.moveTo(i + 2, height - 175); + } + + pdPageContentStream.stroke(); // stroke + + // pdPageContentStream.fill(); + pdPageContentStream.closeAndStroke(); + + // draw the separative line + pdPageContentStream.moveTo(28, height - 239); + pdPageContentStream.lineTo(width - 28, height - 239); + + // pdPageContentStream.lineTo(width - 28, height - 239); + pdPageContentStream.stroke(); // stroke + pdPageContentStream.close(); + + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + return pdDocument; + } + + public void generateHeader(PDDocument pdDocument) { + try { + PDPageContentStream pdPageContentStream = new PDPageContentStream(pdDocument, pdDocument.getPage(0)); + PDFont font = PDType1Font.HELVETICA_BOLD; + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + + public static void main(String args[]) throws IOException { + // Create a Document object. + PDDocument pdDocument = new PDDocument(); + // Create a Page object + PDPage pdPage = new PDPage(PDRectangle.A4); + + // Add the page to the document and save the document to a desired file. + pdDocument.addPage(pdPage); + + pdDocument = SubjectGenerator.generateMarks(pdDocument); + + // pdDocument.save("C:\\Users\\Nico\\Desktop\\testPDFMarks.pdf"); + pdDocument.save("E:\\testPDFMarks.pdf"); + pdDocument.close(); + System.out.println("PDF saved to the location !!!"); + } +} From d04a3a010c2d623785aadf9c30cbd75da4bcdf2a Mon Sep 17 00:00:00 2001 From: ln803631 Date: Fri, 13 Sep 2019 21:06:10 +0200 Subject: [PATCH 3/7] =?UTF-8?q?Ajout=20de=20modifications=20dans=20l'en-t?= =?UTF-8?q?=C3=AAte=20:=20-=20Titre=20et=20sous-titre=20du=20sujet=20centr?= =?UTF-8?q?=C3=A9s=20par=20rapport=20=C3=A0=20la=20page=20-=20Num=C3=A9ro?= =?UTF-8?q?=20d'identification=20de=20la=20page=20(ex=20:=20+1/1/60+)=20-?= =?UTF-8?q?=20Autres=20modifications=20de=20disposition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NGCC/src/GenerateurPdf/SubjectGenerator.java | 38 +++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/NGCC/src/GenerateurPdf/SubjectGenerator.java b/NGCC/src/GenerateurPdf/SubjectGenerator.java index 1cd0be7..eb71e1a 100644 --- a/NGCC/src/GenerateurPdf/SubjectGenerator.java +++ b/NGCC/src/GenerateurPdf/SubjectGenerator.java @@ -1,4 +1,4 @@ -package util; +package GenerateurPdf; import java.awt.Color; import java.io.IOException; @@ -83,12 +83,20 @@ public class SubjectGenerator { pdPageContentStream.newLineAtOffset(width - 236, height - 156); pdPageContentStream.showText("Ecrivez votre Nom"); pdPageContentStream.endText(); + // --- TODO : a optimiser --- \\ // dot lines pdPageContentStream.moveTo(width - 233, height - 175); for (int i = (width - 233); i <= (width - 90); i += 3) { pdPageContentStream.lineTo(i, height - 175); pdPageContentStream.moveTo(i + 2, height - 175); + } + pdPageContentStream.moveTo(width - 233, height - 190); + for (int i = (width - 233); i <= (width - 90); i += 3) { + pdPageContentStream.lineTo(i, height - 190); + pdPageContentStream.moveTo(i + 2, height - 190); + } + // --- TODO : a optimiser --- \\ pdPageContentStream.stroke(); // stroke @@ -101,6 +109,34 @@ public class SubjectGenerator { // pdPageContentStream.lineTo(width - 28, height - 239); pdPageContentStream.stroke(); // stroke + + pdPageContentStream.setFont(font, 11); + + // number (top of page) +n/n/nn+ + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset((width / 2) + 86, height - 30); + pdPageContentStream.showText("+1/1/60+"); + pdPageContentStream.endText(); + + pdPageContentStream.setFont(font, 12); + // Sujet + // center text : https://stackoverflow.com/a/6531362 + String subject = "Exemple PT S3T : de 1970 à l’an 2000, 30 ans d’histoire"; + int fontSize = 12; + float titleWidth = (font.getStringWidth(subject) / 1000) * fontSize; + float titleHeight = (font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000) * fontSize; + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset((width - titleWidth) / 2, (height - 57 - titleHeight)); + pdPageContentStream.showText(subject); + pdPageContentStream.endText(); + + String subtitle = "Tricherie : Toutes consultations de sources numériques sont interdites !!"; + titleWidth = (font.getStringWidth(subtitle) / 1000) * fontSize; + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset((width - titleWidth) / 2, (height - 71 - titleHeight)); + pdPageContentStream.showText(subtitle); + pdPageContentStream.endText(); + pdPageContentStream.close(); } catch (IOException ioe) { From 85401518ec92b308c52dc442ada4acc25f127a45 Mon Sep 17 00:00:00 2001 From: ln803631 Date: Sat, 14 Sep 2019 11:03:48 +0200 Subject: [PATCH 4/7] =?UTF-8?q?-=20G=C3=A9n=C3=A9ration=20des=20footers=20?= =?UTF-8?q?ajout=C3=A9e=20-=20ajout=20de=20compl=C3=A9ments=20dans=20l'en-?= =?UTF-8?q?t=C3=AAte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NGCC/src/GenerateurPdf/SubjectGenerator.java | 73 ++++++++++++++++++-- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/NGCC/src/GenerateurPdf/SubjectGenerator.java b/NGCC/src/GenerateurPdf/SubjectGenerator.java index eb71e1a..205526f 100644 --- a/NGCC/src/GenerateurPdf/SubjectGenerator.java +++ b/NGCC/src/GenerateurPdf/SubjectGenerator.java @@ -25,10 +25,40 @@ public class SubjectGenerator { contentStream.fill(); } + public static PDDocument generateFooter(PDDocument pdDocument) { + int nbTotal = pdDocument.getNumberOfPages(); + int count = 1; + + try { + for (PDPage page : pdDocument.getPages()) { + PDPageContentStream pdPageContentStream = new PDPageContentStream(pdDocument, page, + PDPageContentStream.AppendMode.APPEND, true); + PDFont font = PDType1Font.TIMES_ROMAN; + int width = (int) page.getMediaBox().getWidth(); + int fontSize = 10; + pdPageContentStream.setFont(font, fontSize); + String footer = String.valueOf(count) + " / " + String.valueOf(nbTotal); + float titleWidth = (font.getStringWidth(footer) / 1000) * fontSize; + float titleHeight = (font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000) * fontSize; + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset((width - titleWidth) / 2, (35 - titleHeight)); + pdPageContentStream.showText(footer); + pdPageContentStream.endText(); + pdPageContentStream.close(); + count++; + } + } catch (IOException ioe) { + ioe.printStackTrace(); + } + return pdDocument; + + } + public static PDDocument generateMarks(PDDocument pdDocument) { for (PDPage page : pdDocument.getPages()) { try { - PDPageContentStream pdPageContentStream = new PDPageContentStream(pdDocument, page); + PDPageContentStream pdPageContentStream = new PDPageContentStream(pdDocument, page, + PDPageContentStream.AppendMode.APPEND, true); PDFont font = PDType1Font.TIMES_ROMAN; int height = (int) page.getMediaBox().getHeight(); @@ -118,11 +148,11 @@ public class SubjectGenerator { pdPageContentStream.showText("+1/1/60+"); pdPageContentStream.endText(); - pdPageContentStream.setFont(font, 12); // Sujet // center text : https://stackoverflow.com/a/6531362 String subject = "Exemple PT S3T : de 1970 à l’an 2000, 30 ans d’histoire"; int fontSize = 12; + pdPageContentStream.setFont(font, fontSize); float titleWidth = (font.getStringWidth(subject) / 1000) * fontSize; float titleHeight = (font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000) * fontSize; pdPageContentStream.beginText(); @@ -137,6 +167,36 @@ public class SubjectGenerator { pdPageContentStream.showText(subtitle); pdPageContentStream.endText(); + fontSize = 10; + + // 1st line + pdPageContentStream.setFont(font, fontSize); + String numConsignePart1 = " Veuillez coder votre numéro"; + + titleWidth = (font.getStringWidth(numConsignePart1) / 1000) * fontSize; + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset(width - 224, height - 94 - titleHeight); + pdPageContentStream.showText(numConsignePart1); + pdPageContentStream.endText(); + + // 2nd line + String numConsignePart2 = " d’étudiant ci-contre et écrire votre nom"; + + titleWidth = (font.getStringWidth(numConsignePart2) / 1000) * fontSize; + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset(width - 244, height - 105 - titleHeight); + pdPageContentStream.showText(numConsignePart2); + pdPageContentStream.endText(); + + // 3rd line + String numConsignePart3 = " dans la case ci-dessous."; + + titleWidth = (font.getStringWidth(numConsignePart3) / 1000) * fontSize; + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset(width - 244, height - 118 - titleHeight); + pdPageContentStream.showText(numConsignePart3); + pdPageContentStream.endText(); + pdPageContentStream.close(); } catch (IOException ioe) { @@ -159,12 +219,17 @@ public class SubjectGenerator { // Create a Document object. PDDocument pdDocument = new PDDocument(); // Create a Page object - PDPage pdPage = new PDPage(PDRectangle.A4); + PDPage pdPage1 = new PDPage(PDRectangle.A4); + PDPage pdPage2 = new PDPage(PDRectangle.A4); + PDPage pdPage3 = new PDPage(PDRectangle.A4); // Add the page to the document and save the document to a desired file. - pdDocument.addPage(pdPage); + pdDocument.addPage(pdPage1); + pdDocument.addPage(pdPage2); + pdDocument.addPage(pdPage3); pdDocument = SubjectGenerator.generateMarks(pdDocument); + pdDocument = SubjectGenerator.generateFooter(pdDocument); // pdDocument.save("C:\\Users\\Nico\\Desktop\\testPDFMarks.pdf"); pdDocument.save("E:\\testPDFMarks.pdf"); From 655ee4b52498b7cbaed03b424457f197d9a51e35 Mon Sep 17 00:00:00 2001 From: ln803631 Date: Thu, 19 Sep 2019 13:18:32 +0200 Subject: [PATCH 5/7] =?UTF-8?q?Organisation=20des=20m=C3=A9thodes=20afin?= =?UTF-8?q?=20de=20compartimenter=20les=20diff=C3=A9rentes=20aires=20du=20?= =?UTF-8?q?fichier=20pdf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NGCC/src/GenerateurPdf/SubjectGenerator.java | 141 +++++++++++++------ 1 file changed, 97 insertions(+), 44 deletions(-) diff --git a/NGCC/src/GenerateurPdf/SubjectGenerator.java b/NGCC/src/GenerateurPdf/SubjectGenerator.java index 205526f..d045dc8 100644 --- a/NGCC/src/GenerateurPdf/SubjectGenerator.java +++ b/NGCC/src/GenerateurPdf/SubjectGenerator.java @@ -87,51 +87,7 @@ public class SubjectGenerator { // + 9 * i = position du ieme carre } - // generate rectangles numero etudiant - for (int i = 0; i <= 9; i++) { - // draw first range of rectangles - pdPageContentStream.addRect(80 + (22 * i), height - 107, 11, 11); - // write first range of numbers - pdPageContentStream.beginText(); - pdPageContentStream.newLineAtOffset(80 + (22 * i) + 12, height - 105); - pdPageContentStream.showText(String.valueOf(i)); - pdPageContentStream.endText(); - // draw second range of rectangles - pdPageContentStream.addRect(80 + (22 * i), height - 124, 11, 11); - // write second range of numbers - pdPageContentStream.beginText(); - pdPageContentStream.newLineAtOffset(80 + (22 * i) + 12, height - 122); - pdPageContentStream.showText(String.valueOf(i)); - pdPageContentStream.endText(); - } - pdPageContentStream.setFont(font, 10); - // generate rectangle nom - pdPageContentStream.addRect(width - 238, height - 196, 155, 50); // RECT - // text - pdPageContentStream.beginText(); - pdPageContentStream.newLineAtOffset(width - 236, height - 156); - pdPageContentStream.showText("Ecrivez votre Nom"); - pdPageContentStream.endText(); - // --- TODO : a optimiser --- \\ - // dot lines - pdPageContentStream.moveTo(width - 233, height - 175); - for (int i = (width - 233); i <= (width - 90); i += 3) { - pdPageContentStream.lineTo(i, height - 175); - pdPageContentStream.moveTo(i + 2, height - 175); - - } - pdPageContentStream.moveTo(width - 233, height - 190); - for (int i = (width - 233); i <= (width - 90); i += 3) { - pdPageContentStream.lineTo(i, height - 190); - pdPageContentStream.moveTo(i + 2, height - 190); - } - // --- TODO : a optimiser --- \\ - - pdPageContentStream.stroke(); // stroke - - // pdPageContentStream.fill(); - pdPageContentStream.closeAndStroke(); // draw the separative line pdPageContentStream.moveTo(28, height - 239); @@ -206,6 +162,101 @@ public class SubjectGenerator { return pdDocument; } + /* + * public static PDDocument generateIDPageArea(PDDocument pdDocument) { + * + * } + */ + + public static PDDocument generateNameArea(PDDocument pdDocument) { + try { + PDPage page = pdDocument.getPage(0); + PDPageContentStream pdPageContentStream = new PDPageContentStream(pdDocument, page, + PDPageContentStream.AppendMode.APPEND, true); + PDFont font = PDType1Font.TIMES_ROMAN; + + // Set a Color for the marks + pdPageContentStream.setNonStrokingColor(Color.BLACK); + pdPageContentStream.setNonStrokingColor(0, 0, 0); // black text + pdPageContentStream.setFont(font, 9); + + int height = (int) page.getMediaBox().getHeight(); + int width = (int) page.getMediaBox().getWidth(); + + // generate rectangle nom + pdPageContentStream.addRect(width - 238, height - 196, 155, 50); // RECT + // text + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset(width - 236, height - 156); + pdPageContentStream.showText("Ecrivez votre Nom"); + pdPageContentStream.endText(); + // --- TODO : a optimiser --- \\ + // dot lines + pdPageContentStream.moveTo(width - 233, height - 175); + for (int i = (width - 233); i <= (width - 90); i += 3) { + pdPageContentStream.lineTo(i, height - 175); + pdPageContentStream.moveTo(i + 2, height - 175); + + } + pdPageContentStream.moveTo(width - 233, height - 190); + for (int i = (width - 233); i <= (width - 90); i += 3) { + pdPageContentStream.lineTo(i, height - 190); + pdPageContentStream.moveTo(i + 2, height - 190); + } + // --- TODO : a optimiser --- \\ + + pdPageContentStream.stroke(); // stroke + + // pdPageContentStream.fill(); + pdPageContentStream.closeAndStroke(); + + pdPageContentStream.close(); + + } catch (IOException ioe) { + ioe.printStackTrace(); + } + return pdDocument; + } + + public static PDDocument generateNumEtudArea(PDDocument pdDocument) { + try { + PDPage page = pdDocument.getPage(0); + PDPageContentStream pdPageContentStream = new PDPageContentStream(pdDocument, page, + PDPageContentStream.AppendMode.APPEND, true); + PDFont font = PDType1Font.TIMES_ROMAN; + + // Set a Color for the marks + pdPageContentStream.setNonStrokingColor(Color.BLACK); + pdPageContentStream.setNonStrokingColor(0, 0, 0); // black text + pdPageContentStream.setFont(font, 9); + + int height = (int) page.getMediaBox().getHeight(); + + // generate rectangles numero etudiant + for (int i = 0; i <= 9; i++) { + // draw first range of rectangles + pdPageContentStream.addRect(80 + (22 * i), height - 107, 11, 11); + // write first range of numbers + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset(80 + (22 * i) + 12, height - 105); + pdPageContentStream.showText(String.valueOf(i)); + pdPageContentStream.endText(); + // draw second range of rectangles + pdPageContentStream.addRect(80 + (22 * i), height - 124, 11, 11); + // write second range of numbers + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset(80 + (22 * i) + 12, height - 122); + pdPageContentStream.showText(String.valueOf(i)); + pdPageContentStream.endText(); + } + + pdPageContentStream.close(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + return pdDocument; + } + public void generateHeader(PDDocument pdDocument) { try { PDPageContentStream pdPageContentStream = new PDPageContentStream(pdDocument, pdDocument.getPage(0)); @@ -229,6 +280,8 @@ public class SubjectGenerator { pdDocument.addPage(pdPage3); pdDocument = SubjectGenerator.generateMarks(pdDocument); + pdDocument = SubjectGenerator.generateNumEtudArea(pdDocument); + pdDocument = SubjectGenerator.generateNameArea(pdDocument); pdDocument = SubjectGenerator.generateFooter(pdDocument); // pdDocument.save("C:\\Users\\Nico\\Desktop\\testPDFMarks.pdf"); From 1192045da86111377366064665c659c3c4668919 Mon Sep 17 00:00:00 2001 From: ln803631 Date: Thu, 26 Sep 2019 14:05:20 +0200 Subject: [PATCH 6/7] =?UTF-8?q?Correction=20d'erreurs=20li=C3=A9es=20aux?= =?UTF-8?q?=20coordonn=C3=A9es=20et=20ajout=20de=20deux=20cadres=20(num?= =?UTF-8?q?=C3=A9ro=20d'=C3=A9tudiant=20et=20note)=20afin=20de=20respecter?= =?UTF-8?q?=20l'=C3=A9tape=201=20et=20de=20ne=20prendre=20en=20compte=20qu?= =?UTF-8?q?e=20l'ocr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NGCC/src/GenerateurPdf/SubjectGenerator.java | 75 ++++++++++++++++---- 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/NGCC/src/GenerateurPdf/SubjectGenerator.java b/NGCC/src/GenerateurPdf/SubjectGenerator.java index d045dc8..eb4051b 100644 --- a/NGCC/src/GenerateurPdf/SubjectGenerator.java +++ b/NGCC/src/GenerateurPdf/SubjectGenerator.java @@ -14,6 +14,17 @@ import org.apache.pdfbox.pdmodel.font.PDType1Font; public class SubjectGenerator { + private static void drawDotedLine(PDPageContentStream contentStream, int xi, int yi, int xf, int yf) + throws IOException { + contentStream.moveTo(xi, yi); + for (int i = xi; i <= xf; i += 3) { + contentStream.lineTo(i, yf); + contentStream.moveTo(i + 2, yf); + + } + // contentStream.fill(); + } + private static void drawCircle(PDPageContentStream contentStream, int cx, int cy, int r) throws IOException { // https://stackoverflow.com/a/42836210 final float k = 0.552284749831f; @@ -190,20 +201,13 @@ public class SubjectGenerator { pdPageContentStream.newLineAtOffset(width - 236, height - 156); pdPageContentStream.showText("Ecrivez votre Nom"); pdPageContentStream.endText(); - // --- TODO : a optimiser --- \\ - // dot lines - pdPageContentStream.moveTo(width - 233, height - 175); - for (int i = (width - 233); i <= (width - 90); i += 3) { - pdPageContentStream.lineTo(i, height - 175); - pdPageContentStream.moveTo(i + 2, height - 175); - } - pdPageContentStream.moveTo(width - 233, height - 190); - for (int i = (width - 233); i <= (width - 90); i += 3) { - pdPageContentStream.lineTo(i, height - 190); - pdPageContentStream.moveTo(i + 2, height - 190); - } - // --- TODO : a optimiser --- \\ + // dot lines + // TODO: Enleve car difficulte d'ocr du fait de la presence des pointilles + // SubjectGenerator.drawDotedLine(pdPageContentStream, width - 233, height - + // 175, width - 90, height - 175); + // SubjectGenerator.drawDotedLine(pdPageContentStream, width - 233, height - + // 190, width - 90, height - 190); pdPageContentStream.stroke(); // stroke @@ -218,6 +222,47 @@ public class SubjectGenerator { return pdDocument; } + public static PDDocument generateNumEtudAreaBis(PDDocument pdDocument) { + try { + PDPage page = pdDocument.getPage(0); + PDPageContentStream pdPageContentStream = new PDPageContentStream(pdDocument, page, + PDPageContentStream.AppendMode.APPEND, true); + PDFont font = PDType1Font.TIMES_ROMAN; + + // Set a Color for the marks + pdPageContentStream.setNonStrokingColor(Color.BLACK); + pdPageContentStream.setNonStrokingColor(0, 0, 0); // black text + pdPageContentStream.setFont(font, 9); + + int height = (int) page.getMediaBox().getHeight(); + int width = (int) page.getMediaBox().getWidth(); + + // num rectangle + pdPageContentStream.addRect(width / 4, height - 146, 150, 40); + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset((width / 4) + 2, height - 115); + pdPageContentStream.showText("Ecrivez votre Numéro d'étudiant"); + pdPageContentStream.endText(); + + // note rectangle + pdPageContentStream.addRect(width / 4, height - 200, 150, 40); + pdPageContentStream.beginText(); + pdPageContentStream.newLineAtOffset((width / 4) + 2, height - 170); + pdPageContentStream.showText("Note"); + pdPageContentStream.endText(); + + // dotedlines + + // SubjectGenerator.drawDotedLine(pdPageContentStream, width - 233, height - + // 175, width - 90, height - 175); + + pdPageContentStream.close(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + return pdDocument; + } + public static PDDocument generateNumEtudArea(PDDocument pdDocument) { try { PDPage page = pdDocument.getPage(0); @@ -271,6 +316,8 @@ public class SubjectGenerator { PDDocument pdDocument = new PDDocument(); // Create a Page object PDPage pdPage1 = new PDPage(PDRectangle.A4); + // System.out.println("Height : " + pdPage1.getMediaBox().getHeight()); + // System.out.println("Width : " + pdPage1.getMediaBox().getWidth()); PDPage pdPage2 = new PDPage(PDRectangle.A4); PDPage pdPage3 = new PDPage(PDRectangle.A4); @@ -280,7 +327,7 @@ public class SubjectGenerator { pdDocument.addPage(pdPage3); pdDocument = SubjectGenerator.generateMarks(pdDocument); - pdDocument = SubjectGenerator.generateNumEtudArea(pdDocument); + pdDocument = SubjectGenerator.generateNumEtudAreaBis(pdDocument); pdDocument = SubjectGenerator.generateNameArea(pdDocument); pdDocument = SubjectGenerator.generateFooter(pdDocument); From 534475cd43d013644d8fbd25297edeeffca52931 Mon Sep 17 00:00:00 2001 From: ln803631 Date: Fri, 27 Sep 2019 10:11:40 +0200 Subject: [PATCH 7/7] =?UTF-8?q?S=C3=A9paration=20du=20cadre=20de=20note=20?= =?UTF-8?q?afin=20de=20faciliter=20l'ocr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NGCC/src/GenerateurPdf/SubjectGenerator.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NGCC/src/GenerateurPdf/SubjectGenerator.java b/NGCC/src/GenerateurPdf/SubjectGenerator.java index eb4051b..7cfade7 100644 --- a/NGCC/src/GenerateurPdf/SubjectGenerator.java +++ b/NGCC/src/GenerateurPdf/SubjectGenerator.java @@ -251,6 +251,9 @@ public class SubjectGenerator { pdPageContentStream.showText("Note"); pdPageContentStream.endText(); + pdPageContentStream.moveTo((width / 4) + 75, height - 160); + pdPageContentStream.lineTo((width / 4) + 75, height - 200); + // dotedlines // SubjectGenerator.drawDotedLine(pdPageContentStream, width - 233, height -