1
0
mirror of https://github.com/Stirling-Tools/Stirling-PDF.git synced 2024-11-13 03:00:10 +01:00

Page Scale: add pageSize KEEP #1798 (#1800)

* add `scalePages.keepPageSize` i18n key (#1798)

* add KEEP option to frontend (#1798)

* extract ScalePagesController.getTargetSize() (#1798)

* make ScalePageController honor `pageSize` value `KEEP`

* PR feedback: make caption shorter, avoid unnecessary verbosity (#1798)

* Update messages_ar_AR.properties

---------

Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
This commit is contained in:
Ignacio Carrera 2024-09-08 17:52:50 -03:00 committed by GitHub
parent 765289c89e
commit 580313151b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
39 changed files with 83 additions and 24 deletions

View File

@ -47,30 +47,11 @@ public class ScalePagesController {
String targetPDRectangle = request.getPageSize();
float scaleFactor = request.getScaleFactor();
Map<String, PDRectangle> sizeMap = new HashMap<>();
// Add A0 - A10
sizeMap.put("A0", PDRectangle.A0);
sizeMap.put("A1", PDRectangle.A1);
sizeMap.put("A2", PDRectangle.A2);
sizeMap.put("A3", PDRectangle.A3);
sizeMap.put("A4", PDRectangle.A4);
sizeMap.put("A5", PDRectangle.A5);
sizeMap.put("A6", PDRectangle.A6);
// Add other sizes
sizeMap.put("LETTER", PDRectangle.LETTER);
sizeMap.put("LEGAL", PDRectangle.LEGAL);
if (!sizeMap.containsKey(targetPDRectangle)) {
throw new IllegalArgumentException(
"Invalid PDRectangle. It must be one of the following: A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10");
}
PDRectangle targetSize = sizeMap.get(targetPDRectangle);
PDDocument sourceDocument = Loader.loadPDF(file.getBytes());
PDDocument outputDocument = new PDDocument();
PDRectangle targetSize = getTargetSize(targetPDRectangle, sourceDocument);
int totalPages = sourceDocument.getNumberOfPages();
for (int i = 0; i < totalPages; i++) {
PDPage sourcePage = sourceDocument.getPage(i);
@ -116,4 +97,45 @@ public class ScalePagesController {
Filenames.toSimpleFileName(file.getOriginalFilename()).replaceFirst("[.][^.]+$", "")
+ "_scaled.pdf");
}
private PDRectangle getTargetSize(String targetPDRectangle, PDDocument sourceDocument) {
if (targetPDRectangle.equals("KEEP")) {
if (sourceDocument.getNumberOfPages() == 0) {
return null;
}
// use the first page to determine the target page size
PDPage sourcePage = sourceDocument.getPage(0);
PDRectangle sourceSize = sourcePage.getMediaBox();
return sourceSize;
}
Map<String, PDRectangle> sizeMap = getSizeMap();
if (sizeMap.containsKey(targetPDRectangle)) {
return sizeMap.get(targetPDRectangle);
}
throw new IllegalArgumentException(
"Invalid PDRectangle. It must be one of the following: A0, A1, A2, A3, A4, A5, A6, LETTER, LEGAL, KEEP");
}
private Map<String, PDRectangle> getSizeMap() {
Map<String, PDRectangle> sizeMap = new HashMap<>();
// Add A0 - A6
sizeMap.put("A0", PDRectangle.A0);
sizeMap.put("A1", PDRectangle.A1);
sizeMap.put("A2", PDRectangle.A2);
sizeMap.put("A3", PDRectangle.A3);
sizeMap.put("A4", PDRectangle.A4);
sizeMap.put("A5", PDRectangle.A5);
sizeMap.put("A6", PDRectangle.A6);
// Add other sizes
sizeMap.put("LETTER", PDRectangle.LETTER);
sizeMap.put("LEGAL", PDRectangle.LEGAL);
return sizeMap;
}
}

View File

@ -11,7 +11,7 @@ public class PDFWithPageSize extends PDFFile {
@Schema(
description =
"The scale of pages in the output PDF. Acceptable values are A0-A6, LETTER, LEGAL.",
allowableValues = {"A0", "A1", "A2", "A3", "A4", "A5", "A6", "LETTER", "LEGAL"})
"The scale of pages in the output PDF. Acceptable values are A0-A6, LETTER, LEGAL, KEEP.",
allowableValues = {"A0", "A1", "A2", "A3", "A4", "A5", "A6", "LETTER", "LEGAL", "KEEP"})
private String pageSize;
}

View File

@ -675,6 +675,7 @@ pageLayout.submit=إرسال
scalePages.title=ضبط مقياس الصفحة
scalePages.header=ضبط مقياس الصفحة
scalePages.pageSize=حجم صفحة المستند.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=مستوى التكبير (الاقتصاص) للصفحة.
scalePages.submit=إرسال

View File

@ -675,6 +675,7 @@ pageLayout.submit=Подайте
scalePages.title=Коригиране на мащаба на страницата
scalePages.header=Коригиране на мащаба на страницата
scalePages.pageSize=Размер на страница от документа.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Ниво на мащабиране (изрязване) на страница.
scalePages.submit=Подайте

View File

@ -675,6 +675,7 @@ pageLayout.submit=Submit
scalePages.title=Adjust page-scale
scalePages.header=Adjust page-scale
scalePages.pageSize=Size of a page of the document.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Zoom level (crop) of a page.
scalePages.submit=Submit

View File

@ -675,6 +675,7 @@ pageLayout.submit=Odeslat
scalePages.title=Upravit měřítko stránky
scalePages.header=Upravit měřítko stránky
scalePages.pageSize=Velikost stránky dokumentu.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Úroveň přiblížení (oříznutí) stránky.
scalePages.submit=Odeslat

View File

@ -675,6 +675,7 @@ pageLayout.submit=Indsend
scalePages.title=Justér sidestørrelse
scalePages.header=Justér sidestørrelse
scalePages.pageSize=Størrelse på en side i dokumentet.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Zoom-niveau (beskæring) af en side.
scalePages.submit=Indsend

View File

@ -675,6 +675,7 @@ pageLayout.submit=Abschicken
scalePages.title=Seitengröße anpassen
scalePages.header=Seitengröße anpassen
scalePages.pageSize=Format der Seiten des Dokuments
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Zoomstufe (Ausschnitt) einer Seite
scalePages.submit=Abschicken

View File

@ -675,6 +675,7 @@ pageLayout.submit=Υποβολή
scalePages.title=Προσαρμογή κλίμακας σελίδας
scalePages.header=Προσαρμογή κλίμακας σελίδας
scalePages.pageSize=Μέγεθος μιας σελίδας του εγγράφου.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Επίπεδο ζουμ (περικοπή) σελίδας.
scalePages.submit=Υποβολή

View File

@ -675,6 +675,7 @@ pageLayout.submit=Submit
scalePages.title=Adjust page-scale
scalePages.header=Adjust page-scale
scalePages.pageSize=Size of a page of the document.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Zoom level (crop) of a page.
scalePages.submit=Submit

View File

@ -675,6 +675,7 @@ pageLayout.submit=Submit
scalePages.title=Adjust page-scale
scalePages.header=Adjust page-scale
scalePages.pageSize=Size of a page of the document.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Zoom level (crop) of a page.
scalePages.submit=Submit

View File

@ -675,6 +675,7 @@ pageLayout.submit=Entregar
scalePages.title=Ajustar escala de la página
scalePages.header=Adjustar escala de la página
scalePages.pageSize=Tamaño de la página del documento
scalePages.keepPageSize=Tamaño Original
scalePages.scaleFactor=Nivel de zoom (recorte) de la página
scalePages.submit=Entregar

View File

@ -675,6 +675,7 @@ pageLayout.submit=Entregatu
scalePages.title=Doitu orrialdearen eskala
scalePages.header=Doitu orrialdearen eskala
scalePages.pageSize=Dokumentuaren orrialdearen tamaina
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Orriaren zoom maila (moztea)
scalePages.submit=Entregatu

View File

@ -675,6 +675,7 @@ pageLayout.submit=Fusionner
scalePages.title=Ajuster la taille ou léchelle
scalePages.header=Ajuster la taille ou léchelle
scalePages.pageSize=Taille dune page du document
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Niveau de zoom (recadrage) dune page
scalePages.submit=Ajuster

View File

@ -675,6 +675,7 @@ pageLayout.submit=Cuir isteach
scalePages.title=Coigeartaigh scála an leathanaigh
scalePages.header=Coigeartaigh scála an leathanaigh
scalePages.pageSize=Méid leathanach den doiciméad.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Leibhéal súmáil (barr) de leathanach.
scalePages.submit=Cuir isteach

View File

@ -675,6 +675,7 @@ pageLayout.submit=प्रस्तुत क
scalePages.title=पृष्ठ-स्केल समायोजित करें
scalePages.header=पृष्ठ-स्केल समायोजित करें
scalePages.pageSize=दस्तावेज़ के पृष्ठ का आकार।
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=पृष्ठ का ज़ूम स्तर (क्रॉप)।
scalePages.submit=प्रस्तुत करें

View File

@ -675,6 +675,7 @@ pageLayout.submit=Potvrdi
scalePages.title=Podesite veličinu stranice
scalePages.header=Podesite veličinu stranice
scalePages.pageSize=Veličina stranice dokumenta.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Razina zumiranja (obrezivanje) stranice.
scalePages.submit=Potvrdi

View File

@ -675,6 +675,7 @@ pageLayout.submit=Elküldés
scalePages.title=Oldalméret beállítása
scalePages.header=Oldalméret beállítása
scalePages.pageSize=A dokumentum egy oldalának mérete.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Az oldal nagyításának szintje (vágás).
scalePages.submit=Küldés

View File

@ -675,6 +675,7 @@ pageLayout.submit=Kirim
scalePages.title=Sesuaikan skala halaman
scalePages.header=Sesuaikan skala halaman
scalePages.pageSize=Ukuran halaman dokumen.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Tingkat zoom (potong) halaman.
scalePages.submit=Kirim

View File

@ -675,6 +675,7 @@ pageLayout.submit=Invia
scalePages.title=Regola la scala della pagina
scalePages.header=Regola la scala della pagina
scalePages.pageSize=Dimensione di una pagina del documento.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Livello di zoom (ritaglio) di una pagina.
scalePages.submit=Invia

View File

@ -675,6 +675,7 @@ pageLayout.submit=送信
scalePages.title=ページの縮尺の調整
scalePages.header=ページの縮尺の調整
scalePages.pageSize=1ページのサイズ
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=1ページの拡大レベル (トリミング)。
scalePages.submit=送信

View File

@ -675,6 +675,7 @@ pageLayout.submit=확인
scalePages.title=페이지 배율 조절
scalePages.header=페이지 배율 조절
scalePages.pageSize=페이지의 크기를 조절합니다.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=페이지 배율 조절 (잘라내기)
scalePages.submit=제출

View File

@ -675,6 +675,7 @@ pageLayout.submit=Indienen
scalePages.title=Pagina-schaal aanpassen
scalePages.header=Pagina-schaal aanpassen
scalePages.pageSize=Grootte van een pagina van het document.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Zoomniveau (uitsnede) van een pagina.
scalePages.submit=Indienen

View File

@ -675,6 +675,7 @@ pageLayout.submit=Send inn
scalePages.title=Juster side-skala
scalePages.header=Juster side-skala
scalePages.pageSize=Størrelse på et ark i dokumentet.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Zoom-nivå (beskjær) for en side.
scalePages.submit=Send inn

View File

@ -675,6 +675,7 @@ pageLayout.submit=Wykonaj
scalePages.title=Dopasuj rozmiar stron
scalePages.header=Dopasuj rozmiar stron
scalePages.pageSize=Rozmiar stron dokumentu:
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Poziom powiększenia (przycięcia) stron:
scalePages.submit=Wykonaj

View File

@ -675,6 +675,7 @@ pageLayout.submit=Enviar
scalePages.title=Ajustar Tamanho/Escala da Página
scalePages.header=Ajustar Tamanho/Escala da Página
scalePages.pageSize=Tamanho de uma página do documento.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Fator de zoom (corte) de uma página.
scalePages.submit=Enviar

View File

@ -675,6 +675,7 @@ pageLayout.submit=Enviar
scalePages.title=Ajustar Tamanho/Escala da Página
scalePages.header=Ajustar Tamanho/Escala da Página
scalePages.pageSize=Tamanho de uma página do documento.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Fator de zoom (corte) de uma página.
scalePages.submit=Enviar

View File

@ -675,6 +675,7 @@ pageLayout.submit=Trimite
scalePages.title=Ajustează scala paginii
scalePages.header=Ajustează scala paginii
scalePages.pageSize=Dimensiunea unei pagini a documentului.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Nivel de zoom (decupare) al unei pagini.
scalePages.submit=Trimite

View File

@ -675,6 +675,7 @@ pageLayout.submit=Отправить
scalePages.title=Отрегулировать масштаб страницы
scalePages.header=Отрегулировать масштаб страницы
scalePages.pageSize=Размер страницы документа.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Уровень масштабирования (обрезки) страницы.
scalePages.submit=Отправить

View File

@ -675,6 +675,7 @@ pageLayout.submit=Odoslať
scalePages.title=Upraviť mierku stránky
scalePages.header=Upraviť mierku stránky
scalePages.pageSize=Veľkosť stránky dokumentu.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Úroveň priblíženia (orezania) stránky.
scalePages.submit=Odoslať

View File

@ -675,6 +675,7 @@ pageLayout.submit=Potvrdi
scalePages.title=Podesi razmeru stranica
scalePages.header=Podesi razmeru stranica
scalePages.pageSize=Veličina stranice dokumenta.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Nivo zumiranja (rezanje) stranice.
scalePages.submit=Potvrdi

View File

@ -675,6 +675,7 @@ pageLayout.submit=Skicka
scalePages.title=Justera sidskala
scalePages.header=Justera sidskala
scalePages.pageSize=Storlek på en sida i dokumentet.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Zoomnivå (beskärning) för en sida.
scalePages.submit=Skicka

View File

@ -675,6 +675,7 @@ pageLayout.submit=ส่ง
scalePages.title=ปรับสเกลหน้า
scalePages.header=ปรับสเกลหน้า
scalePages.pageSize=ขนาดหน้าของเอกสาร
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=ระดับการซูม (ครอบตัด) ของหน้า
scalePages.submit=ส่ง

View File

@ -675,6 +675,7 @@ pageLayout.submit=Gönder
scalePages.title=Sayfa Ölçeğini Ayarla
scalePages.header=Sayfa Ölçeğini Ayarla
scalePages.pageSize=Belgenin bir sayfa boyutu.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Bir sayfanın yakınlaştırma seviyesi (kırpma).
scalePages.submit=Gönder

View File

@ -675,6 +675,7 @@ pageLayout.submit=Відправити
scalePages.title=Відрегулювати масштаб сторінки
scalePages.header=Відрегулювати масштаб сторінки
scalePages.pageSize=Розмір сторінки документа.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Рівень масштабування (обрізки) сторінки.
scalePages.submit=Відправити

View File

@ -675,6 +675,7 @@ pageLayout.submit=Gửi
scalePages.title=Điều chỉnh tỷ lệ trang
scalePages.header=Điều chỉnh tỷ lệ trang
scalePages.pageSize=Kích thước của một trang trong tài liệu.
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=Mức độ phóng to (cắt cúp) của một trang.
scalePages.submit=Gửi

View File

@ -675,6 +675,7 @@ pageLayout.submit=提交
scalePages.title=调整页面缩放比例
scalePages.header=调整页面缩放比例
scalePages.pageSize=文档页面的尺寸。
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=页面的缩放级别(裁剪)。
scalePages.submit=提交

View File

@ -675,6 +675,7 @@ pageLayout.submit=送出
scalePages.title=調整頁面大小/比例
scalePages.header=調整頁面大小/比例
scalePages.pageSize=文件的頁面大小。
scalePages.keepPageSize=Original Size
scalePages.scaleFactor=頁面的縮放級別(裁剪)。
scalePages.submit=送出

View File

@ -21,11 +21,12 @@
<div class="mb-3">
<label for="pageSize" th:text="#{scalePages.pageSize}"></label>
<select class="form-control" id="pageSize" name="pageSize">
<option value="KEEP" th:text="#{scalePages.keepPageSize}" selected></option>
<option value="A0">A0</option>
<option value="A1">A1</option>
<option value="A2">A2</option>
<option value="A3">A3</option>
<option value="A4" selected>A4</option>
<option value="A4">A4</option>
<option value="A5">A5</option>
<option value="A6">A6</option>
<option value="LETTER">Letter</option>