react-pdf
react-pdf copied to clipboard
Error Loading PDF - Warning: getHexString - ignoring invalid character
Before you start - checklist
- [x] I followed instructions in documentation written for my React-PDF version
- [x] I have checked if this bug is not already reported
- [x] I have checked if an issue is not listed in Known issues
- [x] If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo
Description
I copied the exact example from https://github.com/wojtekmaj/react-pdf/blob/main/sample/vite/Sample.tsx but the PDF won't load.
I tried setting the file as sample.pdf, /sample.pdf and ./sample.pdf and had the same results with all 3.
Using the load from file option to open the same PDF file works fine.
Steps to reproduce
Open the page that renders the Sample component
Expected behavior
PDF loads
Actual behavior
Errors with
Warning: getHexString - ignoring additional invalid characters.
pdf.worker.min.mjs:26 Warning: getHexString - ignoring invalid character: 33
pdf.worker.min.mjs:26 Warning: getHexString - ignoring invalid character: 79
pdf.worker.min.mjs:26 Warning: getHexString - ignoring invalid character: 84
pdf.worker.min.mjs:26 Warning: getHexString - ignoring invalid character: 89
pdf.worker.min.mjs:26 Warning: getHexString - ignoring invalid character: 80
pdf.worker.min.mjs:26 Warning: getHexString - ignoring additional invalid characters.
pdf.worker.min.mjs:26 Warning: getHexString - ignoring invalid character: 104
pdf.worker.min.mjs:26 Warning: getHexString - ignoring invalid character: 116
pdf.worker.min.mjs:26 Warning: getHexString - ignoring invalid character: 109
pdf.worker.min.mjs:26 Warning: getHexString - ignoring invalid character: 108
pdf.worker.min.mjs:26 Warning: getHexString - ignoring invalid character: 104
pdf.worker.min.mjs:26 Warning: Indexing all PDF objects
react-pdf.js?v=b7a02def:42 Warning: InvalidPDFException: Invalid PDF structure.
printWarning2 @ react-pdf.js?v=b7a02def:42
warning9 @ react-pdf.js?v=b7a02def:61
onLoadError @ react-pdf.js?v=b7a02def:710
(anonymous) @ react-pdf.js?v=b7a02def:748
commitHookEffectListMount @ chunk-UF2ZKYJO.js?v=b7a02def:16883
commitPassiveMountOnFiber @ chunk-UF2ZKYJO.js?v=b7a02def:18124
commitPassiveMountEffects_complete @ chunk-UF2ZKYJO.js?v=b7a02def:18097
commitPassiveMountEffects_begin @ chunk-UF2ZKYJO.js?v=b7a02def:18087
commitPassiveMountEffects @ chunk-UF2ZKYJO.js?v=b7a02def:18077
flushPassiveEffectsImpl @ chunk-UF2ZKYJO.js?v=b7a02def:19458
flushPassiveEffects @ chunk-UF2ZKYJO.js?v=b7a02def:19415
(anonymous) @ chunk-UF2ZKYJO.js?v=b7a02def:19296
workLoop @ chunk-UF2ZKYJO.js?v=b7a02def:197
flushWork @ chunk-UF2ZKYJO.js?v=b7a02def:176
performWorkUntilDeadline @ chunk-UF2ZKYJO.js?v=b7a02def:384
Additional information
My vite.cofig.ts:
/// <reference types="vitest" />
import * as path from "path";
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig } from "vite";
import { VitePWA } from "vite-plugin-pwa";
export default defineConfig({
base: "/",
test: {
environment: 'jsdom',
},
plugins: [
VitePWA({
includeAssets: ["favicon.ico", "robots.txt"],
manifest: {
name: "Django React Template",
theme_color: "#012D3D",
icons: [
{
src: "logo.png",
sizes: "128x128",
type: "image/png",
purpose: "any maskable",
},
],
},
registerType: "autoUpdate",
workbox: {
globPatterns: ["**/*.{js,css,html,ico,png,svg}"],
maximumFileSizeToCacheInBytes: 540000,
cleanupOutdatedCaches: true,
},
}),
react(),
tsconfigPaths(),
],
build: {
chunkSizeWarningLimit: 600,
dynamicImportVarsOptions: {
warnOnError: true
}
},
resolve: {
alias: {
"@": path.resolve(__dirname, "/src/"),
},
},
server: {
host: "0.0.0.0",
port: 8001,
},
preview: {
host: "0.0.0.0",
port: 8001,
},
optimizeDeps: {
include: ['react-pdf', 'pdfjs-dist']
},
});
Environment
- Browser (if applicable):
- React-PDF version: ^10.1.0
- React version: ^18.2.0
- Bundler name and version (if applicable):
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.
That's PDF.js issue, not ours. You may report it to them, attaching the PDF it has issues with.