I have web-app that contain java-script that load pdf to html object tag :
when the user press a button I perform java-script code that close the pdf opened in the main window and then open it in the new window.
this code sometimes fails , I think that is due to synchronization problems , when I refresh the new window (that failed) - it succeed to open the file.
the code from the main window :
Code: Select all
function open_file_not_allow_edit()
{
try {
var pdf = document.getElementById("documentAction:pdfPath");
var allowEdit = document.getElementById("documentAction:AllowEditPdfFlag");
var PDFView1 = document.getElementById("PDFView");
if(PDFView1==null)
{
PDFView1 = document.getElementById("documentAction:PDFView");
}
if(pdf!=null)
{
var val = pdf.value;
// registeration key (license for our Viewer AX SDK.) SetDevInfo(serial key ,developer code )
PDFView1.SetDevInfo("xxx","xxx");
PDFView1.OpenDocument(val, 0, 0, 0); // open the file
docID = PDFView1.Property("Documents.Active", 0);
if(allowEdit.value == "false" )
{
PDFView1.SetDocumentProperty(docID, "ReadOnly", "true", 0); // disables editing for specified document
}
}
}
catch (err) {
// alert('error in opening file');
// alert(err.message);
}
}
Code: Select all
window.onload = function(evt){
try {
var PDFView1 = document.getElementById("PDFView");
var pdf = document.getElementById("documentAction:pdfPath");
var val = pdf.value;
// registeration key (license for our Viewer AX SDK.) SetDevInfo(serial key ,developer code )
PDFView1.SetDevInfo("xxx","xxx");
PDFView1.OpenDocument(val, 0, 0, 0); // open the file
docID = PDFView1.Property("Documents.Active", 0);
PDFView1.SetDocumentProperty(docID, "ReadOnly", "false", 0); // disables editing for specified document
PDFView1.DoVerb("", "ExecuteCommand", "ToggleAllBars", 0, 0);
PDFView1.SetProperty("View.Bars[\"CommentAndMarkup\"].Visible", "true");// add comments toolbar
PDFView1.SetProperty("View.Bars[\"Menu\"].Visible", "true");// add Menu toolbar
PDFView1.SetProperty("View.Bars[\"RotateView\"].Visible", "true");// add RotateView toolbar
PDFView1.SetProperty("View.Bars[\"Standard\"].Visible", "true");// add Standard toolbar
PDFView1.SetProperty("View.Bars[\"Zoom\"].Visible", "true");// add Zoom toolbar
// enable keyboard shortcuts like : "Ctlr+c , Ctrl+v ..."
PDFView1.SetProperty("General.AllowAllAccelerators", "true");
}
catch (err) {
}
} // window.onload finish