Skip to content

Commit 0fa8aaa

Browse files
committed
Added experimental ghostscript wasm conversion using zero config
1 parent 9480084 commit 0fa8aaa

11 files changed

Lines changed: 459 additions & 590 deletions

File tree

.vscodeignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ demo/**
2121
.prettierignore
2222
.prettierrc
2323
.yarnrc
24+
.github/**
25+
.vscode-test/**
2426
CODE_OF_CONDUCT.md
2527
CONTRIBUTING.md
2628
generateEmojiShortcodeMap.js
@@ -30,3 +32,9 @@ tsconfig.webviews.json
3032
tsconfig.tsbuildinfo
3133
webpack.config.js
3234
yarn.lock
35+
node_modules/pdfjs-dist/legacy/**
36+
node_modules/pdfjs-dist/types/**
37+
node_modules/pdfjs-dist/web/**
38+
src/test/**
39+
demo/**
40+
docs/**

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## [0.6.0] - 2025-12-24
4+
5+
### Major Changes
6+
7+
- **Internal Rendering**: Removed dependency on external tools (`Ghostscript`, `Poppler`, `pdfcairo`). The extension now renders PostScript files internally using WebAssembly (`postscript-wasm`) and `pdf.js`.
8+
- **Zero Config**: Removed all path configuration settings. The extension works out of the box without any setup.
9+
310
## [0.5.4] - 2025-12-23
411

512
- Fixed an issue where previewing files with special characters in the filename (e.g., spaces, parentheses) would fail with a syntax error.

README.md

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
<p align="center">
88
<img src="https://github.com/ahnafnafee/PostScript-Preview/raw/master/images/logo.png" alt="PostScript Preview Logo" width="128px" height="auto" />
99
</p>
10-
<p align="center">
11-
<br/>
12-
<a title="READ REQUIREMENTS AFTER INSTALL" href="#-requirements"><img src="https://github.com/ahnafnafee/PostScript-Preview/raw/master/docs/images/req-btn.png" alt="Read Requirements After Install"></a>
13-
</p>
1410

1511
<h1 align="center">PostScript Preview for VS Code</h1>
1612

@@ -41,69 +37,14 @@
4137
This extension requires:
4238

4339
- **[PostScript Language](https://marketplace.visualstudio.com/items?itemName=mxschmitt.postscript)** extension for syntax highlighting
44-
- **GhostScript** (provides `ps2pdf`)
45-
- **Poppler** (provides `pdftocairo` and `pdfinfo`)
46-
47-
### macOS
48-
49-
```bash
50-
brew install ghostscript poppler
51-
```
52-
53-
### Ubuntu / Debian
54-
55-
```bash
56-
sudo apt-get install ghostscript poppler-utils -y
57-
```
58-
59-
### Windows
60-
61-
Install via [Chocolatey](https://chocolatey.org/install) (run as Administrator):
62-
63-
```powershell
64-
choco install ghostscript --version 9.55.0 --force -y
65-
choco install poppler --version 0.89.0 -y --force
66-
```
67-
68-
Add to PATH:
69-
70-
```powershell
71-
[Environment]::SetEnvironmentVariable("Path",[Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) + ";C:\Program Files\gs\gs9.55.0\lib;C:\Program Files\gs\gs9.55.0\bin;C:\ProgramData\chocolatey\lib\poppler\tools",[EnvironmentVariableTarget]::Machine)
72-
```
7340

74-
**Restart VS Code** after installation.
75-
76-
<details>
77-
<summary>Manual PATH setup</summary>
78-
79-
If you have issues setting PATH, add these manually via System Properties → Environment Variables:
80-
81-
```
82-
C:\Program Files\gs\gs9.55.0\lib
83-
C:\Program Files\gs\gs9.55.0\bin
84-
C:\ProgramData\chocolatey\lib\poppler\tools
85-
```
86-
87-
</details>
41+
**Note:** Pre-0.6.0 versions required external installations of Ghostscript and Poppler. As of v0.6.0, these are **no longer required**! The extension now handles rendering internally using WebAssembly.
8842

8943
## Configuration
9044

91-
Configure custom executable paths in VS Code settings (useful for conda environments or non-standard installations):
45+
The extension is zero-config!
9246

93-
| Setting | Description | Default |
94-
| ------------------------------------ | ----------------------------- | ------------ |
95-
| `postscript-preview.path.ps2pdf` | Path to ps2pdf executable | `ps2pdf` |
96-
| `postscript-preview.path.pdftocairo` | Path to pdftocairo executable | `pdftocairo` |
97-
| `postscript-preview.path.pdfinfo` | Path to pdfinfo executable | `pdfinfo` |
98-
99-
Example `settings.json`:
100-
101-
```json
102-
{
103-
"postscript-preview.path.ps2pdf": "/opt/ghostscript/bin/ps2pdf",
104-
"postscript-preview.path.pdftocairo": "/opt/poppler/bin/pdftocairo"
105-
}
106-
```
47+
Previous configuration settings (`postscript-preview.path.*`) have been deprecated and removed as they are no longer needed.
10748

10849
## Multi-Page Documents
10950

package.json

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "postscript-preview",
33
"displayName": "PostScript Preview",
44
"description": "PostScript Preview is an extension that helps to preview EPS and PS files in Visual Studio Code.",
5-
"version": "0.5.4",
5+
"version": "0.6.0",
66
"icon": "images/logo.png",
77
"publisher": "ahnafnafee",
88
"engines": {
@@ -45,26 +45,6 @@
4545
"group": "navigation"
4646
}
4747
]
48-
},
49-
"configuration": {
50-
"title": "PostScript Preview",
51-
"properties": {
52-
"postscript-preview.path.ps2pdf": {
53-
"type": "string",
54-
"default": "ps2pdf",
55-
"description": "Path to ps2pdf executable (from GhostScript). Use this if ps2pdf is not in your system PATH."
56-
},
57-
"postscript-preview.path.pdftocairo": {
58-
"type": "string",
59-
"default": "pdftocairo",
60-
"description": "Path to pdftocairo executable (from Poppler). Use this if pdftocairo is not in your system PATH."
61-
},
62-
"postscript-preview.path.pdfinfo": {
63-
"type": "string",
64-
"default": "pdfinfo",
65-
"description": "Path to pdfinfo executable (from Poppler). Used for detecting page count in multi-page documents."
66-
}
67-
}
6848
}
6949
},
7050
"scripts": {
@@ -88,8 +68,10 @@
8868
"typescript": "^5.9.3"
8969
},
9070
"dependencies": {
71+
"@jspawn/ghostscript-wasm": "^0.0.2",
9172
"@types/temp": "^0.9.4",
9273
"glob": "^7.2.3",
74+
"pdfjs-dist": "^5.4.449",
9375
"temp": "^0.9.1"
9476
},
9577
"repository": {

src/config.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
/**
2-
* Configuration management for PostScript Preview extension
2+
* Configurations for PostScript Preview
33
*/
44
import * as vscode from "vscode";
5-
import { ExtensionConfig } from "./types";
65

7-
/**
8-
* Get configuration values for executable paths
9-
*/
10-
export function getConfig(): ExtensionConfig {
11-
const config = vscode.workspace.getConfiguration("postscript-preview");
12-
return {
13-
ps2pdf: config.get<string>("path.ps2pdf", "ps2pdf"),
14-
pdftocairo: config.get<string>("path.pdftocairo", "pdftocairo"),
15-
pdfinfo: config.get<string>("path.pdfinfo", "pdfinfo"),
16-
};
6+
export interface Config {
7+
// No path configurations needed for internal rendering
8+
}
9+
10+
export function getConfig(): Config {
11+
// Return empty config or any future settings
12+
return {};
1713
}

src/extension.ts

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as vscode from "vscode";
77
import path = require("path");
88
import { PreviewState } from "./types";
99
import { generatePreview } from "./preview";
10-
import { showWhatsNew } from "./whats-new";
1110

1211
/**
1312
* Called when the extension is activated
@@ -18,7 +17,6 @@ export function activate(context: vscode.ExtensionContext): void {
1817

1918
if (isWindows) {
2019
console.log("PostScript Preview: Checking for updates (Windows)...");
21-
showWhatsNew(context);
2220
}
2321

2422
const channel = vscode.window.createOutputChannel("PostScript-Preview");
@@ -49,64 +47,10 @@ export function activate(context: vscode.ExtensionContext): void {
4947

5048
const mainFilePath = document.fileName;
5149

50+
// Generate preview without awaiting (fire and forget)
5251
generatePreview(mainFilePath, panel, channel);
5352
channel.appendLine(`Watching ${filePath}`);
5453

55-
// Handle messages from webview for page navigation
56-
panel.webview.onDidReceiveMessage(
57-
(message) => {
58-
const state = (panel as any).__previewState as
59-
| PreviewState
60-
| undefined;
61-
if (!state) {
62-
return;
63-
}
64-
65-
switch (message.command) {
66-
case "prevPage":
67-
if (state.currentPage > 1) {
68-
state.currentPage--;
69-
generatePreview(
70-
state.filepath,
71-
panel,
72-
channel,
73-
state.currentPage,
74-
state.pdfPath
75-
);
76-
}
77-
break;
78-
case "nextPage":
79-
if (state.currentPage < state.totalPages) {
80-
state.currentPage++;
81-
generatePreview(
82-
state.filepath,
83-
panel,
84-
channel,
85-
state.currentPage,
86-
state.pdfPath
87-
);
88-
}
89-
break;
90-
case "goToPage": {
91-
const page = parseInt(message.page, 10);
92-
if (page >= 1 && page <= state.totalPages) {
93-
state.currentPage = page;
94-
generatePreview(
95-
state.filepath,
96-
panel,
97-
channel,
98-
state.currentPage,
99-
state.pdfPath
100-
);
101-
}
102-
break;
103-
}
104-
}
105-
},
106-
undefined,
107-
context.subscriptions
108-
);
109-
11054
// Watch for file changes
11155
const watcher = vscode.workspace.createFileSystemWatcher(filePath);
11256
watcher.onDidChange((_: vscode.Uri) => {

0 commit comments

Comments
 (0)