Skip to content

Commit ecf844c

Browse files
Aspose.PDF for JavaScript via C++ 25.6
1 parent 3cbd315 commit ecf844c

File tree

7 files changed

+163
-18
lines changed

7 files changed

+163
-18
lines changed

AsposePDFforJS.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AsposePDFforJS.wasm.zip

12.8 KB
Binary file not shown.

README.md

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,62 @@ Add PDF processing, manipulation, and conversion features to your front-end appl
1010
</a>
1111
</p>
1212

13-
## PDF Processing via JavaScript
14-
15-
- **Extract text** from PDF pages or search for a particular text segment using regular expressions.
16-
- **Add or extract** images to & from PDF documents.
17-
- **Concatenate** or **split** PDF files.
18-
- **Linearization** of PDF documents for web optimization.
19-
- **Convert** PDF documents to Office, web, and image formats with the highest visual fidelity.
20-
- **Manipulate** PDF files to manage bookmarks, hyperlinks, watermarks, attachments & annotations.
21-
- **Encrypt** or **decrypt** PDF documents and set document privileges or modify passwords.
22-
- **Digitally sign PDF** documents or remove signatures. Also, verify if the PDF is signed and the signature is valid.
13+
## PDF Processing
14+
15+
- **Extract text** from PDF pages, including search via regular expressions and hidden text detection.
16+
- **Add or extract images** to and from PDF documents; remove or replace images when needed.
17+
- **Concatenate**, **split**, or **reorganize** PDF files; delete specific or blank pages.
18+
- **Linearize** PDF documents for web optimization and **optimize** internal structure and resources.
19+
- **Convert** PDF documents to:
20+
- **Office formats:** DOC, DOCX, XLS, XLSX, PPTX
21+
- **Web formats:** SVG, SVG (ZIP), XPS, EPUB
22+
- **Image formats:** JPEG, PNG, BMP, TIFF, DICOM
23+
- **Other formats:** Grayscale PDF, PDF/A, TeX, TXT
24+
- **Manipulate** PDF structure and content:
25+
- Bookmarks, hyperlinks, annotations, attachments, JavaScript
26+
- Fonts, metadata, layers, background color
27+
- **Secure PDF documents**:
28+
- Encrypt, decrypt, set or change passwords
29+
- Configure access permissions
30+
- **Digitally sign** PDFs using PKCS#7, validate and remove signatures.
31+
- **Add or remove** watermarks, stamps, page numbers, headers/footers, background images.
32+
- **Flatten** PDF documents (forms, annotations, layers).
33+
- **Create booklets** or generate **N-Up layouts**.
34+
- **Export form data** (AcroForm) to FDF, XFDF, XML.
35+
- **Validate** and **convert** to/from **PDF/A** format.
2336

2437
## Read & Write PDF & Other Formats
2538

26-
**Fixed Layout:** PDF, PDF/A, PDF/UA
39+
**Fixed Layout Support:**
40+
- PDF, PDF/A
41+
42+
**Save/Export As:**
43+
- **Office:** DOC, DOCX, XLS, XLSX, PPTX
44+
- **Images:** JPEG, PNG, BMP, TIFF, DICOM
45+
- **Other:** EPUB, SVG, SVG (ZIP), TeX, TXT, Grayscale PDF, PDF/A, XPS
46+
47+
**Input Formats:**
48+
- TXT, Images (JPEG/PNG/BMP/TIFF)
49+
50+
## Advanced Features
51+
52+
- **Fonts:** List, embed/unembed, and replace fonts in PDF files.
53+
- **Metadata:** Set, extract, or remove metadata.
54+
- **Layers:** Get list of layers, merge or flatten them.
55+
- **Forms & Annotations:**
56+
- Delete annotations, bookmarks, JavaScript
57+
- Flatten forms
58+
- **Attachments:** Add, extract, or delete file attachments.
59+
- **Text Tools:**
60+
- Find, replace, or delete text (including hidden text)
61+
- Get word and character counts
2762

28-
## Save PDF Documents As
63+
## Additional Utilities
2964

30-
- **Microsoft Office:** DOC, DOCX, XLS, XLSX, PPTX
31-
- **Images:** JPEG, PNG, BMP, TIFF, EMF
32-
- **Others:** EPUB, DICOM, SVG, SVG(ZIP), GRAYSCALE PDF, PDF/A, TEX, TXT
65+
- **Repair** corrupted or damaged PDF files.
66+
- **Generate PDF** from TXT or image files.
67+
- **Optimize** document resources and structure.
68+
- **Product diagnostics**: retrieve library info, version, and capabilities.
3369

3470
## Platform Independence
3571

example.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ <h2>Aspose.PDF for JavaScript via C++</h2>
292292
<label for="fileUnembedFonts">UNEMBED FONTS<span class="tooltip">Unembed fonts a PDF-file</span></label>
293293
<input type="file" id="fileUnembedFonts" accept="application/pdf" onchange="ffileUnembedFonts(event)">
294294
</div>
295+
<div class="column">
296+
<label for="fileOptimizeFileSize">SIZE OPTIMIZE<span class="tooltip">Optimize size of PDF-file with image compression quality</span></label>
297+
<input type="file" id="fileOptimizeFileSize" accept="application/pdf" onchange="ffileOptimizeFileSize(event)">
298+
</div>
295299
</div>
296300
</div>
297301

@@ -1259,6 +1263,17 @@ <h2>Aspose.PDF for JavaScript via C++</h2>
12591263
file_reader.readAsArrayBuffer(e.target.files[0]);
12601264
}
12611265

1266+
var ffileOptimizeFileSize = function (e) {
1267+
const file_reader = new FileReader();
1268+
file_reader.onload = (event) => {
1269+
const json = AsposePdfOptimizeFileSize(event.target.result, e.target.files[0].name, 10, "ResultOptimizeFileSize.pdf");
1270+
if (json.errorCode == 0) document.getElementById('output').textContent = json.fileNameResult;
1271+
else document.getElementById('output').textContent = json.errorText;
1272+
DownloadFile(json.fileNameResult, "application/pdf");
1273+
}
1274+
file_reader.readAsArrayBuffer(e.target.files[0]);
1275+
}
1276+
12621277
</script>
12631278

12641279
<script>

example_worker.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<option value="AsposePdfDeleteBlankPages">Delete blank pages from a PDF-file</option>
9494
<option value="AsposePdfEmbedFonts">Embed fonts a PDF-file</option>
9595
<option value="AsposePdfUnembedFonts">Unembed fonts a PDF-file</option>
96+
<option value="AsposePdfOptimizeFileSize">Optimize size of PDF-file with image compression quality</option>
9697

9798
<optgroup label="Metadata PDF">
9899
<option value="AsposePdfSetInfo">Set info (metadata) in a PDF-file</option>
@@ -325,6 +326,7 @@
325326
// AsposePdfReplaceFont, AsposePdfDeleteHiddenText, AsposePdfAddWatermark, AsposePdfDeleteWatermarks,
326327
// AsposePdfMergeLayers, AsposePdfFlatten, AsposePdfReplaceTextPages, AsposePdfMakeBooklet,
327328
// AsposePdfMakeNUp, AsposePdfDeleteBlankPages, AsposePdfAddStampPages, AsposePdfEmbedFonts, AsposePdfUnembedFonts,
329+
// AsposePdfOptimizeFileSize
328330
DownloadFile(json.fileNameResult, "application/pdf", params[0]);
329331
}
330332
}
@@ -642,6 +644,11 @@
642644
transfer = [event.target.result];
643645
params = [event.target.result, ffile.name, columns, rows, `Result${operation}.pdf`];
644646
break;
647+
case 'AsposePdfOptimizeFileSize':
648+
const imageQuality = 25;
649+
transfer = [event.target.result];
650+
params = [event.target.result, ffile.name, imageQuality, `Result${operation}.pdf`];
651+
break;
645652
default:
646653
// AsposePdfOptimize, AsposePdfAddPageNum, AsposePdfConvertToGrayscale, AsposePdfAConvertToPDF,
647654
// AsposePdfRemoveMetadata, AsposePdfRepair, AsposePdfOptimizeResource, AsposePdfDeleteAnnotations,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<meta charset="UTF-8">
7+
<title>Aspose.PDF for JavaScript via C++</title>
8+
</head>
9+
10+
<body>
11+
<label for="filePdfOptimizeFileSize">Choose a PDF-file to optimize size with image compression quality</label>
12+
<input type="file" id="filePdfOptimizeFileSize" accept="application/pdf" onchange="ffilePdfOptimizeFileSize(event)">
13+
<br>
14+
<pre id="output"></pre>
15+
</body>
16+
<!-- Load and initiate Aspose.PDF for JavaScript via C++ -->
17+
<script type="text/javascript" async src="AsposePDFforJS.js"></script>
18+
<script type="text/javascript">
19+
/// [Code snippet]
20+
var ffilePdfOptimizeFileSize = function (e) {
21+
const file_reader = new FileReader();
22+
file_reader.onload = (event) => {
23+
const imageQuality = 50;
24+
/*Optimize size of PDF-file with image compression quality and save the "ResultPdfOptimizeFileSize.pdf"*/
25+
const json = AsposePdfOptimizeFileSize(event.target.result, e.target.files[0].name, imageQuality, "ResultPdfOptimizeFileSize.pdf");
26+
if (json.errorCode == 0) document.getElementById('output').textContent = json.fileNameResult
27+
else document.getElementById('output').textContent = json.errorText;
28+
/*Make a link to download the result file*/
29+
DownloadFile(json.fileNameResult, "application/pdf");
30+
};
31+
file_reader.readAsArrayBuffer(e.target.files[0]);
32+
};
33+
/// [Code snippet]
34+
</script>
35+
36+
</html>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<meta charset="UTF-8">
7+
<title>Aspose.PDF for JavaScript via C++</title>
8+
</head>
9+
10+
<body>
11+
<label for="filePdfOptimizeFileSize">Choose a PDF-file to optimize size with image compression quality</label>
12+
<input type="file" id="filePdfOptimizeFileSize" accept="application/pdf" onchange="ffilePdfOptimizeFileSize(event)">
13+
<br>
14+
<pre id="output">please wait for loading...</pre>
15+
</body>
16+
17+
<script type="text/javascript">
18+
/// [Code snippet]
19+
/*Create Web Worker*/
20+
const AsposePDFWebWorker = new Worker("AsposePDFforJS.js");
21+
AsposePDFWebWorker.onerror = evt => console.log(`Error from Web Worker: ${evt.message}`);
22+
AsposePDFWebWorker.onmessage = evt => document.getElementById('output').textContent =
23+
(evt.data == 'ready') ? 'loaded!' :
24+
(evt.data.json.errorCode == 0) ? `Result:\n${DownloadFile(evt.data.json.fileNameResult, "application/pdf", evt.data.params[0])}` : `Error: ${evt.data.json.errorText}`;
25+
26+
/*Event handler*/
27+
const ffilePdfOptimizeFileSize = e => {
28+
const file_reader = new FileReader();
29+
file_reader.onload = event => {
30+
const imageQuality = 50;
31+
/*Optimize size of PDF-file with image compression quality and save the "ResultPdfOptimizeFileSize.pdf" - Ask Web Worker*/
32+
AsposePDFWebWorker.postMessage({ "operation": 'AsposePdfOptimizeFileSize', "params": [event.target.result, e.target.files[0].name, imageQuality, "ResultPdfOptimizeFileSize.pdf"] }, [event.target.result]);
33+
};
34+
file_reader.readAsArrayBuffer(e.target.files[0]);
35+
};
36+
/// [Code snippet]
37+
38+
/*Make a link to download the result file*/
39+
const DownloadFile = (filename, mime, content) => {
40+
mime = mime || "application/octet-stream";
41+
var link = document.createElement("a");
42+
link.href = URL.createObjectURL(new Blob([content], {type: mime}));
43+
link.download = filename;
44+
link.innerHTML = "Click here to download the file " + filename;
45+
document.body.appendChild(link);
46+
document.body.appendChild(document.createElement("br"));
47+
return filename;
48+
}
49+
</script>
50+
51+
</html>

0 commit comments

Comments
 (0)