This product is retired as of September 2020 See PDFTon WebView
===
Often it is desirable to pre-load PDF files to the Reader Plus database and have them ready for viewing before a user attempts to load them. This is easily done with the System.Net.WebClient class and ReadPlus REST calls.
string fileName = "your.pdf";
MyWebclient rpclient = new MyWebclient();
rpclient.Timeout = 180000;
string pdfData = Convert.ToBase64String(File.ReadAllBytes(file));
var resultString = rpclient.UploadString($"http://localhost:62625/api/readerplus/uploadDocument?sIsMasterDocument=1&sEditMode=1&ExistingDocumentID=&DefaultOutputName={fileName}&UserPassword=", pdfData);
dynamic result = JsonConvert.DeserializeObject(resultString);
The WebClient has a default time limit of 100 seconds. Particularly large documents may not complete uploading in that amount of time. You need a way to edit the WebRequest timeout, giving the upload time to finish. The WebClient class does not allow you to modify the default time limit, to do this you need a custom class that inherits from WebClient and overrides the GetWebRequest function.
namespace MyWebClientNamespace
{
class MyWebclient : WebClient
{
// The WebRequest timeout in milliseconds.
public int Timeout = 100;
protected override WebRequest GetWebRequest(Uri uri)
{
WebRequest w = base.GetWebRequest(uri);
w.Timeout = 20 * 60 * 1000; // Set your timeout value
return w;
}
}
}
Now you can set the timeout for each REST call if needed.
Comments
0 comments
Please sign in to leave a comment.