Feature: Choosing between Portrait and Landscape orientation for Multi Page Layout

This commit is contained in:
YAOU Reda 2025-10-19 16:13:22 +02:00
parent 002bfbad69
commit 84db4e5f2e
4 changed files with 23 additions and 7 deletions

View File

@ -51,6 +51,7 @@ public class MultiPageLayoutController {
int pagesPerSheet = request.getPagesPerSheet();
MultipartFile file = request.getFileInput();
String orientation = request.getOrientation();
boolean addBorder = Boolean.TRUE.equals(request.getAddBorder());
if (pagesPerSheet != 2
@ -69,14 +70,14 @@ public class MultiPageLayoutController {
PDDocument newDocument =
pdfDocumentFactory.createNewDocumentBasedOnOldDocument(sourceDocument);
// Create a new A4 landscape rectangle that will be used when pagesPerSheet is 2 or 3
// Create a new A4 landscape rectangle that we use when orientation is landscape
PDRectangle a4Landscape =
new PDRectangle(PDRectangle.A4.getHeight(), PDRectangle.A4.getWidth());
PDPage newPage =
(pagesPerSheet == 2 || pagesPerSheet == 3)
? new PDPage(a4Landscape)
: new PDPage(PDRectangle.A4);
"PORTRAIT".equals(orientation)
? new PDPage(PDRectangle.A4)
: new PDPage(a4Landscape);
newDocument.addPage(newPage);
int totalPages = sourceDocument.getNumberOfPages();
@ -97,9 +98,9 @@ public class MultiPageLayoutController {
// Close the current content stream and create a new page and content stream
contentStream.close();
newPage =
(pagesPerSheet == 2 || pagesPerSheet == 3)
? new PDPage(a4Landscape)
: new PDPage(PDRectangle.A4);
"PORTRAIT".equals(orientation)
? new PDPage(PDRectangle.A4)
: new PDPage(a4Landscape);
newDocument.addPage(newPage);
contentStream =
new PDPageContentStream(

View File

@ -19,6 +19,13 @@ public class MergeMultiplePagesRequest extends PDFFile {
allowableValues = {"2", "3", "4", "9", "16"})
private int pagesPerSheet;
@Schema(
description = "The orientation of the output PDF pages",
type = "string",
defaultValue = "PORTRAIT",
allowableValues = {"PORTRAIT", "LANDSCAPE"})
private String orientation;
@Schema(description = "Boolean for if you wish to add border around the pages")
private Boolean addBorder;
}

View File

@ -1152,6 +1152,7 @@ pipeline.title=Pipeline
pageLayout.title=Multi Page Layout
pageLayout.header=Multi Page Layout
pageLayout.pagesPerSheet=Pages per sheet:
pageLayout.orientation=Orientation:
pageLayout.addBorder=Add Borders
pageLayout.submit=Submit

View File

@ -28,6 +28,13 @@
<option value="16">16</option>
</select>
</div>
<div class="mb-3">
<label for="orientation" th:text="#{pageLayout.orientation}"></label>
<select class="form-control" id="orientation" name="orientation">
<option value="PORTRAIT">Portrait</option>
<option value="LANDSCAPE">Landscape</option>
</select>
</div>
<div class="form-check mb-3">
<input id="addBorder" name="addBorder" type="checkbox">
<label for="addBorder" th:text="#{pageLayout.addBorder}"></label>