Added option to split PDF into multiple parts and merge into one PDF (#841)

* Added option to split PDF into multiple parts and merge into one PDF

* Use the mergeDocuments method in MergeController to implement merging

---------

Co-authored-by: Eric <71648843+sbplat@users.noreply.github.com>
pull/855/head^2
懒猫 3 months ago committed by GitHub
parent af68c70239
commit c8a37245fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      pipeline/defaultWebUIConfigs/split-rotate-auto-rename.json
  2. 2
      src/main/java/stirling/software/SPDF/controller/api/MergeController.java
  3. 19
      src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java
  4. 3
      src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java
  5. 2
      src/main/resources/messages_ar_AR.properties
  6. 2
      src/main/resources/messages_bg_BG.properties
  7. 2
      src/main/resources/messages_ca_CA.properties
  8. 2
      src/main/resources/messages_de_DE.properties
  9. 2
      src/main/resources/messages_el_GR.properties
  10. 2
      src/main/resources/messages_en_GB.properties
  11. 2
      src/main/resources/messages_en_US.properties
  12. 2
      src/main/resources/messages_es_ES.properties
  13. 2
      src/main/resources/messages_eu_ES.properties
  14. 2
      src/main/resources/messages_fr_FR.properties
  15. 2
      src/main/resources/messages_hi_IN.properties
  16. 2
      src/main/resources/messages_hu_HU.properties
  17. 2
      src/main/resources/messages_id_ID.properties
  18. 2
      src/main/resources/messages_it_IT.properties
  19. 2
      src/main/resources/messages_ja_JP.properties
  20. 2
      src/main/resources/messages_ko_KR.properties
  21. 2
      src/main/resources/messages_nl_NL.properties
  22. 2
      src/main/resources/messages_pl_PL.properties
  23. 2
      src/main/resources/messages_pt_BR.properties
  24. 2
      src/main/resources/messages_pt_PT.properties
  25. 2
      src/main/resources/messages_ro_RO.properties
  26. 2
      src/main/resources/messages_ru_RU.properties
  27. 2
      src/main/resources/messages_sr_LATN_RS.properties
  28. 2
      src/main/resources/messages_sv_SE.properties
  29. 2
      src/main/resources/messages_tr_TR.properties
  30. 2
      src/main/resources/messages_zh_CN.properties
  31. 2
      src/main/resources/messages_zh_TW.properties
  32. 3
      src/main/resources/templates/split-pdf-by-sections.html

@ -6,7 +6,8 @@
"parameters": {
"horizontalDivisions": 2,
"verticalDivisions": 2,
"fileInput": "automated"
"fileInput": "automated",
"merge": false
}
},
{
@ -30,4 +31,4 @@
},
"outputDir": "{outputFolder}",
"outputFileName": "{filename}"
}
}

@ -38,7 +38,7 @@ public class MergeController {
private static final Logger logger = LoggerFactory.getLogger(MergeController.class);
private PDDocument mergeDocuments(List<PDDocument> documents) throws IOException {
public PDDocument mergeDocuments(List<PDDocument> documents) throws IOException {
PDDocument mergedDoc = new PDDocument();
for (PDDocument doc : documents) {
for (PDPage page : doc.getPages()) {

@ -53,8 +53,21 @@ public class SplitPdfBySectionsController {
// Process the PDF based on split parameters
int horiz = request.getHorizontalDivisions() + 1;
int verti = request.getVerticalDivisions() + 1;
boolean merge = request.isMerge();
List<PDDocument> splitDocuments = splitPdfPages(sourceDocument, verti, horiz);
String filename =
Filenames.toSimpleFileName(file.getOriginalFilename())
.replaceFirst("[.][^.]+$", "");
if (merge) {
MergeController mergeController = new MergeController();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mergeController.mergeDocuments(splitDocuments).save(baos);
return WebResponseUtils.bytesToWebResponse(
baos.toByteArray(),
filename + "_split.pdf",
MediaType.APPLICATION_OCTET_STREAM);
}
for (PDDocument doc : splitDocuments) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos);
@ -65,9 +78,6 @@ public class SplitPdfBySectionsController {
sourceDocument.close();
Path zipFile = Files.createTempFile("split_documents", ".zip");
String filename =
Filenames.toSimpleFileName(file.getOriginalFilename())
.replaceFirst("[.][^.]+$", "");
byte[] data;
try (ZipOutputStream zipOut = new ZipOutputStream(Files.newOutputStream(zipFile))) {
@ -145,4 +155,5 @@ public class SplitPdfBySectionsController {
return splitDocuments;
}
}

@ -15,4 +15,7 @@ public class SplitPdfBySectionsRequest extends PDFFile {
@Schema(description = "Number of vertical divisions for each PDF page", example = "2")
private int verticalDivisions;
@Schema(description = "Merge the split documents into a single PDF", example = "true")
private boolean merge;
}

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertikale Teiler
split-by-sections.horizontal.placeholder=Anzahl horizontaler Teiler eingeben
split-by-sections.vertical.placeholder=Anzahl vertikaler Teiler eingeben
split-by-sections.submit=PDF teilen
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Lizenzen

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Divisiones Verticales
split-by-sections.horizontal.placeholder=Introduzca el número de divisiones horizontales
split-by-sections.vertical.placeholder=Introduzca el número de divisiones verticales
split-by-sections.submit=Dividir PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licencias

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Divisions verticales
split-by-sections.horizontal.placeholder=Saisir le nombre de divisions horizontales
split-by-sections.vertical.placeholder=Entrer le nombre de divisions verticales
split-by-sections.submit=Diviser le PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licences

@ -960,7 +960,7 @@ split-by-sections.vertical.label=लबवत विजन
split-by-sections.horizontal.placeholder=किज विजन क दरज कर
split-by-sections.vertical.placeholder=लबवत विजन क दरज कर
split-by-sections.submit=PDF किित कर
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vízszintes szakaszok
split-by-sections.horizontal.placeholder=Adja meg a vízszintes szakaszok számát
split-by-sections.vertical.placeholder=Adja meg a függőleges szakaszok számát
split-by-sections.submit=Felosztás
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Pembagian Vertikal
split-by-sections.horizontal.placeholder=Input angka untuk pembagian horizontal
split-by-sections.vertical.placeholder=Input angka untuk pembagian vertikal
split-by-sections.submit=Pisahkan PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Divisioni verticali
split-by-sections.horizontal.placeholder=Inserire il numero di divisioni orizzontali
split-by-sections.vertical.placeholder=Inserire il numero di divisioni verticali
split-by-sections.submit=Dividi PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenze

@ -960,7 +960,7 @@ split-by-sections.vertical.label=垂直方向
split-by-sections.horizontal.placeholder=水平方向の分割数を選択
split-by-sections.vertical.placeholder=垂直方向の分割数を選択
split-by-sections.submit=分割
split-by-sections.merge=1 つの PDF に結合するかどうか
#licenses
licenses.nav=ライセンス

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Verticale secties
split-by-sections.horizontal.placeholder=Voer het aantal horizontale secties in
split-by-sections.vertical.placeholder=Voer het aantal verticale secties in
split-by-sections.submit=PDF splitsen
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenties

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -958,7 +958,7 @@ split-by-sections.vertical.label=Divisões Verticais
split-by-sections.horizontal.placeholder=Introduza o número de divisões horizontais
split-by-sections.vertical.placeholder=Introduza o número de divisões verticais
split-by-sections.submit=Dividir PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenças

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertikalne podele
split-by-sections.horizontal.placeholder=Unesite broj horizontalnih podele
split-by-sections.vertical.placeholder=Unesite broj vertikalnih podele
split-by-sections.submit=Razdvoji PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=Vertical Divisions
split-by-sections.horizontal.placeholder=Enter number of horizontal divisions
split-by-sections.vertical.placeholder=Enter number of vertical divisions
split-by-sections.submit=Split PDF
split-by-sections.merge=Merge Into One PDF
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=垂直分割
split-by-sections.horizontal.placeholder=输入水平分割数
split-by-sections.vertical.placeholder=输入垂直分割数
split-by-sections.submit=分割PDF
split-by-sections.merge=是否合并为一个pdf
#licenses
licenses.nav=Licenses

@ -960,7 +960,7 @@ split-by-sections.vertical.label=垂直劃分
split-by-sections.horizontal.placeholder=輸入水平劃分的數量
split-by-sections.vertical.placeholder=輸入垂直劃分的數量
split-by-sections.submit=分割 PDF
split-by-sections.merge=是否合併為一個pdf
#licenses
licenses.nav=Licenses

@ -23,6 +23,9 @@
<label for="verticalDivisions" th:text="#{split-by-sections.vertical.label}">Vertical Divisions</label>
<input type="number" id="verticalDivisions" name="verticalDivisions" class="form-control" min="0" max="300" required value="1" th:placeholder="#{split-by-sections.vertical.placeholder}">
<br>
<label for="verticalDivisions" th:text="#{split-by-sections.merge}">merge PDFs into one</label>
<input type="checkbox" id="merge" name="merge" th:placeholder="#{split-by-sections.merge}">
<br>
<div id="pdfVisualAid" class="pdf-visual-aid"></div>
<script>
function updateVisualAid() {

Loading…
Cancel
Save