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

Dynamically assign PDF file paths to the viewer #2496

Closed
msepahvand opened this issue Dec 20, 2012 · 22 comments
Closed

Dynamically assign PDF file paths to the viewer #2496

msepahvand opened this issue Dec 20, 2012 · 22 comments

Comments

@msepahvand
Copy link

I was wondering of there is any way for me to dynamically change the path of the PDF file referenced inside viewer.js? Inside my viewer.js right now I have:

var DEFAULT_URL = './MyPDFs/test1.pdf';

Obviously this is the link to the PDF I'm displaying. My question is: can I dynamically change that link (DEFAULT_URL) server side? I'm trying to implement a functionality whereby the user clicks on an entry in a table, I then retrieve the PDF related to that entry from the database, make a copy of it server side and assign the URL of that newly created PDF to the viewer.

Is this possible? If so how would I go about doing it? Thanks for any help, this project is so awesome.

@yurydelendik
Copy link
Contributor

@msepahvand
Copy link
Author

thanks again, you're a lifesaver.

@akashkakkar
Copy link

Hi, Can anyone of you be more descriptive about the solution. Will this method work with local storage url too?

@jviereck
Copy link
Contributor

Will this method work with local storage url too?

I guess it should.

@ghost
Copy link

ghost commented Nov 16, 2013

yurydelendik how can i change moodle default pdf viewer with pdf.js viewer and how can i integrate it with moodle and delete print or save buttons and right click .

@henry-mac
Copy link

How would you pass a base64 data instead of the url within javascript?
"data:application/pdf;base64,JVBERi0x..";

@henry-mac
Copy link

Thanks yurydelendik, I saw that link earlier. However, it only produces one page similar to the helloworld example. I want to be able to use all the features and functionality such as zoom,print,pages, of the http://mozilla.github.io/pdf.js/web/viewer.html.

@yurydelendik
Copy link
Contributor

btw, http://mozilla.github.io/pdf.js/web/viewer.html?file=data:application/pdf;base64,JVBERi0xLjcKCjEgMCBvY...U9G works for me in Firefox.

Also, I know that some browsers (e.g. Internet Explorer) truncate long URLs so you will be able to send only small PDFs.

@henry-mac
Copy link

This is great, I see it works in firefox now too. But it doesn't work in chrome which I do most of my development in because I have "-args --allow-file-access-from-files --disable-xss-auditor --disable-web-security". Also, I hope this will work on the ipad. Thanks for your help yurydelendik.

@ashok565656
Copy link

Hi ,
I am new to ViewerJS. I tried to add this in my GWT. When i use my local file (located in WAR) its open. But i need to open another server file. Is it possible?

/ViewerJS/index.html#../../Generate_Report-7.pdf" this link is working.

but i need like this, /ViewerJS/index.html#http://differentserver/Generate_Report-7.pdf"

Please guide me.

Thanks ,
Ashok

@timvandermeij
Copy link
Contributor

This is PDF.js, not ViewerJS. For ViewerJS support go to https://github.com/kogmbh/ViewerJS.

@timvandermeij
Copy link
Contributor

Please don't post unrelated questions on issues.

@whadla
Copy link

whadla commented Dec 18, 2015

Hello guys I've been searching around for a solution to my issue but I can't find anything I can use.The tool works great when I point to an existing pdf file. However, I'm having issues when I call a .net MVC controller to return a dynamically generated File of type "pdf". For Example: /web/viewer.html?file=URL (to my asp.net controller) Any suggestions would be greatly appreciated.

@whadla
Copy link

whadla commented Dec 18, 2015

Tim thanks for pointing us to ViewerJS. I found my solution here: webodf/ViewerJS#27

"ViewerJS 0.5.5 got released today, and it improves situation around content type detection. It both tries to query to server for the mimetype initially and also can be passed the type as argument in the passed url, e.g. /ViewerJS/index.html?type=pdf#http://mypage.com/service/createpdf
That should solve this problem, so closing this issue." -kossebau

Hopefully this will help anyone that's facing the same issue.

@piyusharc
Copy link

piyusharc commented Jan 6, 2017

Somebody please help me to fix my issue:-
i've developed a small application in php and mysql, where i'm uploading pdf and moving file to UPLOADS folder and storing path in database. But in viewing after passing path i'm not able to open pdf on browser.
i've uploaded PDF.JS files in my folder aswel.
please help me to come out of it. below is my testing url please visit

http://www.farukhzama.com/fileupload/index.php
http://www.farukhzama.com/fileupload/view.php

@MudassarIqbal853
Copy link

Hi
Enjoying using pdf.js
but I have a stuppid question may be this will not be related to all about the pdf.js but after all i wanna ask that i'm using a pdf.js in my project and using whole web page named as viewer.html but i want to open a pdf file in my viewer.html. So how can i do it??
Kind regards
Mudasssar

@nescant
Copy link

nescant commented Jul 3, 2018

Good::

pass it as the '?file=' param, e.g. http://mozilla.github.com/pdf.js/web/viewer.html?file=http%3A%2F%2Fasync5.org%2Fmoz%2Fpdfjs.pdf

nice code ...

@verma210
Copy link

pass it as the '?file=' param, e.g. http://mozilla.github.com/pdf.js/web/viewer.html?file=http%3A%2F%2Fasync5.org%2Fmoz%2Fpdfjs.pdf
In above example i want to hide url of file from users .
How can i pass url dynamically without showing it to users

@timvandermeij timvandermeij added other and removed other labels Sep 20, 2018
@skv90909090
Copy link

i want to know about that when i choose file and the file is preview in pdfjs viewer but i cant accept local path so for this firstly i save file in my project after i want to preview it how can i give path of this please solve my problem sir thanks in advance

@nescant
Copy link

nescant commented Oct 7, 2019

Hi
Enjoying using Asp.net Code..

<%@ Register Assembly="Spire.PdfViewer.Asp" Namespace="Spire.PdfViewer.Asp" TagPrefix="cc1" %>

50% 75% 100% 150% 200% 400%






      <input type="button" id="btnFirst" value="First" onclick="pdfdocumentviewer1.FirstPage()" />
    <input type="button" id="btnPrevious" value="Previous" onclick="pdfdocumentviewer1.PreviousPage()" />
    <input type="text" id="PdfDocumentViewer1_PdfViewerCurrentPage" value="1" style="width: 100px;" />
   Pages:<span id="PdfDocumentViewer1_PdfViwerCountPage"></span>
    <input type="button" id="btnNext" value="Next" onclick="pdfdocumentviewer1.NextPage()" />
    <input type="button" id="btnLast" value="Last" onclick="pdfdocumentviewer1.LastPage()" />

C# Code ..

       string pdflink = ds.Tables[0].Rows[0]["PDFFile"].ToString();
        byte[] pdfData = System.IO.File.ReadAllBytes(Server.MapPath(pdflink));

        //Load PDF byte array into RAD PDF

        //The interval time of emptying caching, specified in seconds.
        this.PdfDocumentViewer1.CacheInterval = 1200;
        //caching time of an image, specified in seconds.
        this.PdfDocumentViewer1.CacheTime = 1000;
        //Cache the number of Image, default is 1000.
        this.PdfDocumentViewer1.CacheNumberImage = 1000;
        //The time of responding to event after stop scrolling, specified in milliseconds.default is 500.
        this.PdfDocumentViewer1.ScrollInterval = 300;
        //Zoom value of page, default is 1.
        this.PdfDocumentViewer1.ZoomFactor = 1;
        this.PdfDocumentViewer1.CustomErrorMessages = "Error information";
        this.PdfDocumentViewer1.LoadFromFile(ds.Tables[0].Rows[0]["PDFFile"].ToString());

@skv90909090
Copy link

skv90909090 commented Oct 7, 2019 via email

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