Skip to content

Commit

Permalink
Adding withCredentials flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecousins committed May 4, 2019
1 parent 88fd629 commit cfae33c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-pdf-js",
"version": "5.0.2",
"version": "5.0.3",
"description": "Simple React component to wrap up PDF.js. The easiest way to render PDFs in your React app.",
"author": "mikecousins",
"license": "MIT",
Expand Down
27 changes: 24 additions & 3 deletions src/index.js
@@ -1,9 +1,29 @@
import PdfJsLib from 'pdfjs-dist';
import React, { useState, useEffect, useRef, useMemo } from 'react';

const Pdf = ({ file, onDocumentComplete, page, scale, rotate, cMapUrl, cMapPackged, workerSrc }) => {
const Pdf = ({
file,
onDocumentComplete,
page,
scale,
rotate,
cMapUrl,
cMapPackged,
workerSrc,
withCredentials,
}) => {
const canvasEl = useRef();
const [loading, numPages] = usePdf({ canvasEl, file, page, scale, rotate, cMapUrl, cMapPackged, workerSrc });
const [loading, numPages] = usePdf({
canvasEl,
file,
page,
scale,
rotate,
cMapUrl,
cMapPackged,
workerSrc,
withCredentials,
});

useEffect(() => {
onDocumentComplete(numPages);
Expand All @@ -25,6 +45,7 @@ export const usePdf = ({
cMapUrl = '../node_modules/pdfjs-dist/cmaps/',
cMapPacked = false,
workerSrc = '//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.1.266/pdf.worker.js',
withCredentials = false,
}) => {
const [pdf, setPdf] = useState(null);

Expand All @@ -33,7 +54,7 @@ export const usePdf = ({
}, []);

useEffect(() => {
PdfJsLib.getDocument({ url: file, cMapUrl, cMapPacked }).promise.then(setPdf);
PdfJsLib.getDocument({ url: file, cMapUrl, cMapPacked, withCredentials }).promise.then(setPdf);
}, [file, cMapUrl, cMapPacked]);

// handle changes
Expand Down

0 comments on commit cfae33c

Please sign in to comment.