Query |
Details |
We have an ASPX page in place already that returns a PDF in binary format. Is there any way we can use this with the PDFViewer? Same for simple PDF pages that we already have a direct URL for
|
we can load the PDF document as the base64 string in the client side of the PDF viewer control. We have created a sample for loading the PDF document by base64 string in the client side (ASPX page) of the PDF viewer control ASP.NET. Kindly download the sample from the below link.
If the provided sample is different from your requirement, kindly provide us more specific details that illustrates your exact requirement. It will be helpful for us to analyze more on your requirement and could provide you the better solution.
|
Do you have any more information on how to handle things such as filenames, etc in the web service? |
Are you need to get the PDF document file name in the client side or server side of the PDF viewer control? Can you please provide more details about this query? So that we can analyze and provide, the more details about this query. |
What i would like to be able to do is to simply load a PDF file from a static url like the following
http:\\myserver.com\myfolder\mydcoument.pdf
or from a url like this
http:\\myserver.com\myfolder\getmydocumen.aspx
both these return a binary file with a mime type of application/PDF
public object DocumentLoad(Dictionary<string, string> jsonResult)
{
string staticurl =“ http:\\myserver.com\myfolder\mydcoument.pdf” ;
string filename = “pdfDownlaoded.pdf”;
using (WebClient client = new WebClient())
{
client.DownloadFile(staticurl + path + "\\" + filename);
}
}
|
i would like to download a PDF from a static URL but without having to write an intermediate web service to do so.
seems overkill to have to write a web service to just display a static PDF file
var staticUrl= , http:\\myserver.com\myfolder\mydcoument.pdf;
var xhr = new XMLHttpRequest();
xhr.open('GET', staticUrl ,true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status == 200) {
var myBlob = this.response;
var reader = new window.FileReader();
reader.readAsDataURL(myBlob);
reader.onloadend = function () {
base64data = reader.result;
$('#<%= PdfViewer1.ClientID %>').css("visibility", "visible");
var pdfviewerObject = $('#<%= PdfViewer1.ClientID %>').data('ejPdfViewer');
pdfviewerObject.load(base64data);
}
}
};
xhr.send(); |
thanks for the example but i cannot get it to work
it downloads the PDF properly but after calling load nothing displays in the PDF control
i am attaching a simple static HTML file that doesnt need any of the server side parts
function buttonClick() {
$("#PdfViewer1").ejPdfViewer({});
var viewer = $("#PdfViewer1").data("ejPdfViewer");
viewer.model.serviceUrl="../api/PdfViewer/"; //Serviceurl required to parsing and rendering the document in PDF viewer control.
var staticUrl = 'https://www.tutorialspoint.com/w3css/w3css_tutorial.pdf';
var xhr = new XMLHttpRequest();
xhr.open('GET', staticUrl, true);
xhr.responseType = 'blob';
xhr.onload = function (e) {
if (this.status == 200) {
var myBlob = this.response;
var reader = new window.FileReader();
reader.readAsDataURL(myBlob);
reader.onloadend = function () {
base64data = reader.result;
viewer.load(base64data);
}
}
};
xhr.send();
} |
not quite sure why it would call and even more so require a server function to display a PDF file from a static location
as i see this right now if i try to display a PDF file on the client it automatically tries to call an upload function on the server to upload the document
Why would it do that?
Ok i got this to work now but i am running into one issue
we will be showing different PDF files dynamically
I noticed that the control immediately calls the Load function to load a PDF file. At that point we may not know yet what file to display until we load it later
i cant seem to figure out how to make this work. If the initial call to load fails the PDF viewer doesnt work well afterwards
We have a web page that shows the user a list of documents to view. Until the user selects a document we have nothing to show. Once the user selects a document we load it into the PDF control.
Problem is that the PDFViewer immediately calls the web services load function when it is instantiated. At that time we don't know yet which document the user will select
Also it would be good to be able to 'clear' the PDFviewer so no document is shown any longer
public object Load(Dictionary<string, string> jsonResult)
{
PdfViewerHelper helper = new PdfViewerHelper();
if (jsonResult.ContainsKey("newFileName"))
{
var name = jsonResult["newFileName"];
var pdfName = name.ToString() + ".pdf";
helper.Load(HttpContext.Current.Server.MapPath("~/Data/" + pdfName));
}
else
{
if (jsonResult.ContainsKey("isInitialLoading"))
{
if (jsonResult.ContainsKey("file"))
{
var name = jsonResult["file"];
var pdfName = name.ToString();
helper.Load((pdfName));
}
else
{
helper.Load("");//PDF is passed as empty string.
}
}
}
string output = JsonConvert.SerializeObject(helper.ProcessPdf(jsonResult));
return output;
} |