这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 93 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,82 +21,97 @@ All documentation available at [https://docs.stirlingpdf.com/](https://docs.stir

## Features

- 50+ PDF Operations
- Parallel file processing and downloads
- Dark mode support
- Custom download options
- Custom 'Pipelines' to run multiple features in a automated queue
- Custom 'Pipelines' to run multiple features in an automated queue
- API for integration with external scripts
- Optional Login and Authentication support (see [here](https://docs.stirlingpdf.com/Advanced%20Configuration/System%20and%20Security) for documentation)
- Database Backup and Import (see [here](https://docs.stirlingpdf.com/Advanced%20Configuration/DATABASE) for documentation)
- Enterprise features like SSO (see [here](https://docs.stirlingpdf.com/Advanced%20Configuration/Single%20Sign-On%20Configuration) for documentation)
- Database Backup and Import (see [here](https://docs.stirlingpdf.com/Advanced%20Configuration/DATABASE) for documentation)

## PDF Features

### Page Operations

- View and modify PDFs - View multi-page PDFs with custom viewing, sorting, and searching. Plus, on-page edit features like annotating, drawing, and adding text and images. (Using PDF.js with Joxit and Liberation fonts)
- Full interactive GUI for merging/splitting/rotating/moving PDFs and their pages
- Merge multiple PDFs into a single resultant file
- Split PDFs into multiple files at specified page numbers or extract all pages as individual files
- Reorganize PDF pages into different orders
- Rotate PDFs in 90-degree increments
- Remove pages
- Multi-page layout (format PDFs into a multi-paged page)
- Scale page contents size by set percentage
- Adjust contrast
- Crop PDF
- Auto-split PDF (with physically scanned page dividers)
- Extract page(s)
- Convert PDF to a single page
- Overlay PDFs on top of each other
- PDF to a single page
- Split PDF by sections

### Conversion Operations

- Convert PDFs to and from images
- Convert any common file to PDF (using LibreOffice)
- Convert PDF to Word/PowerPoint/others (using LibreOffice)
- Convert HTML to PDF
- Convert PDF to XML
- Convert PDF to CSV
- URL to PDF
- Markdown to PDF

### Security & Permissions

- Add and remove passwords
- Change/set PDF permissions
- Add watermark(s)
- Certify/sign PDFs
- Sanitize PDFs
- Auto-redact text

### Other Operations

- Add/generate/write signatures
- Split by Size or PDF
- Repair PDFs
- Detect and remove blank pages
- Compare two PDFs and show differences in text
- Add images to PDFs
- Compress PDFs to decrease their filesize (using qpdf)
- Extract images from PDF
- Remove images from PDF
- Extract images from scans
- Remove annotations
- Add page numbers
- Auto-rename files by detecting PDF header text
- OCR on PDF (using Tesseract OCR)
- PDF/A conversion (using LibreOffice)
- Edit metadata
- Flatten PDFs
- Get all information on a PDF to view or export as JSON
- Show/detect embedded JavaScript



### 50+ PDF Operations

#### Organise
- **Merge**: Combine multiple PDFs into one
- **Split**: Divide PDFs into multiple files
- **Extract page(s)**: Extract specific pages from PDF
- **Remove**: Delete pages from PDF
- **Crop PDF**: Adjust PDF page boundaries
- **Rotate**: Rotate pages in 90-degree increments
- **Adjust page size/scale**: Resize page contents
- **Multi-Page Layout**: Add multiple pages to PDF
- **PDF to Single Large Page**: Convert to single continuous page
- **Organize**: Rearrange PDF pages

#### Convert to PDF
- **Image to PDF**: Convert images to PDF format
- **Convert file to PDF**: Convert various common file types to PDF
- **HTML to PDF**: Transform HTML documents to PDF
- **Markdown to PDF**: Convert Markdown files to PDF
- **CBZ to PDF**: Convert comic book archives
- **CBR to PDF**: Convert comic book rar archives
- **Email to PDF**: Convert email files to PDF

#### Convert from PDF
- **PDF to Word**: Convert to documet (docx, doc, odt) format
- **PDF to Image**: Extract PDF pages as images
- **PDF to RTF (Text)**: Convert to Rich Text Format
- **PDF to Presentation**: Convert to presentation (pptx, ppt, odp) format
- **PDF to CSV**: Extract tables to CSV
- **PDF to XML**: Convert to XML format
- **PDF to HTML**: Transform to HTML
- **PDF to PDF/A**: Convert to archival (PDF/A-1b, PDF/A-2b) format
- **PDF to Markdown**: Convert PDF to Markdown
- **PDF to CBZ**: Convert to comic book archive
- **PDF to CBR**: Convert to comic book rar archive

#### Sign & Security
- **Sign**: Add digital signatures
- **Remove Password**: Remove PDF security
- **Add Watermark**: Apply watermarks
- **Sign with Certificate**: Certificate-based signing
- **Add Stamp to PDF**: Apply digital stamps
- **Auto Redact**: Automatically redact content
- **Change Permissions**: Modify access permissions
- **Add Password**: Apply PDF encryption
- **Manual Redaction**: Manual content redaction
- **Remove Certificate Sign**: Remove digital signatures
- **Sanitize**: Clean PDF of potential security issues
- **Validate PDF Signature**: Verify digital signatures

#### View & Edit
- **OCR / Cleanup scans**: Optical Character Recognition
- **Add Image**: Insert images into PDF
- **Extract Images**: Extract embedded images
- **Change Metadata**: Edit PDF metadata
- **Get ALL Info on PDF**: Comprehensive PDF analysis
- **Advanced Colour options**: Colour manipulation (various options for colour inversion, CMYK conversion)
- **Compare**: Compare PDF documents
- **Add Page Numbers**: Insert page numbering
- **Flatten**: Flatten PDF layers, and interactive elements
- **Remove Annotations**: Delete comments and markups
- **Remove Blank pages**: Delete empty pages
- **Remove Image**: Delete embedded images
- **View/Edit PDF**: Interactive PDF editing
- **Unlock PDF Forms**: Enable form editing
- **Add Attachments**: Attach files to PDF

#### Advanced
- **Compress**: Reduce file size
- **Pipeline**: Automated workflow processing (OCR images pipeline, prepare PDFs for emailing pipeline)
- **Adjust Colours/Contrast**: Colour and contrast adjustment
- **Auto Rename PDF File**: Automatic file renaming
- **Auto Split Pages**: Automatic page splitting
- **Detect/Split Scanned photos**: Photo detection and splitting
- **Overlay PDFs**: Layer PDFs over each other
- **Repair**: Fix corrupted PDFs
- **Show JavaScript**: Display embedded JavaScript
- **Auto Split by Size/Count**: Split by file size or page count
- **Split PDF by Chapters**: Chapter-based splitting
- **Split PDF by Sections**: Section-based splitting
- **Scanner Effect**: Apply scanner-like effects
- **Edit Table of Contents**: Modify PDF bookmarks and TOC

# 📖 Get Started

Expand All @@ -115,8 +130,8 @@ Visit our comprehensive documentation at [docs.stirlingpdf.com](https://docs.sti
Stirling-PDF currently supports 40 languages!

| Language | Progress |
| -------------------------------------------- | -------------------------------------- |
| Arabic (العربية) (ar_AR) | ![59%](https://geps.dev/progress/59) |
|----------------------------------------------|----------------------------------------|
| Arabic (العربية) (ar_AR) | ![59%](https://geps.dev/progress/59) |
| Azerbaijani (Azərbaycan Dili) (az_AZ) | ![60%](https://geps.dev/progress/60) |
| Basque (Euskara) (eu_ES) | ![35%](https://geps.dev/progress/35) |
| Bulgarian (Български) (bg_BG) | ![66%](https://geps.dev/progress/66) |
Expand All @@ -130,13 +145,13 @@ Stirling-PDF currently supports 40 languages!
| French (Français) (fr_FR) | ![88%](https://geps.dev/progress/88) |
| German (Deutsch) (de_DE) | ![95%](https://geps.dev/progress/95) |
| Greek (Ελληνικά) (el_GR) | ![65%](https://geps.dev/progress/65) |
| Hindi (हिंदी) (hi_IN) | ![65%](https://geps.dev/progress/65) |
| Hindi (हिंदी) (hi_IN) | ![65%](https://geps.dev/progress/65) |
| Hungarian (Magyar) (hu_HU) | ![97%](https://geps.dev/progress/97) |
| Indonesian (Bahasa Indonesia) (id_ID) | ![60%](https://geps.dev/progress/60) |
| Irish (Gaeilge) (ga_IE) | ![66%](https://geps.dev/progress/66) |
| Italian (Italiano) (it_IT) | ![96%](https://geps.dev/progress/96) |
| Japanese (日本語) (ja_JP) | ![90%](https://geps.dev/progress/90) |
| Korean (한국어) (ko_KR) | ![66%](https://geps.dev/progress/66) |
| Japanese (日本語) (ja_JP) | ![90%](https://geps.dev/progress/90) |
| Korean (한국어) (ko_KR) | ![66%](https://geps.dev/progress/66) |
| Norwegian (Norsk) (no_NB) | ![64%](https://geps.dev/progress/64) |
| Persian (فارسی) (fa_IR) | ![62%](https://geps.dev/progress/62) |
| Polish (Polski) (pl_PL) | ![70%](https://geps.dev/progress/70) |
Expand All @@ -145,18 +160,18 @@ Stirling-PDF currently supports 40 languages!
| Romanian (Română) (ro_RO) | ![56%](https://geps.dev/progress/56) |
| Russian (Русский) (ru_RU) | ![90%](https://geps.dev/progress/90) |
| Serbian Latin alphabet (Srpski) (sr_LATN_RS) | ![97%](https://geps.dev/progress/97) |
| Simplified Chinese (简体中文) (zh_CN) | ![91%](https://geps.dev/progress/91) |
| Simplified Chinese (简体中文) (zh_CN) | ![91%](https://geps.dev/progress/91) |
| Slovakian (Slovensky) (sk_SK) | ![50%](https://geps.dev/progress/50) |
| Slovenian (Slovenščina) (sl_SI) | ![69%](https://geps.dev/progress/69) |
| Spanish (Español) (es_ES) | ![95%](https://geps.dev/progress/95) |
| Swedish (Svenska) (sv_SE) | ![63%](https://geps.dev/progress/63) |
| Thai (ไทย) (th_TH) | ![57%](https://geps.dev/progress/57) |
| Tibetan (བོད་ཡིག་) (bo_CN) | ![63%](https://geps.dev/progress/63) |
| Traditional Chinese (繁體中文) (zh_TW) | ![97%](https://geps.dev/progress/97) |
| Tibetan (བོད་ཡིག་) (bo_CN) | ![63%](https://geps.dev/progress/63) |
| Traditional Chinese (繁體中文) (zh_TW) | ![97%](https://geps.dev/progress/97) |
| Turkish (Türkçe) (tr_TR) | ![96%](https://geps.dev/progress/96) |
| Ukrainian (Українська) (uk_UA) | ![69%](https://geps.dev/progress/69) |
| Vietnamese (Tiếng Việt) (vi_VN) | ![55%](https://geps.dev/progress/55) |
| Malayalam (മലയാളം) (ml_IN) | ![71%](https://geps.dev/progress/71) |
| Malayalam (മലയാളം) (ml_IN) | ![71%](https://geps.dev/progress/71) |

## Stirling PDF Enterprise

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ public void init() {
/* Ghostscript */
addEndpointToGroup("Ghostscript", "repair");
addEndpointToGroup("Ghostscript", "compress-pdf");
addEndpointToGroup("Ghostscript", "crop");
addEndpointToGroup("Ghostscript", "replace-invert-pdf");

/* tesseract */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import org.apache.pdfbox.multipdf.LayerUtility;
import org.apache.pdfbox.pdmodel.PDDocument;
Expand All @@ -21,16 +24,19 @@
import io.swagger.v3.oas.annotations.tags.Tag;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import stirling.software.SPDF.model.api.general.CropPdfForm;
import stirling.software.common.service.CustomPDFDocumentFactory;
import stirling.software.common.util.GeneralUtils;
import stirling.software.common.util.ProcessExecutor;
import stirling.software.common.util.WebResponseUtils;

@RestController
@RequestMapping("/api/v1/general")
@Tag(name = "General", description = "General APIs")
@RequiredArgsConstructor
@Slf4j
public class CropController {

private final CustomPDFDocumentFactory pdfDocumentFactory;
Expand All @@ -42,6 +48,15 @@ public class CropController {
"This operation takes an input PDF file and crops it according to the given"
+ " coordinates. Input:PDF Output:PDF Type:SISO")
public ResponseEntity<byte[]> cropPdf(@ModelAttribute CropPdfForm request) throws IOException {
if (request.isRemoveDataOutsideCrop()) {
return cropWithGhostscript(request);
} else {
return cropWithPDFBox(request);
}
}

private ResponseEntity<byte[]> cropWithPDFBox(@ModelAttribute CropPdfForm request)
throws IOException {
PDDocument sourceDocument = pdfDocumentFactory.load(request);

PDDocument newDocument =
Expand Down Expand Up @@ -97,4 +112,59 @@ public ResponseEntity<byte[]> cropPdf(@ModelAttribute CropPdfForm request) throw
GeneralUtils.generateFilename(
request.getFileInput().getOriginalFilename(), "_cropped.pdf"));
}

private ResponseEntity<byte[]> cropWithGhostscript(@ModelAttribute CropPdfForm request)
throws IOException {
PDDocument sourceDocument = pdfDocumentFactory.load(request);

for (int i = 0; i < sourceDocument.getNumberOfPages(); i++) {
PDPage page = sourceDocument.getPage(i);
PDRectangle cropBox =
new PDRectangle(
request.getX(),
request.getY(),
request.getWidth(),
request.getHeight());
page.setCropBox(cropBox);
}

Path tempInputFile = Files.createTempFile("crop_input", ".pdf");
Path tempOutputFile = Files.createTempFile("crop_output", ".pdf");

try {
sourceDocument.save(tempInputFile.toFile());
sourceDocument.close();

ProcessExecutor processExecutor =
ProcessExecutor.getInstance(ProcessExecutor.Processes.GHOSTSCRIPT);
List<String> command =
List.of(
"gs",
"-sDEVICE=pdfwrite",
"-dUseCropBox",
"-o",
tempOutputFile.toString(),
tempInputFile.toString());

processExecutor.runCommandWithOutputHandling(command);

byte[] pdfContent = Files.readAllBytes(tempOutputFile);

return WebResponseUtils.bytesToWebResponse(
pdfContent,
request.getFileInput().getOriginalFilename().replaceFirst("[.][^.]+$", "")
+ "_cropped.pdf");

} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("Ghostscript processing was interrupted", e);
} finally {
try {
Files.deleteIfExists(tempInputFile);
Files.deleteIfExists(tempOutputFile);
} catch (IOException e) {
log.debug("Failed to delete temporary files", e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,20 @@ public ResponseEntity<byte[]> scalePages(@ModelAttribute ScalePagesRequest reque
private PDRectangle getTargetSize(String targetPDRectangle, PDDocument sourceDocument) {
if ("KEEP".equals(targetPDRectangle)) {
if (sourceDocument.getNumberOfPages() == 0) {
return null;
// Do not return null here; throw a clear exception so callers don't get a nullable
// PDRectangle.
throw ExceptionUtils.createInvalidPageSizeException("KEEP");
}

// use the first page to determine the target page size
PDPage sourcePage = sourceDocument.getPage(0);
PDRectangle sourceSize = sourcePage.getMediaBox();

if (sourceSize == null) {
// If media box is unexpectedly null, treat it as invalid
throw ExceptionUtils.createInvalidPageSizeException("KEEP");
}

return sourceSize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;

import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand All @@ -18,6 +17,8 @@

import stirling.software.SPDF.model.api.misc.ReplaceAndInvertColorRequest;
import stirling.software.SPDF.service.misc.ReplaceAndInvertColorService;
import stirling.software.common.util.GeneralUtils;
import stirling.software.common.util.WebResponseUtils;

@RestController
@RequestMapping("/api/v1/misc")
Expand All @@ -33,7 +34,7 @@ public class ReplaceAndInvertColorController {
description =
"This endpoint accepts a PDF file and provides options to invert all colors, replace"
+ " text and background colors, or convert to CMYK color space for printing. Input:PDF Output:PDF Type:SISO")
public ResponseEntity<InputStreamResource> replaceAndInvertColor(
public ResponseEntity<byte[]> replaceAndInvertColor(
@ModelAttribute ReplaceAndInvertColorRequest request) throws IOException {

InputStreamResource resource =
Expand All @@ -45,9 +46,10 @@ public ResponseEntity<InputStreamResource> replaceAndInvertColor(
request.getTextColor());

// Return the modified PDF as a downloadable file
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=inverted.pdf")
.contentType(MediaType.APPLICATION_PDF)
.body(resource);
String filename =
GeneralUtils.generateFilename(
request.getFileInput().getOriginalFilename(), "_inverted.pdf");
return WebResponseUtils.bytesToWebResponse(
resource.getContentAsByteArray(), filename, MediaType.APPLICATION_PDF);
}
}
Loading
Loading