I have read over the Webviewer Developer Guide and I am trying to create my own WebViewer from scratch using the instructions detailed on the "Using JavaScript with WebViewer" section of the Guide. I have followed the instructions and have made a number of attempts to display the WebViewer but nothing is working. I am using XAMPP and localhost is my server name. I have tried placing the jQuery in the head section of my HTML after the jQuery and WebViewer files and even after the "viewer" div. Neither attempts work. What am I doing incorrectly? I have the jQuery, WebViewer, and .xod files as the only files in my XAMPP htdocs folder. Please have a look at my code below...
<!DOCTYPE html>
<html>
<head>
<title>Viewer Test</title>
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="WebViewer.min.js"></script>
</head>
<body>
<div id="viewer"></div>
<script type="text/javascript">
$(function() {
var viewerElement = document.getElementById('viewer');
var myWebViewer = new PDFTron.WebViewer({
type: "html5,Silverlight,flash",
initialDoc: "GettingStarted.xod"
}, viewerElement);
});
</script>
</body>
</html>
Also, I would like to use the cloud service PDFTron provides to convert docs to .xod, but how can I connect my web application to your servers so users can upload their files and convert them via the cloud and then are able to view them in my application?
Thank you
var myWebViewer = new PDFTron.WebViewer({
type: "html5,Silverlight,flash",
initialDoc: "GettingStarted.xod",
path: "your/path/to/lib/folder"
}, viewerElement);
});
//Example of overriding the default link appearance and behavior
//==============================================================
me.docViewer.on('linkReady', function(e, linkElement, link){
if(link instanceof CoreControls.Hyperlink){
linkElement.onclick = function(){
//external link clicked
window.open(link.GetTarget());
};
}else if(link instanceof CoreControls.Link) {
linkElement.parentClick = linkElement.onclick;
linkElement.onclick = function(){
this.parentClick();
//override the default behavior of internal links
};
}
});
(function() {
"use strict";
$(document).bind("documentLoaded", function(event) {
window.custom = window.custom || {};
window.custom.links = [];
var textSelectedParent = Tools.TextSelectTool.prototype.textSelected;
Tools.TextSelectTool.prototype.textSelected = function(pageIndex, quads, text, me) {
textSelectedParent.call(this, pageIndex, quads, text, me);
window.custom.selectedQuads = {
pageIndex: pageIndex,
quads: quads
};
};
$("<button>").attr({
'id': 'optionsButton',
'class': 'ui-ele',
'type': 'button'
})
.text('Create Link')
.prependTo($("#control")).button({
}).click(function() {
if (window.custom.selectedQuads !== null) {
//var url = "http://google.com";
var url = prompt("Please enter the URL of the link", "http://google.com");
for (var i = 0; i < window.custom.selectedQuads.quads.length; i++) {
var q = window.custom.selectedQuads.quads[i];
window.custom.links.push({
pageIndex: window.custom.selectedQuads.pageIndex,
points: q.GetPoints(),
url: url
});
}
renderCustomLinks();
}
});
function renderCustomLinks() {
var docViewer = readerControl.getDocumentViewer();
var doc = docViewer.GetDocument();
var pageIndex = 0;
for (var i = 0; i < window.custom.links.length; i++) {
var points = window.custom.links[i].points;
var pageIndex = window.custom.links[i].pageIndex;
var url = window.custom.links[i].url;
var point1 = doc.GetPDFCoordinates(pageIndex, points.x1, points.y1);
var point2 = doc.GetPDFCoordinates(pageIndex, points.x3, points.y3);
var pageLinks = doc.GetLinks(pageIndex);
// creates an external link
var externalLink = new CoreControls.Hyperlink([point1.x, point1.y, point2.x, point2.y], url);
pageLinks.push(externalLink);
}
//workaround to force links to be re-created
readerControl.setZoomLevel(readerControl.getZoomLevel());
}
//=============================================
// Override the default behavior of links
//=============================================
var docViewer = readerControl.getDocumentViewer();
docViewer.on('linkReady', function(e, linkElement, link) {
if (link instanceof CoreControls.Hyperlink) {
linkElement.onclick = function() {
//external link clicked
window.open(link.GetTarget());
//handle your own logic here
};
}
});
});
})();
Yep works perfectly. I just commented out the tools I didn't need. Also my text underline tool is no longer working and I am not sure what I did. The image and code is proper in the annotation panel html file but when I click on the image the button doesn't work. Also I created an extra tab on the sidepanel of the webviewer and my customization works perfectly, but the problem is that when I switch to that tab, the page resets back to page one of the document. For example, if I am viewing and annotating page 10 of my document and I click on the new tab I created, the document resets back to page one instead of staying on page 10. How can I make it so where users click on my new tab and it doesn't reset the document being viewed to page one? These are my two issues, here is my code below for the new tab I created regarding my second issue...
$("<li style='height: 27px; width: 38px;'>").attr({
'id': 'thread',
'class' : '.ui-icon ui-icon-thread',
'type': 'button'
})
.text('Section')
.appendTo($(".ui-tabs-nav")).button({
text: false,
icons: {
primary: "ui-icon ui-icon-custom-comment"
}
}).click(function(){
$("#viewer").fadeToggle();
$("#thread").fadeToggle();
});
This is also a very small and minor issue and if it cannot be changed it is no problem, but is there a way to change the text that pops up on screen which displays "Annotations were successfully saved". I'd like to add my site name to this and possibly add my site's logo too.
--
You received this message because you are subscribed to the Google Groups "PDFTron WebViewer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdfnet-webview...@googlegroups.com.
To post to this group, send email to pdfnet-w...@googlegroups.com.
Visit this group at http://groups.google.com/group/pdfnet-webviewer.
For more options, visit https://groups.google.com/groups/opt_out.
Hi Jack,Okay I see what you mean.Instead of using fadeToggle, you can use the CSS visibility style to hide the viewer. This won't cause a jump to the first page.e.g....
}).click(function(){
if($("#viewer").css("visibility") === "hidden"){
$("#viewer").css("visibility", "visible");
}else{
$("#viewer").css("visibility", "hidden");
}
});
setInterval(function(){
var am = me.docViewer.GetAnnotationManager();
var clientAnnotData= am.GetAnnotCommand();
$.ajax({
url: serverurl
cache: false,
data : clientAnnotData,
success: function(data) {
//server returned some annotation commands
if (data !== null) {
am.ImportAnnotCommand(data);
}
},
error: function() {
//server gave an error
},
dataType: 'xml'
});
},3000); //execute this code every 3 seconds
...
updateAnnotations(){
//use the did to identify the document.
var query = '?did=' + this.doc_id;
if (this.doc_id === null) {
//Document id is not available. did will not be set for server-side annotation handling.
query = '';
}
//send a POST request (save annotations)
var xfdfString = am.ExportAnnotations();
$.ajax({
type: 'POST',
url: this.server_url + query,
data: {
'data': xfdfString
});
//send a GET request (to load annotations that may have been updated by others)
$.ajax({
url: this.server_url + query,
cache: false,
success: function(data) {
if (data !== null) {
am.ImportAnnotations(data);
}
},
dataType: 'xml'
});
}
For more options, visit https://groups.google.com/d/optout.
Hi Jack,