Skip to content

Commit ebae0cb

Browse files
Aspose.PDF for JavaScript via C++ 25.7
1 parent cbc8160 commit ebae0cb

File tree

7 files changed

+122
-14
lines changed

7 files changed

+122
-14
lines changed

AsposePDFforJS.js

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

AsposePDFforJS.wasm.zip

135 KB
Binary file not shown.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Add PDF processing, manipulation, and conversion features to your front-end appl
2020
- **Office formats:** DOC, DOCX, XLS, XLSX, PPTX
2121
- **Web formats:** SVG, SVG (ZIP), XPS, EPUB
2222
- **Image formats:** JPEG, PNG, BMP, TIFF, DICOM
23-
- **Other formats:** Grayscale PDF, PDF/A, TeX, TXT
23+
- **Other formats:** Grayscale PDF, PDF/A, TeX, TXT, Markdown
2424
- **Manipulate** PDF structure and content:
2525
- Bookmarks, hyperlinks, annotations, attachments, JavaScript
2626
- Fonts, metadata, layers, background color

example.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ <h2>Aspose.PDF for JavaScript via C++</h2>
126126
<label for="fileToPDF">PDF<span class="tooltip">Convert a PDF-file to PDF (separate pages)</span></label>
127127
<input type="file" id="fileToPDF" accept="application/pdf" onchange="ffileToPDF(event)">
128128
</div>
129+
<div class="column">
130+
<label for="fileToMarkdown">MD<span class="tooltip">Convert a PDF-file to Markdown</span></label>
131+
<input type="file" id="fileToMarkdown" accept="application/pdf" onchange="ffileToMarkdown(event)">
132+
</div>
129133
</div>
130134
</div>
131135

@@ -1107,6 +1111,17 @@ <h2>Aspose.PDF for JavaScript via C++</h2>
11071111
file_reader.readAsArrayBuffer(e.target.files[0]);
11081112
}
11091113

1114+
var ffileToMarkdown= function (e) {
1115+
const file_reader = new FileReader();
1116+
file_reader.onload = (event) => {
1117+
const json = AsposePdfToMarkdown(event.target.result, e.target.files[0].name, "ResultPDFtoMarkdown.md");
1118+
if (json.errorCode == 0) document.getElementById('output').textContent = json.fileNameResult;
1119+
else document.getElementById('output').textContent = json.errorText;
1120+
DownloadFile(json.fileNameResult, "text/markdown");
1121+
}
1122+
file_reader.readAsArrayBuffer(e.target.files[0]);
1123+
}
1124+
11101125
var ffilePdfValidatePDFA = function (e) {
11111126
const file_reader = new FileReader();
11121127
file_reader.onload = (event) => {

example_worker.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<option value="AsposePdfToEPUB">Convert a PDF-file to ePub</option>
4646
<option value="AsposePdfToDoc">Convert a PDF-file to Doc</option>
4747
<option value="AsposePdfToPptX">Convert a PDF-file to PptX</option>
48+
<option value="AsposePdfToMarkdown">Convert a PDF-file to Markdown</option>
4849
<option value="AsposePdfExtractText" selected>Extract text from a PDF-file</option>
4950
<option value="AsposePdfExtractImage">Extract image from a PDF-file</option>
5051
<option value="AsposePdfExportFdf">Export from a PDF-file with AcroForm to FDF</option>
@@ -275,6 +276,9 @@
275276
case 'AsposePdfToTxt':
276277
DownloadFile(json.fileNameResult, "text/plain", params[0]);
277278
break;
279+
case 'AsposePdfToMarkdown':
280+
DownloadFile(json.fileNameResult, "text/markdown", params[0]);
281+
break;
278282
case 'AsposePdfTablesToCSV':
279283
document.getElementById('output').textContent = "Files(tables) count: " + json.filesCount.toString();
280284
for (let fileIndex = 0; fileIndex < json.filesCount; fileIndex++)
@@ -378,6 +382,10 @@
378382
transfer = [event.target.result];
379383
params = [event.target.result, ffile.name, `Result${operation}.txt`];
380384
break;
385+
case 'AsposePdfToMarkdown':
386+
transfer = [event.target.result];
387+
params = [event.target.result, ffile.name, `Result${operation}.md`];
388+
break;
381389
case 'AsposePdfToEPUB':
382390
transfer = [event.target.result];
383391
params = [event.target.result, ffile.name, `Result${operation}.epub`];

snippets/AsposePdfToMarkdown.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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="fileToMarkdown">Choose a PDF-file to convert to Markdown</label>
12+
<input type="file" id="fileToMarkdown" accept="application/pdf" onchange="ffileToMarkdown(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 ffileToMarkdown = function (e) {
21+
const file_reader = new FileReader();
22+
file_reader.onload = (event) => {
23+
/*Convert a PDF-file to Markdown and save the "ResultPDFtoMarkdown.md"*/
24+
const json = AsposePdfToMarkdown(event.target.result, e.target.files[0].name, "ResultPDFtoMarkdown.md");
25+
if (json.errorCode == 0) document.getElementById('output').textContent = json.fileNameResult
26+
else document.getElementById('output').textContent = json.errorText;
27+
/*Make a link to download the result file*/
28+
DownloadFile(json.fileNameResult, "text/markdown");
29+
}
30+
file_reader.readAsArrayBuffer(e.target.files[0]);
31+
}
32+
/// [Code snippet]
33+
</script>
34+
35+
</html>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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="fileToMarkdown">Choose a PDF-file to convert to Markdown</label>
12+
<input type="file" id="fileToMarkdown" accept="application/pdf" onchange="ffileToMarkdown(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, "text/markdown", evt.data.params[0])}` : `Error: ${evt.data.json.errorText}`;
25+
26+
/*Event handler*/
27+
const ffileToMarkdown = e => {
28+
const file_reader = new FileReader();
29+
file_reader.onload = event => {
30+
/*Convert a PDF-file to Markdown and save the "ResultPDFtoMarkdown.md" - Ask Web Worker*/
31+
AsposePDFWebWorker.postMessage({ "operation": 'AsposePdfToMarkdown', "params": [event.target.result, e.target.files[0].name, "ResultPDFtoMarkdown.md"] }, [event.target.result]);
32+
};
33+
file_reader.readAsArrayBuffer(e.target.files[0]);
34+
};
35+
/// [Code snippet]
36+
37+
/*Make a link to download the result file*/
38+
const DownloadFile = (filename, mime, content) => {
39+
mime = mime || "application/octet-stream";
40+
var link = document.createElement("a");
41+
link.href = URL.createObjectURL(new Blob([content], {type: mime}));
42+
link.download = filename;
43+
link.innerHTML = "Click here to download the file " + filename;
44+
document.body.appendChild(link);
45+
document.body.appendChild(document.createElement("br"));
46+
return filename;
47+
}
48+
</script>
49+
50+
</html>

0 commit comments

Comments
 (0)