Render pdf with Rails - javascript

In my project, I want to somehow display a pdf file on the page. For this, I am trying to use the <object> tag. So far, so good, since the pdf lives in the /public folder in my Rails app.
The problem is that now I want the user to be able to display a pdf that is on his pc. I tried using Javascript to alter the <object> tag, but that does not work since Rails generates a new GET request to get the file, and the file is not on the server. Any ideas of how I can solve this?
I have tried using PDF.js, but it does not integrate well in the assets pipeline. Also, I would have to customize and hack the code to add some other functionalities, so PDF.js is kinda off the table (at least for now).

You can use the wicked_pdf gem to generate pdf then use Google PDF viewer for displaying it

Related

Generating a PDF from a HTML page that holds d3js graphs

I'm working on a solution that shows different graphs on a webpage using d3js to draw them. We're now trying to generate a PDF file from the report but can't find a solution that works using our graphs. Is there anyone that has experience with a similar problem and knows a library we can use?
We've been trying these and some others but all have failed to work properly so far:
PhantomJs (Doesn't seem to work in Azure)
JsPdf (Stylesheets are not shown properly)
Rotativa (Best so far but still didn't always work properly)
Thanks,
Mark
As this was a application installed on a server, we ended up creating a service that's using CEFsharp to capture the page as a PDF.
Using MSMQ we send a PDF capture request to the service, the service captures the PDF and returns the result through MSMQ. The user will get a notification in the web application that the PDF is ready to be downloaded.
Might not be the solution we hoped for, but an advantage is that users can also schedule PDF's as the service is always running.

Can Fine-Uploader Parse PDF Pages into Thumbnail Images

I am working on a website that has a need for a file uploader that integrates well with forms and potentially S3. Fine-uploader looks like a great fit for us. We will be, however, adding a PDF splitter/merger so users can drop one or more PDF files and pull specific pages out and send them as one document. I may need to find a separate JS library to render the PDF pages as image/thumbnails for interaction, but wondering/hoping fine-uploader could handle the page thumbnail rendering similarly to how it does so for image file, but giving a thumbnail for each PDF page.
Fine Uploader does not natively preview PDFs. If you'd like to generate previews for PDFs client-side, consider using a library specifically for that purpose. One possible choice is pdf.js. You can use Fine Uploader's API to get a handle on the PDF file (uploader.getFile(id)) and then pass this file off to pdf.js. Note that you may have to convert this file into a typed array first using FileReader.

Use PDF.js offline

Is it possible to use PDF.js without having the website online? I'm trying to do a simple offline website that reads pdf using pdf.js but it won't work without being online.
Anyone could help?
Yes absolutely you can use it offline. Download the latest version here.
Now extract the zip file and put it on a server(use xampp/wamp/lamp or any other localhost) because the worker is not enabled for file:// urls.
To show the pdf files traverse to web/viewer.html from the localhost and it should load its default pdf.
As to the question about how to show your pdf's use: viewer.html?file=relative/path/to/your/pdf
Say for example inside the web folder(the one in which viewer.html is there) of your pdf.js you create a directory say named pdfFiles and in it you add a pdf named say mypdf.pdf in it then to display it use: viewer.html?file=pdfFiles/mypdf.pdf and it will display it.
Look here for more details on how to dynamically assign PDF file paths to the viewer. If you have any other queries let me know. I have used pdf.js offline and it works wonderfully on almost all the browsers I know.

linking html web page to text editor to practice

I'm trying to link this page http://www.bauer.uh.edu/parks/f1471m.htm to my text editor ( text mate) with a mac.
I even copied the code and pasted it into an HTML file, and made a .js file (the one I'm trying to use to practice with) in the same folder and to use the local tag with no success.
I tried using src="http://www.bauer.uh.edu/parks/f1471m.htm" with no luck.
am I doing something wrong?
I'm making a few assumptions here...
From what you're describing, I think you're trying to directly edit the file. Unless you have write access on that server, what you're doing isn't going to work. Some web development software will allow you to do this, but most text editors don't.
Can you work on the file locally (on your computer's file system) and upload it to the server through FTP?
Many browsers give you the ability to save a page locally these days. That would set up the proper structure for you on your own machine. (FireFox can do this using Save Page)

Play framework external dynamic HTML handling

I'm developing a web application on a Play framework 2.2.0 (Scala). The application is generally taking some input from the user, and then calls external module which in turn processes the input and generates html report. The report has a rather complex structure with html, javascript and json data, all put into different files. Then I wish to be able to render this report to the user by the Play framework, without him having to download report in an archive.
I tried to put these report files to some directory in the assets, and Redirect, but this won't work in production. Then I tried to use Ok.sendFile inline, but since content depends on other files the report does not render correctly.
I wonder if there is any "intended" way to render such dynamically generated HTML to the user?

Categories