question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

missing support for "view" parameter in URL fragment identifiers

See original GitHub issue

According to Parameters for Opening PDF Files (version 9.0) (and referenced in RFC 8118):

view=Fit view=FitH view=FitH,top view=FitV view=FitV,left view=FitB view=FitBH view=FitBH,top view=FitBV view=FitBV,left

Set the view of the displayed page, using the keyword values defined in the PDF language specification. For more information, see the PDF Reference. Scroll values left and top are floats or integers in a coordinate system where 0,0 represents the top left corner of the visible page, regardless of document rotation.

It appears that the view parameter in PDF URL fragment identifiers is currently unsupported. To verify, I tested as follows:


Configuration:

Steps to reproduce the problem:

  1. Check out the repository, run npm install and gulp server, then navigate the viewer to a PDF that isn’t automatically zoomed in to fill your viewport width on viewer initialization (http://localhost:8888/web/viewer.html?file=%2Ftest%2Fpdfs%2Ftracemonkey.pdf works for me).
  2. Append #page=1&view=FitH to the URL in the address bar, and reload the page.

What is the expected behavior?

The viewer should set the zoom level so that the PDF fills the entire width of the viewport.

What went wrong?

The viewport was not transformed as expected.


It looks like the problem is mainly with PDFLinkService.setHash. There is no check for the view parameter.

Interestingly enough, Fit* values are being checked for in the zoomparameter, but I’m having trouble understanding why (since none of RFC 3778, RFC 8118, or the PDF Open Parameters document say that those are vallid values for zoom). The deepest I was able to dig was this PR, but it looks like Fit* values have been handled this way even before that.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
residentevil1256commented, Oct 29, 2019

Hello, I am working on a project for a software course and I would love to work on this. I noticed that the Fit* values work for the zoom parameter. I want to make sure that adding support for these values for the view parameter is still a desired feature. If so, I would appreciate any additional information anyone has on this since it is my first time contributing to a public Open-Source project. Thank you.

0reactions
ousiacommented, Nov 15, 2022

@timvandermeij, as you suggested, I think the values from view and zoom may be split such as in:

if (params.has("view")) {
  const viewArgs = params.get("view").split(",");
  const viewArg = viewArgs[0];

  if (viewArg === "Fit" || viewArg === "FitB") {
    dest = [null, { name: viewArg }];
  } else if (
    viewArg === "FitH" ||
    viewArg === "FitBH" ||
    viewArg === "FitV" ||
    viewArg === "FitBV"
  ) {
    dest = [
      null,
      { name: viewArg },
      viewArgs.length > 1 ? viewArgs[1] | 0 : null,
    ];
  } else if (viewArg === "FitR") {
    if (viewArgs.length !== 5) {
      console.error(
        'PDFLinkService.setHash: Not enough parameters for "FitR".'
      );
    } else {
      dest = [
        null,
        { name: viewArg },
        viewArgs[1] | 0,
        viewArgs[2] | 0,
        viewArgs[3] | 0,
        viewArgs[4] | 0,
      ];
    }
  } else {
    console.error(
      `PDFLinkService.setHash: "${viewArg}" is not a valid view value.`
    );
  }
}

if (params.has("zoom")) {
  // Build the destination array.
  const zoomArgs = params.get("zoom").split(","); // scale,left,top
  const zoomArg = zoomArgs[0];
  const zoomArgNumber = parseFloat(zoomArg);

  // If the zoomArg is a number, it has to get divided by 100.
  dest = [
    null,
    { name: "XYZ" },
    zoomArgs.length > 1 ? zoomArgs[1] | 0 : null,
    zoomArgs.length > 2 ? zoomArgs[2] | 0 : null,
    zoomArgNumber ? zoomArgNumber / 100 : zoomArg,
  ];
}

If this is right (I have basically copied and pasted text), I don’t mind to submit a PR. But consider that I cannot code properly (very basic Lua exposure and no proper JavaScript).

Many thanks for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

6 Things You Should Know About Fragment URLs
1. A Fragment URL Specifies A Location Within A Page Any URL that contains a # character is a fragment URL. The portion...
Read more >
Get fragment (value after hash '#') from a URL [closed]
I found in the apache docs here http://httpd.apache.org/docs/2.2/rewrite/advanced.html the following... By default, redirecting to an HTML anchor doesn't work, ...
Read more >
Preserve URL fragment across sign-in and sign-up redirects
This allows links to a specific line in a private project's file to work by preserving the line number fragment across sign-in and...
Read more >
Hash URIs | W3C Blog
When a URI reference is used to perform a retrieval action on the identified resource, the optional fragment identifier, separated from the ...
Read more >
Common Routing Tasks - Angular
This element informs Angular to update the application view with the component for the selected route. Template with routerLink and router-outlet content_copy < ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found