Skip to content

Commit

Permalink
ref #179: moved to a two digits version parameter. From 5 to 1.5.
Browse files Browse the repository at this point in the history
This is a breaking change to accomodate PDF version 2.0
  • Loading branch information
torakiki committed Jan 16, 2016
1 parent 6bd0cf4 commit f5d42de
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public interface CliArgumentsWithPdfOutput extends TaskCliArguments {
@Option(description = "compress output file (optional)")
boolean getCompressed();

@Option(shortName = "v", description = "pdf version of the output document/s {2, 3, 4, 5, 6 or 7}. Default is 6. (optional)", defaultValue = "6")
@Option(shortName = "v", description = "pdf version of the output document/s {1.2, 1.3, 1.4, 1.5, 1.6 or 1.7}. Default is 1.6. (optional)", defaultValue = "1.6")
PdfVersionAdapter getPdfVersion();
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void offValueCompressed() {

@Test
public void specifiedValuePdfVersion() {
AbstractPdfOutputParameters result = defaultCommandLine().with("--pdfVersion", "4").invokeSejdaConsole();
AbstractPdfOutputParameters result = defaultCommandLine().with("--pdfVersion", "1.4").invokeSejdaConsole();

assertEquals(describeExpectations(), PdfVersion.VERSION_1_4, result.getVersion());
}
Expand Down
26 changes: 13 additions & 13 deletions sejda-console/src/test/shell/commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ target/assembled/bin/sejda-console extractpages -f ../sejda-core/src/test/resour
target/assembled/bin/sejda-console extractpages --help
target/assembled/bin/sejda-console splitbysize --help
target/assembled/bin/sejda-console encrypt -h
target/assembled/bin/sejda-console encrypt -a "test a pwd" --compressed -o /tmp/sejda-smoketest/ -p [FILENUMBER]_ -f ../sejda-core/src/test/resources/pdf/large_test.pdf -v 5 -j overwrite
target/assembled/bin/sejda-console encrypt -a "test a pwd" --compressed -o /tmp/sejda-smoketest/ -p [FILENUMBER]_ -f ../sejda-core/src/test/resources/pdf/large_test.pdf -v 1.5 -j overwrite
target/assembled/bin/sejda-console rotate -h
target/assembled/bin/sejda-console rotate -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -p rotated_ -r 90 -m even --existingOutput overwrite
target/assembled/bin/sejda-console rotate -f ../sejda-core/src/test/resources/pdf/large_test.pdf ../sejda-core/src/test/resources/pdf/large_enc_test.pdf:secret123 -o /tmp/sejda-smoketest/ -p rotated_ -r 180 -m all -j overwrite -v 5
target/assembled/bin/sejda-console rotate -f ../sejda-core/src/test/resources/pdf/large_test.pdf ../sejda-core/src/test/resources/pdf/large_enc_test.pdf:secret123 -o /tmp/sejda-smoketest/ -p rotated_ -r 180 -m all -j overwrite -v 1.5
target/assembled/bin/sejda-console rotate -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -r 90 -m all -j skip
target/assembled/bin/sejda-console rotate -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -r 90 -s 4,12-14 -j overwrite
target/assembled/bin/sejda-console -h setmetadata
target/assembled/bin/sejda-console setmetadata -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/meta.pdf -a Torakiki -t "Test the title" -s "What a subject" -k "some,keywords,here" --overwrite -v 4
target/assembled/bin/sejda-console setmetadata -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/meta.pdf -a "Torakiki" -t "Test the title" -s "What a subject" -k "some,keywords,here" --overwrite -v 4
target/assembled/bin/sejda-console setmetadata -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/meta.pdf -a Torakiki -t "Test the title" -s "What a subject" -k "some,keywords,here" --overwrite -v 1.4
target/assembled/bin/sejda-console setmetadata -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/meta.pdf -a "Torakiki" -t "Test the title" -s "What a subject" -k "some,keywords,here" --overwrite -v 1.4
target/assembled/bin/sejda-console splitbysize --help
target/assembled/bin/sejda-console splitbysize -f ../sejda-core/src/test/resources/pdf/large_test.pdf -p [FILENUMBER] -o /tmp/sejda-smoketest/ -s 1000000 -j overwrite --compressed
target/assembled/bin/sejda-console splitbysize -f ../sejda-core/src/test/resources/pdf/large_enc_test.pdf:secret123 -p [FILENUMBER] -o /tmp/sejda-smoketest/ -s 1000000 -j skip --compressed
Expand Down Expand Up @@ -74,24 +74,24 @@ target/assembled/bin/sejda-console merge -d ../sejda-core/src/test/resources/pdf
target/assembled/bin/sejda-console settransitions -h
target/assembled/bin/sejda-console setpagetransitions -h
# TODO: folder contains encrypted files, maybe fix this by creating separate folders for encrypted and un-encrypted files
# target/assembled/bin/sejda-console merge -d ../sejda-core/src/test/resources/pdf/ -o /tmp/sejda-smoketest/merged.pdf --overwrite -v 7
# target/assembled/bin/sejda-console merge -d ../sejda-core/src/test/resources/pdf/ -o /tmp/sejda-smoketest/merged.pdf --overwrite -v 1.7
target/assembled/bin/sejda-console unpack -h
target/assembled/bin/sejda-console pdftomultipletiff -h
# TODO: find a pdfbox configured sejda file and smoke-run it
#target/assembled/bin/sejda-console -Dsejda.config.file=./etc/sejda.xml
target/assembled/bin/sejda-console decrypt -f ../sejda-core/src/test/resources/pdf/large_enc_test.pdf:secret123 -o /tmp/sejda-smoketest/ -p dec -j fail
target/assembled/bin/sejda-console setmetadata -h
target/assembled/bin/sejda-console setmetadata -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/meta.pdf -a "Torakiki" -t "Test the title" -s "What a subject" -k "some,keywords,here" --overwrite -v 4
target/assembled/bin/sejda-console setmetadata -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/meta2.pdf -a "Torakiki" -t "Test the title" -s "What a subject" -k "some,keywords,here" --overwrite -v 4
target/assembled/bin/sejda-console setmetadata -f /tmp/sejda-smoketest/meta.pdf -o /tmp/sejda-smoketest/meta2.pdf -a "Torakiki" -t "Test the title" -s "What a subject" --overwrite -v 4
target/assembled/bin/sejda-console setmetadata -f /tmp/sejda-smoketest/meta.pdf -o /tmp/sejda-smoketest/meta2.pdf -a "Torakiki" -t "Test the title" -s "What a subject" -k "" --overwrite -v 4
target/assembled/bin/sejda-console setmetadata -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/meta.pdf -a "Torakiki" -t "Test the title" -s "What a subject" -k "some,keywords,here" --overwrite -v 1.4
target/assembled/bin/sejda-console setmetadata -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/meta2.pdf -a "Torakiki" -t "Test the title" -s "What a subject" -k "some,keywords,here" --overwrite -v 1.4
target/assembled/bin/sejda-console setmetadata -f /tmp/sejda-smoketest/meta.pdf -o /tmp/sejda-smoketest/meta2.pdf -a "Torakiki" -t "Test the title" -s "What a subject" --overwrite -v 1.4
target/assembled/bin/sejda-console setmetadata -f /tmp/sejda-smoketest/meta.pdf -o /tmp/sejda-smoketest/meta2.pdf -a "Torakiki" -t "Test the title" -s "What a subject" -k "" --overwrite -v 1.4
target/assembled/bin/sejda-console setviewerpreferences -h
target/assembled/bin/sejda-console setviewerpreferences -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -p view_ --hideMenu --hideToolbar --displayDocTitle
target/assembled/bin/sejda-console setviewerpreferences -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -p view_ --hideMenu --hideToolbar --displayDocTitle -v 6 -j overwrite
target/assembled/bin/sejda-console setviewerpreferences -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -p view_ --hideMenu --hideToolbar --displayDocTitle -v 7 -j overwrite
target/assembled/bin/sejda-console setviewerpreferences -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -p view_ --hideMenu --hideToolbar --displayDocTitle -v 1.6 -j overwrite
target/assembled/bin/sejda-console setviewerpreferences -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -p view_ --hideMenu --hideToolbar --displayDocTitle -v 1.7 -j overwrite
target/assembled/bin/sejda-console setheaderfooter -h
target/assembled/bin/sejda-console setheaderfooter -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -d 12 -s 5- -x right -t Courier -k 1 -l "[PAGE_ARABIC] my footer" -j overwrite -v 4
target/assembled/bin/sejda-console setheaderfooter -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -s all -x right -y top -t Times-Bold -l "[PAGE_ROMAN]" -j overwrite -v 4
target/assembled/bin/sejda-console setheaderfooter -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -d 12 -s 5- -x right -t Courier -k 1 -l "[PAGE_ARABIC] my footer" -j overwrite -v 1.4
target/assembled/bin/sejda-console setheaderfooter -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -s all -x right -y top -t Times-Bold -l "[PAGE_ROMAN]" -j overwrite -v 1.4
target/assembled/bin/sejda-console pdftojpeg -h
target/assembled/bin/sejda-console pdftojpeg -f ../sejda-core/src/test/resources/pdf/medium_test.pdf -o /tmp/sejda-smoketest/ -p [FILENUMBER###20] -r 90 -j overwrite
target/assembled/bin/sejda-console pdftojpeg -f ../sejda-core/src/test/resources/pdf/medium_test.pdf -o /tmp/sejda-smoketest/ -z 1.3 -j overwrite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private void asserts(int size) throws IOException {
testContext.forEachPdfOutput(d -> {
assertEquals(Sejda.CREATOR, d.getDocumentInformation().getCreator());
assertFalse(d.isEncrypted());
assertEquals("Wrong output PDF version", PdfVersion.VERSION_1_6.getVersionAsDoubleString(), d.getVersion());
assertEquals("Wrong output PDF version", PdfVersion.VERSION_1_6.getVersionString(), d.getVersion());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public TaskTestContext assertCreator() {
*/
public TaskTestContext assertVersion(PdfVersion version) {
requirePDDocument();
assertEquals("Wrong output PDF version", version.getVersionAsDoubleString(), outputDocument.getVersion());
assertEquals("Wrong output PDF version", version.getVersionString(), outputDocument.getVersion());
return this;
}

Expand Down
49 changes: 16 additions & 33 deletions sejda-model/src/main/java/org/sejda/model/pdf/PdfVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,22 @@
*/
public enum PdfVersion implements FriendlyNamed {

VERSION_1_0(0, 1.0d, "%PDF-1.0"),
VERSION_1_1(1, 1.1d, "%PDF-1.1"),
VERSION_1_2(2, 1.2d, "%PDF-1.2"),
VERSION_1_3(3, 1.3d, "%PDF-1.3"),
VERSION_1_4(4, 1.4d, "%PDF-1.4"),
VERSION_1_5(5, 1.5d, "%PDF-1.5"),
VERSION_1_6(6, 1.6d, "%PDF-1.6"),
VERSION_1_7(7, 1.7d, "%PDF-1.7");
VERSION_1_0(1.0d, "%PDF-1.0"),
VERSION_1_1(1.1d, "%PDF-1.1"),
VERSION_1_2(1.2d, "%PDF-1.2"),
VERSION_1_3(1.3d, "%PDF-1.3"),
VERSION_1_4(1.4d, "%PDF-1.4"),
VERSION_1_5(1.5d, "%PDF-1.5"),
VERSION_1_6(1.6d, "%PDF-1.6"),
VERSION_1_7(1.7d, "%PDF-1.7");

private int version;
private double versionDouble;
private double version;
private String versionHeader;
private String displayName;

private PdfVersion(int version, double versionDouble, String versionHeader) {
private PdfVersion(double version, String versionHeader) {
this.displayName = String.valueOf(version);
this.version = version;
this.versionDouble = versionDouble;
this.versionHeader = versionHeader;
}

Expand All @@ -56,37 +54,22 @@ public String getFriendlyName() {
return displayName;
}

/**
* @return an int representation of the version
*/
public int getVersion() {
return version;
}

/**
* @return a double representation of the version
*/
public double getVersionAsDouble() {
return versionDouble;
}

/**
* @return a double representation of the version
*/
public String getVersionAsDoubleString() {
return String.valueOf(versionDouble);
public double getVersion() {
return version;
}

/**
* @return a char representation of the int version
* @return a String representation of the version
*/
public char getVersionAsCharacter() {
return String.valueOf(version).charAt(0);
public String getVersionString() {
return String.valueOf(version);
}

/**
* @return the PDF header for this version<br>
* Pdf reference 1.7, 3.4.1 File Header
* @return the PDF header for this version as specified in Chap 7.5.2 of PDF 32000-1:2008
*/
public String getVersionHeader() {
return versionHeader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void setPageLabelsOnDocument(Map<Integer, PdfPageLabel> labels) {
*/
public void setVersionOnPDDocument(PdfVersion version) {
if (version != null) {
document.setVersion(version.getVersionAsDoubleString());
document.setVersion(version.getVersionString());
LOG.trace("Version set to '{}'", version);
}
}
Expand Down

0 comments on commit f5d42de

Please sign in to comment.