Support for Gatsby.js

PDF.js Express Version

Detailed description of issue
My project is built using Gatsby and I was following the getting started guide for React. (gatsby uses react) I made sure to copy all the files to the static/public folder. However when I initialize the page, it throws a 404 error inside the div where the webviewer ref is.
’ There’s not a page yet at /webviewer/lib/ui/index.html

Expected behaviour

Does your issue happen with every document, or just one?
Every document

Link to document

Code snippet
import React, { useEffect, useRef } from ‘react’
import Layout from ‘components/Layout’
import WebViewer from ‘@pdftron/pdfjs-express’

const Test = () => {
	const viewer = useRef(null)
	useEffect(() => {
				path: '/webviewer/lib',
				initialDoc: ''
		).then((instance) => {
	}, [])
	return (
			<div className="h-screen">
				<p>TEST PDF</p>
				<div className="webviewer" ref={viewer}></div>

export default Test

Hi there!

This is actually an issue I’ve had in the past with Gatsby as well. It happens because Gatsby is unable to serve static html files in development mode.

There is an open ticket you can view in the Gatsby repo here, and you can view a workaround that I actually posted a little while ago here.

Basically you just need to find another way to serve the PDF.js Express files in development mode.

Thank you,

Thanks for linking to that ticket. While I didn’t use your work around solution, I was able to find a bit simpler of a work around in that ticket. For anyone here looking in the future, all I had to do was add this snippet to my gatsby-node.js file:

const express = require('express')

exports.onCreateDevServer = ({ app }) => {
1 Like