Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to render href links with additional attributes

1,810 views
Skip to first unread message

Vincenzo Bacarella

unread,
Jan 27, 2014, 9:55:36 AM1/27/14
to dev-p...@lists.mozilla.org
Hi,

I would know how to mod PDF.js in order to render all links inside PDF with

- target="_blank" , so links are opened in a new window (and not in the
same windows, loosing the PDF.js viewer)
- with an additional class='xyz' in order to manage these link with my js
stuff

Thanks!

Leonard Rosenthol

unread,
Jan 27, 2014, 10:54:45 AM1/27/14
to Vincenzo Bacarella, dev-p...@lists.mozilla.org
What you really should do is look at the PDF object for that link and use
the specified target since PDF links support a "target" option and pdf.js
should respect that.

Leonard

On 1/27/14 6:55 AM, "Vincenzo Bacarella" <vincenzo....@gmail.com>
wrote:
>_______________________________________________
>dev-pdf-js mailing list
>dev-p...@lists.mozilla.org
>https://lists.mozilla.org/listinfo/dev-pdf-js

Vincenzo Bacarella

unread,
Jan 28, 2014, 7:54:30 AM1/28/14
to
Hi Leonard,

thanks, but I don't see any support to "target" option in the PDF reference.

The only solution is to translate the href at rendering time inside PDF.js.

Any suggestion on where to insert the mod?

Thanks

Leonard Rosenthol

unread,
Jan 28, 2014, 8:10:47 AM1/28/14
to Vincenzo Bacarella, dev-p...@lists.mozilla.org
The Remote GoTo and Embedded GoTo actions both have a NewWindow key that
is equivalent to target for PDF. For URI actions, I would probably always
open them in a separate window since that's expected behavior going from a
PDF to an arbitrary web link (which could be anything).

Leonard

On 1/28/14 4:54 AM, "Vincenzo Bacarella" <vincenzo....@gmail.com>
wrote:

Yury Delendik

unread,
Jan 28, 2014, 8:11:23 AM1/28/14
to Vincenzo Bacarella
Hi Vincenzo,

We had a similar discussion [1]. So, yes, if the specification allows to
specify a new window destination for PDF link, we will need to fix that
by setting the target attribute.

What you are asking is easy to address by changing the code at
annotation.js [2].

[1] https://github.com/mozilla/pdf.js/issues/3812
[2]
https://github.com/mozilla/pdf.js/blob/master/src/shared/annotation.js#L704

Thanks

Vincenzo Bacarella

unread,
Jan 28, 2014, 10:57:04 AM1/28/14
to
Thanks Yury,

I was able to add

element.target = "_blank";
element.className = "iframe";


My purpose is to integrate the ColorBox jQuery Plugin (http://www.jacklmoore.com/colorbox/) in order to open external pdf link in a rich overlayer.

So:

- I modified the rendering of external pdf link with class=iframe and target=_blank through annotation.js

- I inserted in the head of viewer.html

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.jacklmoore.com/colorbox/jquery.colorbox.js"></script>

- I inserted in viewer.html before </body>

<script>
jQuery("a.iframe").colorbox({iframe:true, width:"50%", height:"60%"});
</script>

But it doesn't work, the external link is opened just like a simple link in a new window (due to target=_blank)

Any suggestion?

Thanks again for you work, is very impressive.

Yury Delendik

unread,
Jan 28, 2014, 4:39:04 PM1/28/14
to Vincenzo Bacarella
On 1/28/14, 9:57 AM, Vincenzo Bacarella wrote:

> I was able to add
>
> element.target = "_blank";
> element.className = "iframe";
>

....

> - I inserted in viewer.html before </body>
>
> <script>
> jQuery("a.iframe").colorbox({iframe:true, width:"50%", height:"60%"});
> </script>
>
> But it doesn't work, the external link is opened just like a simple link in a new window (due to target=_blank)
>

Rendering of the pages happens asynchronously. (I don't use/known jQuery
or ColorBox) Try something like this at the annotations.js instead of
className assignment:

jQuery(element).colorbox({iframe:true, width:"50%", height:"60%"});


Vincenzo Bacarella

unread,
Jan 29, 2014, 10:28:38 AM1/29/14
to
Thanks, it works now.

Aditya M

unread,
Feb 22, 2014, 3:08:23 AM2/22/14
to
Hi Vincenzo,

When PDF is opened from another site by clicking on a link and look at the source code we can see the viewer.html. How is viewer.html created in the first place. What defines the HTML mark up in viewer.html.

The PDF is obtained in array of bytes. So how is the canvas and text layer created in first place.

Please be kind to reply.
Thank you
0 new messages