-
Notifications
You must be signed in to change notification settings - Fork 85
allowed for data URIs in the src of the pdf viewer for dynamic pdf viewing #15
base: develop
Are you sure you want to change the base?
Conversation
ha, I was just about to implement this myself. Thanks a lot! |
@akrennmair this pull request is very good, I think it will make quite a few people happy. I am trying to test this one out in development right now. |
…erlapping the way it was fixed in arlimus/angularjs-pdf@ea02de6
…into develop Conflicts: ng-pdfviewer.js
…the pdf in those cases, but only scaling the currently drawn image. rerendering is done once at the end of a possible drag-and-drop rescaling operation of the viewer.
I am getting raw pdf data from the $http (angular service) as a string. I wanted to know how may I use this code to modify the src of the viewer according to my input pdf data. Any ideas? |
Any changes for @grane22 problem? I'm in the same condition and I don't know how to.. |
@marchrius You should try looking at this post. http://stackoverflow.com/questions/33287993/rendering-raw-pdf-data-from-web-service-using-pdf-js-specify-src-in-angular-io. I found the comment useful. So instead of getting the data as dataURI, I am getting the data from the server as arraybuffer by setting the response type like this. Then i just convert the response data to Uint8Array by doing this You can use this uInt8Array in pdf.js as follows: PDFJS.getDocument({data: uInt8Array}).then(function(pdf){ Let me know if you need any help on this! |
@grane22 Thanks very much! I'm stuck at I need to use it in ng-pdfviewer and not in pdf.js. |
@marchrius I am trying to figure that out too. It shouldn't be that hard i guess. I will let you know once this works in ng-pdfviewer |
Hi @grane22 thanks. I'm forking this repo to apply my actual mod. |
hi there! @grane22 and @marchrius: i'm not sure what the problem is. what's wrong with something like this:
in case this works for you guys i can suggest a patch that will allow this method, the dataURI, and the original path version to work simultaneously. |
@michaschwab the problem (my problem) is: <pdfviewer data-base64="{{base64encoded}}" on-page-load="pageLoaded(page,total)"
id="pdfViewer" load-progress="loadProgress(loaded, total, state)"
class="ng-isolate-scope"></pdfviewer> This becouse the downloads is made by DocumentViewer (and this is correct IMHO) and the redering by the ng-pdfviewer.. Also, this PDFJS.getDocument({data: uInt8Array}, null, null, $scope.documentProgress)
.then(function(_pdfDoc) { ... is the same as (in terms of final results) to this PDFJS.getDocument(uInt8Array)
.then(function(_pdfDoc) { ... becouse the file is immediately loaded. |
Thanks, that was pretty clear! But I still don't see the problem, even though I know what you're trying to do. |
…nged by less than a pixel, and the canvas size setting uses the image data that is already available if it was not re-rendered since the last resize.
hey guys , do I need to repleace the code from the ng-pdfviewer with this code ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please merge this, its working perfectly fine.
Hi @grane22 ,
**controller;**
var module = angular.module ("myModule", []);
}); When I lift the server it only paints me the pdfjs-viewer viewer without the data but if I refresh the screen by pressing F5 it works for me. |
Sorry, the html code
controller;
|
@juanmacaballeror Are you getting the raw PDF data from an HTTP request or are you hardcoding it? It is strictly advisable to get it from the server as base64 response and pass it directly as in this library example https://github.com/legalthings/angular-pdfjs-viewer#data In your code you just have to change this
to
Notice no moustache brackets while referencing the scope var in |
Hello
Gaurav Rane,
First of all thank you very much for answering after so long.
The base64 code in this example I have copied for a test but for my
project I will get it through a service that will return the value in
BASE64 so what I understand that I can not use the service $ http.get
because the response
$ http.get ("http://example.com/file.pdf", {
responseType: 'arraybuffer'
}). then (function (response) {
$ scope.data = new Uint8Array (response.data);
});
Is that so?
what I do not understand, is that as I have the code, it does not
render the pdf when I start the server but if I press f5 it already
renders the pdf.
You can see my project in;https://gitlab.com/JuanmaCaballero/pdfJsViewer.git
Without calling the service $ http.get you can not render the pdf ??
Thank you very much again and if you need anything from Madrid
(Spain), do not hesitate ...
a greeting
El mar., 24 jul. 2018 a las 19:58, Gaurav Rane (<[email protected]>)
escribió:
… @juanmacaballeror <https://github.com/juanmacaballeror> Are you getting
the raw PDF data from an HTTP request or are you hardcoding it? It is
strictly advisable to get it from the server as base64 response and pass it
directly as in this library example
https://github.com/legalthings/angular-pdfjs-viewer#data
In your code you just have to change this
<pdfjs-viewer data="{{prueba}}" download="false" print="false">
</pdfjs-viewer>
to
<pdfjs-viewer data="prueba" download="false" print="false">
</pdfjs-viewer>
*Notice no moustache brackets while referencing the scope var in data prop*
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#15 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AJmLAMYPx5YovvEGbZjnqxZRm0AYz4VIks5uJ2AxgaJpZM4Ctstw>
.
|
with this patch, it's possible to use ng-pdfviewer interactively by changing the source of the dom element to different data uris. we can use the dom element like this:
and then feed the data uri into pdfContent. that even allows to use a user selected pdf file to be displayed immediately, using html5 filereader:
with