Skip to content

PDF.js not working in VSCode webview #20042

Closed Answered by a-gss
a-gss asked this question in Q&A
Discussion options

You must be logged in to vote

Ok forget about ES6 ! It actually works. I thought that because of an open issue on the vscode repo saying you could not.

The PDFjs viewer API changed a bit from v3 to v5, you need to pass the PDF URI as an object to the open function. Something like this:

const pdfWebviewUri = webview.asWebviewUri(vscode.Uri.file(pdfPath)).toString();
...
const injectScript = `
            <script>
                window.addEventListener('load', function () {
                    const pdfUri = '${pdfWebviewUri}';
                    if (!pdfUri) { return; }

                    if (window.PDFViewerApplication) {
                        PDFViewerApplication.initializedPromise.then(() => {

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by a-gss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant