Initial commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
.idea
|
||||
.directory
|
||||
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Upload PDF</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<form action="upload.php" method="post" enctype="multipart/form-data">
|
||||
Select PDF file to upload:
|
||||
<input type="file" name="fileToUpload" id="fileToUpload">
|
||||
<input type="submit" value="Upload PDF" name="Submit">
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
$target_dir = "uploads/";
|
||||
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
|
||||
$uploadOk = 1;
|
||||
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
|
||||
|
||||
// check if file already exists
|
||||
if (file_exists($target_file)) {
|
||||
echo "Sorry, file already exists.";
|
||||
$uploadOk = 0;
|
||||
}
|
||||
|
||||
// check file size
|
||||
if ($_FILES["fileToUpload"]["size"] > 500000) {
|
||||
echo "Sorry, your file is too large.";
|
||||
$uploadOk = 0;
|
||||
}
|
||||
|
||||
// allow certain file formats
|
||||
if ($imageFileType != "pdf") {
|
||||
echo "Sorry, only PDF files are allowed.";
|
||||
$uploadOk = 0;
|
||||
}
|
||||
|
||||
// check if $uploadOk is set to 0 by an error
|
||||
if ($uploadOk == 0) {
|
||||
echo "Sorry, your file was not uploaded.";
|
||||
|
||||
// otherwise upload file
|
||||
} else {
|
||||
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
|
||||
echo "The file " . htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " has been uploaded.";
|
||||
} else {
|
||||
echo "Sorry, there was an error uploading your file.";
|
||||
}
|
||||
}
|
||||
|
||||
// process file
|
||||
$output = shell_exec("java -jar TaskSheetChecker.jar " . $target_dir . htmlspecialchars(basename($_FILES["fileToUpload"]["name"])));
|
||||
$keySeparator = ',';
|
||||
$delimiter = ';';
|
||||
|
||||
$key_array = array();
|
||||
$value_array = array();
|
||||
|
||||
$currentString = "";
|
||||
|
||||
for ($i = 0; $i < strlen($output); $i++) {
|
||||
if ($output[$i] == ',') {
|
||||
array_push($key_array, $currentString);
|
||||
$currentString = "";
|
||||
} else if ($output[$i] == ';') {
|
||||
array_push($value_array, $output[$i]);
|
||||
$currentString = "";
|
||||
} else {
|
||||
$currentString = $currentString . $output[$i];
|
||||
}
|
||||
}
|
||||
|
||||
echo count($key_array) . "<br>";
|
||||
echo count($value_array);
|
||||
|
||||
foreach ($value_array as &$value)
|
||||
echo $value . "<br>";
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Upload PDF</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php
|
||||
// TODO: php code goes here
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
.idea
|
||||
.settings
|
||||
bin
|
||||
out
|
||||
.classpath
|
||||
.project
|
||||
*.iml
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: Tsc
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
|
||||
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
|
||||
import org.apache.pdfbox.pdmodel.interactive.form.PDField;
|
||||
|
||||
public class Tsc {
|
||||
|
||||
public static void listFields(PDDocument doc) throws Exception {
|
||||
PDDocumentCatalog catalog = doc.getDocumentCatalog();
|
||||
PDAcroForm form = catalog.getAcroForm();
|
||||
List<PDField> fields = form.getFields();
|
||||
|
||||
int numberOfFields = 0;
|
||||
int filledNumberOfFields = 0;
|
||||
|
||||
for (PDField field : fields) {
|
||||
String value = field.getValueAsString().trim();
|
||||
String key = field.getPartialName();
|
||||
// System.out.println("\"" + key + "\" = \"" + value + "\"");
|
||||
System.out.print(key + "," + value + ";");
|
||||
numberOfFields++;
|
||||
if (value.length() > 0)
|
||||
filledNumberOfFields++;
|
||||
}
|
||||
|
||||
|
||||
// System.out.println("Anzahl ausfuellbarer Felder: \t" + numberOfFields);
|
||||
// System.out.println("Ausgefuellte Felder: \t\t" + filledNumberOfFields);
|
||||
// System.out.println("----------------------------------");
|
||||
if(filledNumberOfFields==numberOfFields) {
|
||||
// System.out.println("OK! Alle Felder sind ausgefuellt.");
|
||||
System.out.println("OK");
|
||||
}else {
|
||||
// System.out.println("Nicht OK!!! Einige Felder sind nicht ausgefuellt!");
|
||||
System.out.println("NOT_OK");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// System.out.println(args[0]);
|
||||
if (args.length != 1) {
|
||||
System.err.println("Uebergeben Sie den absoluten Pfad von genau einer pdf Datei als Parameter");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
File file = new File(args[0]);
|
||||
if (!file.isFile()) {
|
||||
// System.out.println("Datei \"" + file.getAbsolutePath() + "\" existiert nicht.");
|
||||
System.exit(-1);
|
||||
}
|
||||
// System.out.println("Ueberpruefe Datei: \"" + file.getAbsolutePath()+"\"");
|
||||
// System.out.println("----------------------------------");
|
||||
PDDocument doc = PDDocument.load(file);
|
||||
listFields(doc);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user