Delete useless package

This commit is contained in:
cl705239 2019-10-25 15:30:01 +02:00
parent 701fd5edc9
commit f26ae86707
5 changed files with 0 additions and 398 deletions

View File

@ -1,10 +0,0 @@
package RecadragePdf;
public class CorrectionPdf {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}

View File

@ -1,53 +0,0 @@
package RecadragePdf;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class DetectionPdf {
String dir="";
String filename="";
BufferedImage img;
public DetectionPdf(String directory,String file) {
dir=directory;
filename=file;
File f =new File(dir+filename);
try {
img=ImageIO.read(f);
} catch (IOException e) {
System.out.println(e);
}
}
public boolean estDroite() { //determine si l'image png/jpg du pdf est droite
int count=0;
boolean stop=false;
for (int ty=0; ty<100 && !stop;ty++) {
for (int tx=0;tx<img.getWidth();tx++) {
Color tmp=new Color(img.getRGB(tx, ty));
if (tmp.getGreen()<10) {
count++;
stop=true;
}
}
}
if (count>img.getWidth()/5.4 && count <img.getWidth()/5)
return true;
return false;
}
public static void main(String avg[])
{
DetectionPdf rec=new DetectionPdf ("C:\\Users\\kg403211\\eclipse-workspace\\QCM\\src\\RecadragePdf\\Pdf\\","DOC-sujet.pdf");
System.out.println(rec.estDroite());
}
}

View File

@ -1,38 +0,0 @@
import java.io.File;
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.util.Matrix;
public class LoadingExistingDocument {
public static void main(String args[]) throws IOException {
//Loading an existing document
File file = new File("P:\\Bureau\\ptut s3\\eclipse\\image\\DOC-corrige.pdf");
PDDocument document = PDDocument.load(file);
PDPage page = document.getDocumentCatalog().getPages().get(0);
PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false);
cs.transform(Matrix.getRotateInstance(Math.toRadians(45), 0, 0));
System.out.println("PDF loaded");
cs.close();
//Adding a blank page to the document
document.addPage(new PDPage());
//Saving the document
document.save("P:\\Bureau\\ptut s3\\eclipse\\image\\sample.pdf");
document.
//Closing the document
document.close();
}
}

View File

@ -1,195 +0,0 @@
package RecadragePdf;
import java.awt.Color;
import java.awt.image.BufferedImage;
// https://www.dyclassroom.com/image-processing-project/how-to-get-and-set-pixel-value-in-java
// https://stackoverflow.com/a/7750416
// https://stackoverflow.com/a/14514504
// https://stackoverflow.com/questions/9589297/findout-if-the-page-is-bw-or-color-in-pdf-using-java
// https://pdfbox.apache.org/2.0/migration.html
// http://www.kscodes.com/java/draw-rectangle-using-apache-pdfbox/
// https://www.javatpoint.com/pdfbox-adding-rectangles
// https://stackoverflow.com/a/33440883
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
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;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
public class PdfAnalyzer {
public BufferedImage blackWhiteConvert(BufferedImage image) {
// TODO : voir recursivite
int width = image.getWidth();
int height = image.getHeight();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if (image.getRGB(x, y) < 128) {
image.setRGB(x, y, 0);
} else {
image.setRGB(x, y, 255);
}
}
}
return image;
}
public boolean isBlackWhite(BufferedImage image) {
// TODO : voir recursivite
int width = image.getWidth();
int height = image.getHeight();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if ((image.getRGB(x, y) != 0) || (image.getRGB(x, y) != 255)) {
return false;
}
}
}
return true;
}
public ArrayList<BufferedImage> convertPagesToBWJPG(PDDocument document) {
ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();
PDFRenderer pdfRenderer = new PDFRenderer(document);
try {
int pageCounter = 0;
for (PDPage page : document.getPages()) {
System.out.println("page.getRotation() : " + page.getRotation());
System.out.println("pageCounter : " + pageCounter);
BufferedImage bim = pdfRenderer.renderImageWithDPI(pageCounter++, 300, ImageType.BINARY); // BINARY =
// noir et
// blanc
images.add(bim);
System.out.println("Ajout n°" + pageCounter);
}
// document.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return images;
}
public void saveOnDisk(ArrayList<BufferedImage> images, String originalFileName) {
int pageCounter = 0;
try {
for (BufferedImage img : images) {
ImageIO.write(img, "JPEG", new File(originalFileName + pageCounter++ + ".jpg"));
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
// public void drawRectangle(int x, int y)
public static void main(String args[]) throws IOException {
/*
* Pattern p = Pattern.compile("\\d{1,16}"); Matcher m = p.matcher("123456789");
* boolean b = m.matches();
*/
PdfAnalyzer pdfAnalyzer = new PdfAnalyzer();
File pdfFile;
PDDocument document = null;
ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();
BufferedImage img = null;
// File f = null;
// CONVERT PAGES TO IMAGES
try {
String pdfFilename = "C:\\Users\\Nico\\Desktop\\M3302 - Sujet S3T 2019.pdf";
pdfFile = new File(pdfFilename);
document = PDDocument.load(pdfFile);
images = pdfAnalyzer.convertPagesToBWJPG(document);
pdfAnalyzer.saveOnDisk(images, "C:\\Users\\Nico\\Desktop\\M3302 - Sujet S3T 2019.pdf");
} catch (IOException e) {
System.out.println(e);
} /*
* if (!pdfAnalyzer.isBlackWhite(img)) { BufferedImage bw_image =
* pdfAnalyzer.blackWhiteConvert(img); }
*/
// DRAW RECTANGLE ON X,Y
// Create a Document object.
PDDocument pdDocument = new PDDocument();
// Create a Page object
PDPage pdPage = new PDPage(PDRectangle.A4);
int height = (int) pdPage.getMediaBox().getHeight();
int width = (int) pdPage.getMediaBox().getWidth();
System.out.println(height + " " + width);
// Add the page to the document and save the document to a desired file.
pdDocument.addPage(pdPage);
try {
// Create a Content Stream
PDPageContentStream pdPageContentStream = new PDPageContentStream(pdDocument, pdPage);
// Set a Color for the Rectangle
pdPageContentStream.setNonStrokingColor(Color.BLACK);
// Give the X, Y coordinates and height and width
PDFont font = PDType1Font.HELVETICA_BOLD;
pdPageContentStream.setNonStrokingColor(0, 0, 0); // black text
pdPageContentStream.setFont(font, 9);
String title = "Evaluation Pattern";
pdPageContentStream.beginText();
pdPageContentStream.newLineAtOffset((width / 2) - title.length(), height - 10);
pdPageContentStream.showText(title);
pdPageContentStream.endText();
int count = 0;
for (int y = height - 50; y > (height / 2); y -= 25) {
// write some text
String enonce = "Question " + count + " : ...";
pdPageContentStream.beginText();
pdPageContentStream.newLineAtOffset(10, y);
pdPageContentStream.showText(enonce);
pdPageContentStream.endText();
// draw an empty rectangle
pdPageContentStream.addRect(50, y - 15, 10, 10); // X (lower left x corner), Y (lower left y corner),
// Width,
// Height
pdPageContentStream.closeAndStroke();
// write some text
pdPageContentStream.beginText();
pdPageContentStream.newLineAtOffset(70, y - 15);
pdPageContentStream.showText("Question non cochée " + count);
pdPageContentStream.endText();
// draw a filled rectangle
pdPageContentStream.addRect(200, y - 15, 10, 10);
pdPageContentStream.fill();
// write some text
pdPageContentStream.beginText();
pdPageContentStream.newLineAtOffset(220, y - 15);
pdPageContentStream.showText("Question cochée " + count++);
pdPageContentStream.endText();
}
// pdPageContentStream.fill();
// Once all the content is written, close the stream
pdPageContentStream.close();
pdDocument.save("C:\\Users\\Nico\\Desktop\\testPDFRect.pdf");
pdDocument.close();
System.out.println("PDF saved to the location !!!");
} catch (IOException ioe) {
System.out.println("Error while saving pdf" + ioe.getMessage());
}
}
}

View File

@ -1,102 +0,0 @@
package RecadragePdf;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
public class PdfToImage {
public BufferedImage blackWhiteConvert(BufferedImage image) {
// Convertit une image en image en noir et blanc
// TODO : voir recursivite
int width = image.getWidth();
int height = image.getHeight();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if (image.getRGB(x, y) < 128) {
image.setRGB(x, y, 0);
} else {
image.setRGB(x, y, 255);
}
}
}
return image;
}
public boolean isBlackWhite(BufferedImage image) {
// verifie si une image est en noir et blanc
// TODO : voir recursivite
int width = image.getWidth();
int height = image.getHeight();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if ((image.getRGB(x, y) != 0) || (image.getRGB(x, y) != 255)) {
return false;
}
}
}
return true;
}
public ArrayList<BufferedImage> convertPagesToBWJPG(PDDocument document) {
// convertit chaque page d'un document pdf en image noir et blanc
// retourne une array liste d'images
ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();
PDFRenderer pdfRenderer = new PDFRenderer(document);
try {
int pageCounter = 0;
for (PDPage page : document.getPages()) {
System.out.println("page.getRotation() : " + page.getRotation());
System.out.println("pageCounter : " + pageCounter);
BufferedImage bim = pdfRenderer.renderImageWithDPI(pageCounter++, 300, ImageType.BINARY); // BINARY =
// noir et
// blanc
images.add(bim);
System.out.println("Ajout n°" + pageCounter);
}
// document.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return images;
}
public void saveOnDisk(ArrayList<BufferedImage> images, String originalFileDir) {
// sauvegarde sur le disque les images
int pageCounter = 0;
try {
for (BufferedImage img : images) {
ImageIO.write(img, "JPEG", new File(originalFileDir + "img_" + pageCounter++ + ".jpg"));
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
public static void main(String args[]) throws IOException {
PdfAnalyzer pdfAnalyzer = new PdfAnalyzer();
File pdfFile;
PDDocument document = null;
ArrayList<BufferedImage> images = new ArrayList<BufferedImage>(); // stockera les images (resultat)
// CONVERT PAGES TO IMAGES
try {
String pdfFilename = "DOC-sujet.pdf"; // nom du fichier pdf à ouvrir (TODO: changer le chemin)
pdfFile = new File(pdfFilename); // cree un fichier pdf (non sauvegarde sur le disque)
document = PDDocument.load(pdfFile); // charge le fichier pdf cree pour le traiter
images = pdfAnalyzer.convertPagesToBWJPG(document); // appelle la methode qui convertit les pages en images
// (jpg) noir et blanches
pdfAnalyzer.saveOnDisk(images, "C:\\Users\\kg403211\\eclipse-workspace\\QCM\\src\\RecadragePdf\\Pdf"); // sauvegarde les images au chemin specifie (TODO: changer le chemin)
} catch (IOException e) {
System.out.println(e);
}
}
}