Pdf.js: passing query params to url specified in 'file='

Created on 13 Jun 2014  路  2Comments  路  Source: mozilla/pdf.js

Really like pdf.js, one big question i do have though, for pdf.js i provide it a file to read by doing 'viewer.html?file=http://mywebsite.com/getpdf.php'.

Is it possible to pass a query param to getpdf.php such as a record ID in the database to extract the PDF file from?

Basically would love to be able to do 'viewer.html?file=http://mywebsite.com/getpdf.php?id=1' or something similar.

Most helpful comment

URL-encode the parameter, e.g.

<?php
$url = 'viewer.html?file=' . urlencode('http://example.com/getpdf.pdf?id=1');
echo $url;
?>

or

var url = 'viewer.html?file=' + encodeURIComponent('http://example.com/getpdf.pdf?id=1');
alert(url);

All 2 comments

URL-encode the parameter, e.g.

<?php
$url = 'viewer.html?file=' . urlencode('http://example.com/getpdf.pdf?id=1');
echo $url;
?>

or

var url = 'viewer.html?file=' + encodeURIComponent('http://example.com/getpdf.pdf?id=1');
alert(url);

... the http://example.com/getpdf.pdf?id=1 shall return valid PDF file/stream, but that's out of scope of this project (http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx might help). Closing as answered.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlexP3 picture AlexP3  路  3Comments

xingxiaoyiyio picture xingxiaoyiyio  路  3Comments

PeterNerlich picture PeterNerlich  路  3Comments

dmisdm picture dmisdm  路  3Comments

anggikolo11 picture anggikolo11  路  3Comments