PDF-XChange editor and Response.BinaryWrite

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
cguanes
User
Posts: 4
Joined: Mon May 03, 2021 4:48 pm

PDF-XChange editor and Response.BinaryWrite

Post by cguanes »

We have an intranet system that display into a web browser PDF stored in SQL, this work perfect with Adobe Reader but recently a big number of users started using the PDF Xchange Editor and we noticed that the users with PDF Xchange editor when they click on the link to display the PDF inside the IE Browser is running the page_load twice, the first time with all the parameters to open the correct PDF and then again without any parameter.

The code to stream the pdf to the browse is simple:
We have the PDF Binary in a memorystream PDFStream


Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; filename=DOCPDF.pdf");
Response.AddHeader("content-length", PdfStream.Length.ToString());
Response.BinaryWrite(PdfStream.ToArray());
Response.Flush();
Response.End();


When Adobe reader, the page is finishing after the Response.End(), but for some reason when the client have PDF Xchange, the page_load start over after the Response.End().

Any idea what to do to be sure it only load one time?

Thank you.
cguanes
User
Posts: 4
Joined: Mon May 03, 2021 4:48 pm

Re: PDF-XChange editor and Response.BinaryWrite

Post by cguanes »

I tried this code .... same result

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "inline; filename=DOCPDF.pdf");
HttpContext.Current.Response.AddHeader("content-length", PdfStream.Length.ToString());
HttpContext.Current.Response.BinaryWrite(PdfStream.ToArray());
HttpContext.Current.Response.Flush(); // Sends all currently buffered output to the client.
HttpContext.Current.Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();


it will trigger again the page_load only when using PDF Xchange Editor viewer.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17812
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: PDF-XChange editor and Response.BinaryWrite

Post by Tracker Supp-Stefan »

Hello cguanes,

Could you please prepare a sample project that can illustrate the problem and send that to us along with any sample files necessary?

Kind regards,
Stefan
cguanes
User
Posts: 4
Joined: Mon May 03, 2021 4:48 pm

Re: PDF-XChange editor and Response.BinaryWrite

Post by cguanes »

attached to this you will find a small project example, just reading a pdf file into memorystream and writing to stream.

If you put a break point on the first line of Page_load, you will see the page_load is being called twice, that is not happening with Adobe reader.
Of course my original project is more complex including SQL updates and running twice is affecting the way that it should work.

You can try with this code using the response.end() or the other example posted before using HttpContext.Current.ApplicationInstance.CompleteRequest();
displaypdf.rar
(87.76 KiB) Downloaded 29 times
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: PDF-XChange editor and Response.BinaryWrite

Post by Vasyl-Tracker Dev Team »

Hi cguanes.

Thanks for your clear sample project - we reproduced the problem. At the moment we detected that the issue is caused by our Sharepoint-plugin for our PDF Editor. So, as temporary workaround - you may turn OFF this plugin here:
image.png
(IE > EmbeddedPdfEditor > File > Preferences, and restart the IE)

We will try to fix this trouble in the near future. Thanks for the detailed report.

Cheers.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: PDF-XChange editor and Response.BinaryWrite

Post by Vasyl-Tracker Dev Team »

There is another possibility to solve your problem. When the Editor trying to detect if it is talking with a Sharepoint server, it sends HTTP 'HEAD' request. But looks like your server app responds to the 'HEAD' request like as to regular 'GET' request sending all including response body again. So if you can detect HTTP verb and send only headers in case of 'HEAD' request, I guess it will solve the issue.

I just checked the Page_load::sender.Request.RequestType at second call:
image.png
- the RequestType=='HEAD' as expected...
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
cguanes
User
Posts: 4
Joined: Mon May 03, 2021 4:48 pm

Re: PDF-XChange editor and Response.BinaryWrite

Post by cguanes »

I will try this
User avatar
Radi - Tracker Supp
Site Admin
Posts: 597
Joined: Tue Mar 03, 2015 12:46 pm

PDF-XChange editor and Response.BinaryWrite

Post by Radi - Tracker Supp »

:)
Post Reply