how to get pdfJS to render a pdf from URL? - javascript

i am using PDFJS to render PDFs files using their URL after scanning the current page a js snipet return the urls. then it passes them to pdfJS. until now everything works the problem show when the PDF is already open in the browser . i take the URL (*.pdf) and pass it the same way as before the difference is that the file is not downloaded and i have this response.
Warning: Unhandled rejection: Unexpected server response (0) while retrieving PDF "http://geekographie.maieul.net/IMG/pdf/progit.fr.pdf".
(just for the record i dont have CORS issues).

Try this "http://mozilla.github.io/pdf.js/"
Installation
download and unzip file.
put "PDF" file in this folder.
config in "viwer.js", edit var DEFAULT_URL.
upload folder to server.
Have fun!

Related

External files with Content-type application/vnd.ms-excel

I am trying to download a .xls when I click a button on my website for this it is loading another page with
header("Content-type: application/vnd.ms-excel");
in the php file
I am also using certain libraries to generate the text that is to be presented in the xls file
echo "<script src = '.....'></script>"
When I remove the header part then the data is presented correctly in the browser
but with the header I sometimes get the error "missing files <relative path added to my Downloads folder>",
but the text is never present in the xls file which I am generating using the external javascript files
I believe when downloading they make the downloads folder the root and want all the external files to be present on my computer instead of the server
How can I work around this?
Thank you

Pdfmake Uncaught invalid image error even with correctly url

When I try to download PDF file with image generated by pdfmake I got:
Uncaught invalid image, images dictionary should contain dataURL entries (or local file paths in node.js)
I have visited playground on their website but I got there the same error.
Here I paste the example url to image generated by my server. It works fine as you can see (paste it to the browser url).
Finally I posted code:
pdfMake.createPdf({
content:[{image: 'url from paste bin here'}]
}).download();
Honestly I have ran out of ideas.
You can include local JPGs and PNGs from your filesystem if you put them in the ./images folder from the pdfmake root. Then they will be referenced as "./images/filename.jpg" (or .png as the case may be). [EDIT: Also, images won't load above a certain filesize in preview. They will still work on server side rendering. I had a 4.7 MB PNG that would render just fine server side but no matter what, can't get it to render on the client. So just be sure to be using small images if you want to use the dev playground clientside preview feature.)

Downloading File After Renaming Using HTML Or JavaScript

I want to download file from external server but after renaming it. Let's say http://playtictactoe.atwebpages.com/logo.png is an image file I want to download. I have used the following HTML:
<a href="http://playtictactoe.atwebpages.com/logo.png" download="myName.png">
Download File
</a>
But this doesn't rename the file. I've read somewhere that this is because of Response Header on server. Is there any way to ignore Response Header on client side? Else guide me any other solution.
You can download the file as a buffer and resave with the file api like descriped here:
HTML5 File API downloading file from server and saving it in sandbox
Or lookup FileAPI and XMLRequest to Buffer. You download the file as binaryBuffer save it with fileAPI and rename it. This should also work in Firefox. But this is not the simple solution you are searching for. Even though it works ;-)
You can then rename the file like you want.
Cheers

JavaScript googlemaps read coordinates from file

I want to display some markers using googlemaps. The information (coordinates) are stored in a local *.csv file (wich I want to use a "ressource-file").
How can I read this *.csv file? If I use "jQuery.get('myFile.csv', function (data) {..." it dosn't work.
The error message is: Cross origin requests are only supported for protocol schemes
Do I hava to make a file selection to read the file? Is there no other way?
Thanks
Is it possible that you are trying to load data from a file and not a running server(for example by double-clicking the .html from your file manager)?
If your are on the file:// protocol (which you can see in your url) this will not work. You could try changing to the development directory and runnig python3 -m http.server which will start a small development server. You can than change to http://localhost:8000 and see if it works.

JSZip unzipping error

Trying to handle with JSZip library.
I am having an issue to unzip a file. Here's a plunker demo. As you can see I can successfully zip a content, but when I try to unzip a zipped content I get an error (can be seen in console):
Uncaught Error: Corrupted zip : can't find end of central directory
Any ideas why this happens?
In any case, here's what I am trying to achieve: I have an textarea on my page. Upon click I want to zip textarea content and send zipped data to server. Another call must be able to receive a zipped data, unzip it and replace textarea text with unzipped one. Everything works ok, except unzipping problem.
The generateAsync() method defaults to a base64 output but the loadAsync() method only see a string.
You have two solutions :
change the generated format with `generateAsync({type:"uint8array"}) (see here)
or tell the load method that you are loading base64 content : loadAsync(data,{base64:true}) (see here)
As answered by David has resolved my problem on my local workstation running Windows 10 OS. However it is failed on the Server running RHEL OS.
I have to fix it by switching to yauzl package for unzipping. It is recommended as mention on package's official repository, with specified merge pull 383.

Categories

Resources