Skip to content

Commit 7c89f83

Browse files
committed
ref #179: added a smooth transition between single digit to two digits
pdf version
1 parent d0706b2 commit 7c89f83

File tree

4 files changed

+102
-3
lines changed

4 files changed

+102
-3
lines changed

sejda-console/src/main/java/org/sejda/cli/model/CliArgumentsWithPdfOutput.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
package org.sejda.cli.model;
2121

22-
import org.sejda.conversion.PdfVersionAdapter;
22+
import org.sejda.conversion.PdfVersionAdapterWithFallback;
2323

2424
import uk.co.flamingpenguin.jewel.cli.Option;
2525

@@ -35,5 +35,5 @@ public interface CliArgumentsWithPdfOutput extends TaskCliArguments {
3535
boolean getCompressed();
3636

3737
@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")
38-
PdfVersionAdapter getPdfVersion();
38+
PdfVersionAdapterWithFallback getPdfVersion();
3939
}

sejda-console/src/main/java/org/sejda/cli/transformer/BaseCliArgumentsTransformer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private void populateCommonImageOutputParameters(AbstractPdfToImageParameters pa
130130
private void populateCommonPdfOutputParameters(AbstractPdfOutputParameters parameters,
131131
CliArgumentsWithPdfOutput taskCliArguments) {
132132
parameters.setCompress(taskCliArguments.getCompressed());
133-
parameters.setVersion(taskCliArguments.getPdfVersion().getEnumValue());
133+
parameters.setVersion(taskCliArguments.getPdfVersion().getVersion());
134134
}
135135

136136
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Created on 17 gen 2016
3+
* Copyright 2015 by Andrea Vacondio (andrea.vacondio@gmail.com).
4+
* This file is part of Sejda.
5+
*
6+
* Sejda is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Sejda is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with Sejda. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package org.sejda.conversion;
20+
21+
import org.sejda.model.pdf.PdfVersion;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
25+
/**
26+
* Adapter providing a smooth transition between single digit pdf versions (7 for pdf version 1.7) used in sejda-console v1.x to double digit pdf version (1.7 for pdf version 1.7)
27+
* used in sejda-console v2.x
28+
*
29+
* @author Andrea Vacondio
30+
*
31+
*/
32+
public class PdfVersionAdapterWithFallback {
33+
private static final Logger LOG = LoggerFactory.getLogger(PdfVersionAdapterWithFallback.class);
34+
35+
private PdfVersion version;
36+
37+
public PdfVersionAdapterWithFallback(String userFriendlyName) {
38+
if (userFriendlyName.matches("[01234567]{1}")) {
39+
LOG.warn(
40+
"Single digit PDF version '{}' is deprecated and will be removed in future releases, please use the two digits '1.{}' format",
41+
userFriendlyName, userFriendlyName);
42+
this.version = new PdfVersionAdapter("1." + userFriendlyName).getEnumValue();
43+
} else {
44+
this.version = new PdfVersionAdapter(userFriendlyName).getEnumValue();
45+
}
46+
}
47+
48+
public PdfVersion getVersion() {
49+
return version;
50+
}
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Created on 17 gen 2016
3+
* Copyright 2015 by Andrea Vacondio (andrea.vacondio@gmail.com).
4+
* This file is part of Sejda.
5+
*
6+
* Sejda is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Sejda is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with Sejda. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package org.sejda.conversion;
20+
21+
import static org.junit.Assert.assertEquals;
22+
23+
import org.junit.Test;
24+
import org.sejda.model.exception.SejdaRuntimeException;
25+
import org.sejda.model.pdf.PdfVersion;
26+
27+
/**
28+
* @author Andrea Vacondio
29+
*
30+
*/
31+
public class PdfVersionAdapterWithFallbackTest {
32+
@Test
33+
public void testPositiveFallback() {
34+
assertEquals(PdfVersion.VERSION_1_4, new PdfVersionAdapterWithFallback("4").getVersion());
35+
}
36+
37+
@Test
38+
public void testPositive() {
39+
assertEquals(PdfVersion.VERSION_1_6, new PdfVersionAdapterWithFallback("1.6").getVersion());
40+
}
41+
42+
@Test(expected = SejdaRuntimeException.class)
43+
public void missingPoint() {
44+
new PdfVersionAdapterWithFallback("9").getVersion();
45+
}
46+
47+
}

0 commit comments

Comments
 (0)