Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any solution for use custom httpHeaders? #11792

Closed
zhuangzhuang opened this issue Apr 9, 2020 · 2 comments
Closed

Any solution for use custom httpHeaders? #11792

zhuangzhuang opened this issue Apr 9, 2020 · 2 comments

Comments

@zhuangzhuang
Copy link

Attach (recommended) or Link to PDF file here:

Configuration:

  • Web browser and its version:
  • Operating system and its version:
  • PDF.js version:
  • Is a browser extension:

Steps to reproduce the problem:

  1. on file viewer.js

    event.initCustomEvent("webviewerloaded", true, true, {});

    listen event and motify appOptions

  2. on file app.js

    const apiParameters = AppOptions.getAll(OptionKind.API);
    get config for api

  3. but app_options.js has not option for httpHeaders ,

    function getDocument(src) {
    support this option

What is the expected behavior? (add screenshot)

suport custom httpHeader for viewer.js
i can only hook xhr, fetch for hack this moment.

What went wrong? (add screenshot)

Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Apr 9, 2020

Configuration:

* Web browser and its version:

* Operating system and its version:

* PDF.js version:

* Is a browser extension:

When opening an issue, you always need to provide the above information (since otherwise it's not guaranteed that an answer applies to the PDF.js version you're using).

However, something along the following lines ought to work:

document.addEventListener("webviewerloaded", function() {
  // Prevent the default "tracemonkey.pdf" file from loading.
  PDFViewerApplicationOptions.set("defaultUrl", "");

  PDFViewerApplication.initializedPromise.then(function() {
    // The viewer has now been initialized.

    // Open your PDF file, with custom headers.
    PDFViewerApplication.open("A string containing the path to your PDF file", {
      httpHeaders: // Add your HTTP headers here.
    });
  })
});

@zhuangzhuang
Copy link
Author

@Snuffleupagus thanks for your help,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants