Commit a521ee5e authored by Hermann Owren Elton's avatar Hermann Owren Elton Committed by Olaf Rosendahl
Browse files

Fixed PDFcreator and change layout in PDF

parent 8f91c4ae
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" version="4">
<component name="FacetManager">
<facet type="jpa" name="JPA">
<configuration>
<setting name="validation-enabled" value="true" />
<datasource-mapping>
<factory-entry name="Database" value="bf5a09e6-a24e-431b-a948-8d6107c78421" />
<factory-entry name="Database-setup" />
</datasource-mapping>
<naming-strategy-map />
<deploymentDescriptor name="persistence.xml" url="file://$MODULE_DIR$/src/main/resources/META-INF/persistence.xml" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/App" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:win:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:win:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:win:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:win:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-web:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-web:win:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-media:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-media:win:11" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.16" level="project" />
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:3.6.1" level="project" />
<orderEntry type="library" name="Maven: javaxt:javaxt-core:1.7.8" level="project" />
<orderEntry type="library" name="Maven: org.hibernate:hibernate-core:5.4.1.Final" level="project" />
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.2.Final" level="project" />
<orderEntry type="library" name="Maven: javax.persistence:javax.persistence-api:2.2" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.24.0-GA" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.9.5" level="project" />
<orderEntry type="library" name="Maven: antlr:antlr:2.7.7" level="project" />
<orderEntry type="library" name="Maven: org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.1.1.Final" level="project" />
<orderEntry type="library" name="Maven: org.jboss:jandex:2.0.5.Final" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.4" level="project" />
<orderEntry type="library" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
<orderEntry type="library" name="Maven: org.dom4j:dom4j:2.1.1" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:5.1.0.Final" level="project" />
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jaxb:jaxb-runtime:2.3.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jaxb:txw2:2.3.1" level="project" />
<orderEntry type="library" name="Maven: com.sun.istack:istack-commons-runtime:3.0.7" level="project" />
<orderEntry type="library" name="Maven: org.jvnet.staxex:stax-ex:1.8" level="project" />
<orderEntry type="library" name="Maven: com.sun.xml.fastinfoset:FastInfoset:1.2.15" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.6.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.6.0" level="project" />
<orderEntry type="library" name="Maven: com.itextpdf:itextpdf:5.5.13.1" level="project" />
<orderEntry type="library" name="Maven: com.cloudinary:cloudinary-http44:1.25.0" level="project" />
<orderEntry type="library" name="Maven: com.cloudinary:cloudinary-core:1.25.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.4" level="project" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" version="4">
<component name="FacetManager">
<facet type="jpa" name="JPA">
<configuration>
<setting name="validation-enabled" value="true" />
<datasource-mapping>
<factory-entry name="Database" value="bf5a09e6-a24e-431b-a948-8d6107c78421" />
<factory-entry name="Database-setup" />
</datasource-mapping>
<naming-strategy-map />
<deploymentDescriptor name="persistence.xml" url="file://$MODULE_DIR$/src/main/resources/META-INF/persistence.xml" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/App" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:win:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:win:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:win:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:win:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-web:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-web:win:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-media:11" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-media:win:11" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.16" level="project" />
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:3.6.1" level="project" />
<orderEntry type="library" name="Maven: javaxt:javaxt-core:1.7.8" level="project" />
<orderEntry type="library" name="Maven: org.hibernate:hibernate-core:5.4.1.Final" level="project" />
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.2.Final" level="project" />
<orderEntry type="library" name="Maven: javax.persistence:javax.persistence-api:2.2" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.24.0-GA" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.9.5" level="project" />
<orderEntry type="library" name="Maven: antlr:antlr:2.7.7" level="project" />
<orderEntry type="library" name="Maven: org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.1.1.Final" level="project" />
<orderEntry type="library" name="Maven: org.jboss:jandex:2.0.5.Final" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.4" level="project" />
<orderEntry type="library" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
<orderEntry type="library" name="Maven: org.dom4j:dom4j:2.1.1" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:5.1.0.Final" level="project" />
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jaxb:jaxb-runtime:2.3.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jaxb:txw2:2.3.1" level="project" />
<orderEntry type="library" name="Maven: com.sun.istack:istack-commons-runtime:3.0.7" level="project" />
<orderEntry type="library" name="Maven: org.jvnet.staxex:stax-ex:1.8" level="project" />
<orderEntry type="library" name="Maven: com.sun.xml.fastinfoset:FastInfoset:1.2.15" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.6.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.6.0" level="project" />
<orderEntry type="library" name="Maven: com.itextpdf:itextpdf:5.5.13.1" level="project" />
<orderEntry type="library" name="Maven: com.cloudinary:cloudinary-http44:1.25.0" level="project" />
<orderEntry type="library" name="Maven: com.cloudinary:cloudinary-core:1.25.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.4" level="project" />
</component>
</module>
......@@ -2,6 +2,8 @@ package Components;
import Database.HibernateClasses.Photo;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileOutputStream;
......@@ -17,8 +19,9 @@ public final class PDFCreator {
private static Document document;
private static List<Photo> photos;
private static String albumName;
private static Font smallFont = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD);
private static Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
private static Font smallFont = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD);
private static Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 22, Font.BOLD);
private static Font imageFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
/**
* Private constructor to hinder creation of utility class
......@@ -41,10 +44,11 @@ public final class PDFCreator {
albumName = name;
document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(saveLocation));
document.open();
addHeader();
addImageContainers();
document.close();
}
......@@ -76,10 +80,6 @@ public final class PDFCreator {
Paragraph imagesContainer = new Paragraph();
addEmptyLineTo(imagesContainer, 1);
Paragraph images = new Paragraph("Images", smallFont);
addEmptyLineTo(images, 1);
imagesContainer.add(images);
document.add(imagesContainer);
addAllImages();
}
......@@ -92,22 +92,54 @@ public final class PDFCreator {
*/
private static void addAllImages() throws DocumentException, IOException {
for (Photo photo : photos) {
Paragraph photoBox = new Paragraph();
Paragraph imageBox = new Paragraph();
Image image = Image.getInstance(photo.getUrl());
scaleImage(image);
imageBox.add(image);
PdfPTable photoBox = createTable(photo);
Paragraph titleBox = new Paragraph(photo.getTitle());
Paragraph emptyLines = new Paragraph();
addEmptyLineTo(emptyLines, 4);
photoBox.add(0, titleBox);
photoBox.add(1, imageBox);
addEmptyLineTo(photoBox, 2);
document.add(photoBox);
document.add(emptyLines);
}
}
/**
* Creates a PdfTable
*
* @param photo the photo that is being added to the table
* @return the finished table
* @throws DocumentException
* @throws IOException
*/
private static PdfPTable createTable(Photo photo) throws DocumentException, IOException {
Image image = Image.getInstance(photo.getUrl());
scaleImage(image);
PdfPTable photoBox = new PdfPTable(2);
photoBox.setWidthPercentage(100);
photoBox.setWidths(new int[]{1, 2});
photoBox.addCell(createTextCell(photo.getTitle()));
photoBox.addCell(new PdfPCell(image, true));
return photoBox;
}
/**
* Creates a text cell that is positioned to the left of the table
*
* @param text the text in the cell
* @return the finished cell
*/
private static PdfPCell createTextCell(String text) {
PdfPCell cell = new PdfPCell();
Paragraph p = new Paragraph(text, imageFont);
p.setAlignment(Element.ALIGN_LEFT);
cell.addElement(p);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setBorder(Rectangle.NO_BORDER);
return cell;
}
/**
* Scales the images according to the ratio between the height and the width of the image.
*
......@@ -115,11 +147,11 @@ public final class PDFCreator {
*/
private static void scaleImage(Image image) {
if (image.getWidth() == image.getHeight()) {
image.scaleToFit(300, 300);
image.scaleToFit(400, 400);
} else if (image.getWidth() > image.getHeight()) {
image.scaleToFit(300, 600);
image.scaleToFit(400, 800);
} else {
image.scaleToFit(600, 300);
image.scaleToFit(800, 400);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment