Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsModPdf.cpp
Go to the documentation of this file.
1 #include <Wt/WApplication>
2 #include <Wt/WLogger>
3 #include <Wt/WText>
4 
5 #include <Logger/WsLogger.h>
6 
7 #include "WsModPdf.h"
8 
9 using namespace Wt;
10 
11 extern "C" {
12  void WsModPdfInit(void)
13  {
14  void* hndl = dlopen("libwt.so", RTLD_NOW | RTLD_GLOBAL);
15  if ( hndl == NULL ) {
16  LOG(ERROR) << "WsModPdf :: Cannot load libwt.so shared library! " << dlerror();
17  return;
18  }
19  }
20 }
21 
22 WsPdf::WsPdf(WContainerWidget* parent)
23  : WContainerWidget(parent)
24 { }
25 
27 { }
28 
29 void WsPdf::setDiffPath(const std::string& diffPath)
30 {
31  m_sDiffPath = diffPath;
32 }
33 
35 {
36  WContainerWidget::load();
37  setId("pdf");
38  resize(WLength(100, WLength::Percentage), WLength(100, WLength::Percentage));
39  setOverflow(WContainerWidget::OverflowAuto);
40  std::string p1 = Wt::WApplication::instance()->internalPath();
41  //std::string p = "/demo_site/about/wt.pdf";
42  std::string p(m_sDiffPath + p1);
43  if ( p.size() > 0 ) {
44  std::string javaScript = "\
45  PDFJS.workerSrc='" + WApplication::instance()->resourcesUrl() + "webpdf/pdf.js';\
46  PDFJS.getPdf('" + p + "', function getPdf(data) {\
47  var pdf = new PDFJS.PDFDoc(data);\
48  var page = pdf.getPage(1);\
49  var scale = 1.5;\
50  var canvas = document.getElementById('pdf');\
51  var context = canvas.getContext('2d');\
52  canvas.height = page.height * scale;\
53  canvas.width = page.width * scale;\
54  })";
55  WApplication::instance()->doJavaScript(javaScript);
56  }
57 }
58 
59 
60 
61 
62 
64  : WsModule()
65 {
66  // Add the required javascript file
67  WApplication::instance()->require(WApplication::instance()->resourcesUrl() + "webpdf/pdf.js");
68 }
69 
71 {
72 }
73 
74 WWidget* WsModPdf::createContentsMenuBar(WContainerWidget* parent) const
75 {
76  return 0;
77 }
78 
79 WWidget* WsModPdf::createContents(WContainerWidget* parent) const
80 {
81  WsPdf* pcw = new WsPdf(parent);
82  pcw->setDiffPath(diffPath());
83  pcw->setOptions(options());
84  return pcw;
85 }
86 
87 WsEditorWidget* WsModPdf::createEditor(WContainerWidget* parent) const
88 {
89  return 0;
90 }
91 
92 WWidget* WsModPdf::createAdmin(WContainerWidget* parent) const
93 {
94  return 0;
95 }
96 
98 {
99  return true;
100 }
101 
102 std::string WsModPdf::description() const
103 {
104  return "WsModPdf wittyShare module";
105 }
106 
const std::string & diffPath() const
Definition: WsOption.cpp:189
~WsModPdf()
Definition: WsModPdf.cpp:70
~WsPdf()
Definition: WsModPdf.cpp:26
virtual void load()
Definition: WsModPdf.cpp:34
WsModPdf()
Definition: WsModPdf.cpp:63
std::string m_sDiffPath
Definition: WsModPdf.h:25
const std::vector< WsOption > & options() const
Get all options.
Definition: WsOption.cpp:70
Wt::WWidget * createContents(Wt::WContainerWidget *parent=0) const
Create the contents.
Definition: WsModPdf.cpp:79
void setDiffPath(const std::string &diffPath)
Definition: WsModPdf.cpp:29
bool saveEditor() const
Definition: WsModPdf.cpp:97
Wt::WWidget * createContentsMenuBar(Wt::WContainerWidget *parent=0) const
Create the functionalities.
Definition: WsModPdf.cpp:74
#define LOG
Definition: WsLogger.h:22
Wt::WWidget * createAdmin(Wt::WContainerWidget *parent=0) const
Create the contents for an administrator.
Definition: WsModPdf.cpp:92
WsPdf(Wt::WContainerWidget *parent=0)
Definition: WsModPdf.cpp:22
WsEditorWidget * createEditor(Wt::WContainerWidget *parent=0) const
Create the contents for an editor (create a view of options).
Definition: WsModPdf.cpp:87
void WsModPdfInit(void)
Definition: WsModPdf.cpp:12
void setOptions(const std::vector< WsOption > &vOptions)
Set all options.
Definition: WsOption.cpp:57
Definition: WsModPdf.h:17
#define ERROR
Definition: WsLogger.h:42
std::string description() const
Return the description of the module.
Definition: WsModPdf.cpp:102