Skip to content

Commit

Permalink
code formatting, move to java 8, drop ant in favor of maven
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanpas committed Oct 9, 2018
1 parent d54a2ce commit 0ab2a06
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 256 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.class
*.pdf
*.odt
pom.properties
.settings
.project
.classpath
.vscode
target
10 changes: 0 additions & 10 deletions Makefile

This file was deleted.

98 changes: 0 additions & 98 deletions build.xml

This file was deleted.

38 changes: 19 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>yanpas</groupId>
<artifactId>pdfmerger</artifactId>
<version>1.0</version>
<version>1.1</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<name>Pdf Merger</name>
<url>https://github.com/Yanpas/PdfMerger</url>

<dependencies>
<dependency>
<groupId>pdfbox</groupId>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2.0</version>
<version>2.0.12</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>yanpas.pdfmerger.PdfMerger</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>

</project>
15 changes: 7 additions & 8 deletions src/main/java/yanpas/pdfmerger/Merger.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ class Merger implements AutoCloseable {
private PDDocumentOutline outOutline = new PDDocumentOutline();
private PDDocument outDocument = new PDDocument();

private void addOutlines(Iterable<PDOutlineItem> itemCollection, PDOutlineItem rootItem,
PDDocument inDoc) throws IOException {
private void addOutlines(Iterable<PDOutlineItem> itemCollection, PDOutlineItem rootItem, PDDocument inDoc)
throws IOException {
for (PDOutlineItem item : itemCollection) {
PDPage destPage = null;
destPage = item.findDestinationPage(inDoc);
PDOutlineItem outItem = new PDOutlineItem();
if (destPage != null) {
PDPage itemDestPage =
outDocument.getPages().get(inDoc.getPages().indexOf(destPage) + outPagesN);
PDPage itemDestPage = outDocument.getPages().get(inDoc.getPages().indexOf(destPage) + outPagesN);
outItem.setDestination(itemDestPage);
}
outItem.setTitle(item.getTitle());
Expand All @@ -39,7 +38,7 @@ private void appendDoc(final File inFile) throws IOException {
try {
inDocuments.push(PDDocument.load(inFile));
} catch (IOException e) {
throw new IOException("File \"" + inFile.getAbsolutePath() + "\" seems to be non-pdf");
throw new IOException("File \"" + inFile.getAbsolutePath() + "\" seems to be non-pdf", e);
}

PDDocument inDoc = inDocuments.peek();
Expand All @@ -48,10 +47,10 @@ private void appendDoc(final File inFile) throws IOException {
return;
String finname = inFile.getName();
if (finname.length() > 4)
finname = finname.substring(0,finname.length()-4);
finname = finname.substring(0, finname.length() - 4);
PDDocumentOutline inOutline = inDoc.getDocumentCatalog().getDocumentOutline();

for (int i=0; i<inPagesN; ++i)
for (int i = 0; i < inPagesN; ++i)
outDocument.addPage(inDoc.getPage(i));

PDOutlineItem outRoot = new PDOutlineItem();
Expand Down Expand Up @@ -84,4 +83,4 @@ public void close() {
System.err.println(e.getLocalizedMessage());
}
}
}
}
9 changes: 5 additions & 4 deletions src/main/java/yanpas/pdfmerger/PdfMerger.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ public static void main(String[] args) {
}

try (Merger m = new Merger()) {
for(File file : infiles) {
System.out.println("Processing "+file.getName());
for (File file : infiles) {
System.out.println("Processing " + file.getName());
m.addDocument(file);
}
System.out.println("Saving");
m.save(outname);
} catch (IOException e){
} catch (IOException e) {
System.err.println(e.getLocalizedMessage());
System.err.println("Stack trace:");
e.printStackTrace();
System.exit(1);
}
}
}
}
}
Loading

0 comments on commit 0ab2a06

Please sign in to comment.