Compare commits

..

No commits in common. "a438a151058f2f904e1812c128ace0545684f4ba" and "47bce86ae280969a012fc359208d1dd3659039c8" have entirely different histories.

4 changed files with 40 additions and 38 deletions

View File

@ -552,10 +552,10 @@ public class PdfUtils {
public boolean containsTextInFile(PDDocument pdfDocument, String text, String pagesToCheck) public boolean containsTextInFile(PDDocument pdfDocument, String text, String pagesToCheck)
throws IOException { throws IOException {
PDFTextStripper textStripper = new PDFTextStripper(); PDFTextStripper textStripper = new PDFTextStripper();
StringBuilder pdfText = new StringBuilder(); String pdfText = "";
if (pagesToCheck == null || "all".equals(pagesToCheck)) { if (pagesToCheck == null || "all".equals(pagesToCheck)) {
pdfText = new StringBuilder(textStripper.getText(pdfDocument)); pdfText = textStripper.getText(pdfDocument);
} else { } else {
// remove whitespaces // remove whitespaces
pagesToCheck = pagesToCheck.replaceAll("\\s+", ""); pagesToCheck = pagesToCheck.replaceAll("\\s+", "");
@ -571,21 +571,21 @@ public class PdfUtils {
for (int i = startPage; i <= endPage; i++) { for (int i = startPage; i <= endPage; i++) {
textStripper.setStartPage(i); textStripper.setStartPage(i);
textStripper.setEndPage(i); textStripper.setEndPage(i);
pdfText.append(textStripper.getText(pdfDocument)); pdfText += textStripper.getText(pdfDocument);
} }
} else { } else {
// Handle individual page // Handle individual page
int page = Integer.parseInt(splitPoint); int page = Integer.parseInt(splitPoint);
textStripper.setStartPage(page); textStripper.setStartPage(page);
textStripper.setEndPage(page); textStripper.setEndPage(page);
pdfText.append(textStripper.getText(pdfDocument)); pdfText += textStripper.getText(pdfDocument);
} }
} }
} }
pdfDocument.close(); pdfDocument.close();
return pdfText.toString().contains(text); return pdfText.contains(text);
} }
public boolean pageCount(PDDocument pdfDocument, int pageCount, String comparator) public boolean pageCount(PDDocument pdfDocument, int pageCount, String comparator)

View File

@ -94,14 +94,14 @@ public class AutoRenameController {
// Merge lines with same font size // Merge lines with same font size
List<LineInfo> mergedLineInfos = new ArrayList<>(); List<LineInfo> mergedLineInfos = new ArrayList<>();
for (int i = 0; i < lineInfos.size(); i++) { for (int i = 0; i < lineInfos.size(); i++) {
StringBuilder mergedText = new StringBuilder(lineInfos.get(i).text); String mergedText = lineInfos.get(i).text;
float fontSize = lineInfos.get(i).fontSize; float fontSize = lineInfos.get(i).fontSize;
while (i + 1 < lineInfos.size() while (i + 1 < lineInfos.size()
&& lineInfos.get(i + 1).fontSize == fontSize) { && lineInfos.get(i + 1).fontSize == fontSize) {
mergedText.append(" ").append(lineInfos.get(i + 1).text); mergedText += " " + lineInfos.get(i + 1).text;
i++; i++;
} }
mergedLineInfos.add(new LineInfo(mergedText.toString(), fontSize)); mergedLineInfos.add(new LineInfo(mergedText, fontSize));
} }
// Sort lines by font size in descending order and get the first one // Sort lines by font size in descending order and get the first one

View File

@ -1,9 +1,8 @@
package stirling.software.SPDF.controller.api.misc; package stirling.software.SPDF.controller.api.misc;
import io.github.pixee.security.Filenames; import java.nio.charset.StandardCharsets;
import io.swagger.v3.oas.annotations.Operation; import java.util.Map;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.common.PDNameTreeNode; import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;
import org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript; import org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript;
@ -14,13 +13,17 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import io.github.pixee.security.Filenames;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import stirling.software.common.model.api.PDFFile; import stirling.software.common.model.api.PDFFile;
import stirling.software.common.service.CustomPDFDocumentFactory; import stirling.software.common.service.CustomPDFDocumentFactory;
import stirling.software.common.util.WebResponseUtils; import stirling.software.common.util.WebResponseUtils;
import java.nio.charset.StandardCharsets;
import java.util.Map;
@RestController @RestController
@RequestMapping("/api/v1/misc") @RequestMapping("/api/v1/misc")
@Tag(name = "Misc", description = "Miscellaneous APIs") @Tag(name = "Misc", description = "Miscellaneous APIs")
@ -35,8 +38,7 @@ public class ShowJavascript {
description = "desc. Input:PDF Output:JS Type:SISO") description = "desc. Input:PDF Output:JS Type:SISO")
public ResponseEntity<byte[]> extractHeader(@ModelAttribute PDFFile file) throws Exception { public ResponseEntity<byte[]> extractHeader(@ModelAttribute PDFFile file) throws Exception {
MultipartFile inputFile = file.getFileInput(); MultipartFile inputFile = file.getFileInput();
StringBuilder script = new StringBuilder(); String script = "";
boolean foundScript = false;
try (PDDocument document = pdfDocumentFactory.load(inputFile)) { try (PDDocument document = pdfDocumentFactory.load(inputFile)) {
@ -53,28 +55,28 @@ public class ShowJavascript {
PDActionJavaScript jsAction = entry.getValue(); PDActionJavaScript jsAction = entry.getValue();
String jsCodeStr = jsAction.getAction(); String jsCodeStr = jsAction.getAction();
if (jsCodeStr != null && !jsCodeStr.trim().isEmpty()) { script +=
script.append("// File: ") "// File: "
.append(Filenames.toSimpleFileName(inputFile.getOriginalFilename())) + Filenames.toSimpleFileName(
.append(", Script: ") inputFile.getOriginalFilename())
.append(name) + ", Script: "
.append("\n") + name
.append(jsCodeStr) + "\n"
.append("\n"); + jsCodeStr
foundScript = true; + "\n";
}
} }
} }
} }
if (!foundScript) { if (script.isEmpty()) {
script = new StringBuilder("PDF '") script =
.append(Filenames.toSimpleFileName(inputFile.getOriginalFilename())) "PDF '"
.append("' does not contain Javascript"); + Filenames.toSimpleFileName(inputFile.getOriginalFilename())
+ "' does not contain Javascript";
} }
return WebResponseUtils.bytesToWebResponse( return WebResponseUtils.bytesToWebResponse(
script.toString().getBytes(StandardCharsets.UTF_8), script.getBytes(StandardCharsets.UTF_8),
Filenames.toSimpleFileName(inputFile.getOriginalFilename()) + ".js", Filenames.toSimpleFileName(inputFile.getOriginalFilename()) + ".js",
MediaType.TEXT_PLAIN); MediaType.TEXT_PLAIN);
} }

View File

@ -1896,12 +1896,12 @@ editTableOfContents.replaceExisting=Meglévő könyvjelzők cseréje (törölje
editTableOfContents.editorTitle=Könyvjelző szerkesztő editTableOfContents.editorTitle=Könyvjelző szerkesztő
editTableOfContents.editorDesc=Könyvjelzők hozzáadása és rendezése lent. Kattintson a + gombra gyermek könyvjelzők hozzáadásához. editTableOfContents.editorDesc=Könyvjelzők hozzáadása és rendezése lent. Kattintson a + gombra gyermek könyvjelzők hozzáadásához.
editTableOfContents.addBookmark=Új könyvjelző hozzáadása editTableOfContents.addBookmark=Új könyvjelző hozzáadása
editTableOfContents.importBookmarksDefault=Importálás editTableOfContents.importBookmarksDefault=Import
editTableOfContents.importBookmarksFromJsonFile=JSON fájl feltöltése editTableOfContents.importBookmarksFromJsonFile=Upload JSON file
editTableOfContents.importBookmarksFromClipboard=Beillesztés vágólapról editTableOfContents.importBookmarksFromClipboard=Paste from clipboard
editTableOfContents.exportBookmarksDefault=Exportálás editTableOfContents.exportBookmarksDefault=Export
editTableOfContents.exportBookmarksAsJson=Letöltés JSON formátumban editTableOfContents.exportBookmarksAsJson=Download as JSON
editTableOfContents.exportBookmarksAsText=Másolás szövegként editTableOfContents.exportBookmarksAsText=Copy as text
editTableOfContents.desc.1=Ez az eszköz lehetővé teszi a tartalomjegyzék (könyvjelzők) hozzáadását vagy szerkesztését egy PDF dokumentumban. editTableOfContents.desc.1=Ez az eszköz lehetővé teszi a tartalomjegyzék (könyvjelzők) hozzáadását vagy szerkesztését egy PDF dokumentumban.
editTableOfContents.desc.2=Hierarchikus struktúrákat hozhat létre, ha gyermek könyvjelzőket ad a szülő könyvjelzőkhöz. editTableOfContents.desc.2=Hierarchikus struktúrákat hozhat létre, ha gyermek könyvjelzőket ad a szülő könyvjelzőkhöz.
editTableOfContents.desc.3=Minden könyvjelzőhöz szükséges egy cím és egy céloldalszám. editTableOfContents.desc.3=Minden könyvjelzőhöz szükséges egy cím és egy céloldalszám.