loading the PDF file dynamically and displaying on browser

1.8k Views Asked by At

I want to load the PDF file on browser dynamically without giving the PDF filename as shown in below html code as in my case the PDF is generated with timestamp when ever user requests. html code:

<object data="/views/files/pdf/spreadDetails.pdf" type="application/pdf" width="100%" height="100%">
<iframe src="/views/files/pdf/spreadDetails.pdf" width="100%" height="100%" style="border: none;">
     This browser does not support PDFs.
 <a href="/views/files/pdf/spreadDetails.pdf">Download PDF</a>
 </iframe>
 </object>

The above html code displays the spreadDetails.pdf in the browser. I have a java code which dynamically creates a PDF file and it names the pdf file along with the timestamp when the user has clicked on the Gerate PDF button. (example : The PDF filename is as spreadDetails07132017113357AM.pdf(filename with date and time)). My requirement is how can i load the PDF file and show on browser because the above html code only works when the filename is correctly given but in my case i cannot give the filename as the pdf file is generated when ever the user requested by clicking on the button and as soon as it generates i have to load and show on the browser. Any suggestions would be helpful.

I have checked the below links but unable to get how to load the pdf files when generated dynamically with timestamp.

http://www.dynamicdrive.com/forums/showthread.php?47346-Changing-lt-object-gt-tag-element-s-data-property-dynamically

https://discoveringsharepoint.wordpress.com/2014/09/18/embedding-a-pdf-file-dynamically-on-a-web-page/

In both the above links, the PDF file name is constant but in my case its dynamic.

1

There are 1 best solutions below

3
On

Provide <.. Id = ""> to the <object>, <iframe>, <a> and manipulate the data, source and href values and set the name you used during generatepdf (are you able to get the name used for pdf creation?). That should fix the issue.