Reading pdf file from local http server

113 views
Skip to first unread message

vanc

unread,
Nov 29, 2017, 11:55:31 AM11/29/17
to PDFTron WebViewer
PDFTron team,

First tried reading the pdf file from file syytem without giving server name, It worked perfectly. Now using local http server to read the same file, using serverUrl, but the file is not not getting loaded and doesn#t give any error. However the webviewer shows initializing...100% and nothing happens.
My sample code below:

var myWebViewer = new PDFTron.WebViewer({
//path: "WebViewer/lib",
path: "/WebViewer/lib",
type: "html5",
l: licenkey,
documentType: "pdf",
xdomainProxyUrl: "/proxy.html",
initialDoc : "/test.pdf",
showLocalFilePicker: true,
enableAnnotations:true,
config: "/nCconfig.js",
streaming: true,
showToolbarControl:true,
annotationUser: 'Guest',
annotationAdmin: true,
serverUrl: 'http://localhost:8080'
}, viewerElement);

Please help and suggest what is wrong or missing here.
Thanks!

Matt Parizeau

unread,
Nov 29, 2017, 6:56:53 PM11/29/17
to PDFTron WebViewer
Hi,

The serverUrl option is meant to be the endpoint that handles your annotation loading. Are you referring to annotation loading or document loading? For annotation loading see here https://www.pdftron.com/webviewer/demo/tutorials/getting-started-annotations.html

For document loading you can specify the initialDoc relative to your html file, or as you've done in your code snippet, relative to the root of your server. So if your html file is at localhost:8080/html/index.html and your file is at localhost:8080/test.pdf you could set the initialDoc like you've done there. Alternatively you could set it to a relative path like '../test.pdf'

Do you see any errors in the developer console?

Matt Parizeau
Software Developer
PDFTron Systems Inc.

vanc

unread,
Nov 30, 2017, 12:13:52 PM11/30/17
to PDFTron WebViewer
Hi Matt,

Thanks so much for your response. I could able to solve the issue of reading file from same domain server per your suggestions. However, my actual requirement is to read the pdf file from cross-domain. I am using SharePoint to load the viewer in a page. And trying to load the file in App Context of SharePoint from the Host web, however it is giving me following error:
Origin http://app-<guid>.test not found in Access-Control-Allow-Origin header.
I have set all required permissions and using SP.RequestExecutor to read the file and from the host web. Still Webviewer is not giving an option to ask for username and password and gives network failure.

Please help!

vanc

unread,
Nov 30, 2017, 12:16:11 PM11/30/17
to PDFTron WebViewer
To add more, I am using Edge and IE 11, so does that need those request headers to be inserted explicitly.
I get following 401 for the file I am trying to access:
DENIED - The requested resource requires user authentication.

Thanks much!!


On Thursday, November 30, 2017 at 12:56:53 AM UTC+1, Matt Parizeau wrote:

Justin Jung

unread,
Dec 1, 2017, 4:58:38 PM12/1/17
to PDFTron WebViewer on behalf of vanc
Hello,

You can refer to this post where two WebViewer users discussed their SharePoint implementations: https://groups.google.com/d/msg/pdfnet-webviewer/I63hvVavhbc/XejKjINa5-IJ
Also, WebViewer expects that the client will already be authenticated to access the document when loading initially. Your application will need to handle the user authentication beforehand.

Justin Jung
Reply all
Reply to author
Forward
0 new messages