0

I am using PDF.js to open a PDF file currently and its working fine.

Previously I was using like this:

http://myapp.mycompany.com/web/viewer.html?file=http://myapp.mycompany.com/my-PDF-file.pdf

My Problem:

For some reasons, I really do not want to reveal the file path of my PDF file and want to move my PDF files outside root directory. Is there any other way to provide the pdf file to the viewer.html? or is this the oly way?

NOTE: I have moved all the PDF files outside my root directory. So How can I access the PDF now?

2 Answers 2

4

Yes, there is. Call some function instead (and you don't even need PDF.js):

http://www.example.com/getPDF.php?fileName=pdfname.pdf

function fileName() {
    $fileName = $_GET['fileName'];
    header("Content-type:application/pdf");
    header("Content-Disposition:inline;filename='{$fileName}'");
    readfile(__DIR__."/../pdfs/private/{$fileName}");
}
Sign up to request clarification or add additional context in comments.

5 Comments

sorry..I want to use PDF.js, since it provides a good looking reviewer ,how can I use PDF.js to load a file, do u have any idea on that?
Change your URL to http://myapp.mycompany.com/web/viewer.html?file=http://myapp.mycompany.com/getPDF.php?filename=pdfname.pdf and the above response would be the contents of file getPDF.php you may need to urlencode the part after file= (depending on the implementation in viewer.html)
@apokryfos: hey I got it worked,thank you so much for your suggestion :)
@Abhinav PDF.js is mostly for browsers that does not support native PDF preview or if you want to make some advanced actions with your PDF.
@Justinas: yeah,I was looking for some advanced actions thats why I wanted to implement it through PDF.js, and I solved it wid your suggestion, thnx :)
0

Use rawurlencode to encode '/getP‌​DF.php?filename=pdfname.pdf' part:

"http://myapp.mycompany.com/web/viewer.html?file=".rawurlencode("/getP‌​DF.php?filename=".rawurlencode("pdfname.pdf"))

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.