From version < 2.1 >
edited by Julien Fleury
on 2020/12/16 04:36
To version 1.1 >
edited by Julien Fleury
on 2020/12/16 04:26
>
Change comment: Install extension [com.xwiki.pdfviewer:macro-pdfviewer-ui/2.1.1]

Summary

Details

Page properties
Content
... ... @@ -1,4 +4,1 @@
1 -
2 -Sample PDF Viewer
3 -
4 4  {{pdfviewer file="pdftest.pdf" /}}
pdfviewer.zip
Size
... ... @@ -1,1 +1,1 @@
1 -2.5 MB
1 +3.7 MB
Content
XWiki.WikiMacroClass[0]
Macro code
... ... @@ -1,25 +1,140 @@
1 +{{include reference="Licenses.Code.VelocityMacros"/}}
2 +
3 +{{velocity output="false"}}
4 +#macro (getUrlFromFile $file)
5 + #set ($url = $NULL)
6 + #if ($file.startsWith('http://') || $file.startsWith('https://'))
7 + #set ($url = $file)
8 + #else
9 + #if ("$!docname" != '')
10 + #set ($document = $xwiki.getDocument($docname))
11 + #else
12 + #set ($document = $doc)
13 + #end
14 + #set ($attachment = $document.getAttachment($file))
15 + #set ($url = $NULL)
16 + #if ($attachment)
17 + #set ($url = $document.getAttachmentURL($file))
18 + #elseif ($asAuthor && $xwiki.hasProgrammingRights() && $xwiki.exists('XWiki.PDFViewerService'))
19 + #set ($document = $xwiki.getDocumentAsAuthor($docname))
20 + #set ($attachment = $document.getAttachment($file))
21 + #if( $attachment)
22 + #set ($digestFactory = $services.component.getInstance('org.xwiki.crypto.DigestFactory', 'SHA-1'))
23 + #set ($encoder = $services.component.getInstance('org.xwiki.crypto.BinaryStringEncoder', 'URLBase64'))
24 + #if ($digestFactory && $encoder)
25 + #set ($contentAuthor = $services.model.serialize($doc.contentAuthorReference, 'default'))
26 + #set ($digest = $digestFactory.instance)
27 + #set ($is = $digest.getInputStream($attachment.contentInputStream))
28 + #set ($discard = $digest.getInputStream($attachment.contentInputStream).skip(1000))
29 + #set ($discard = $is.close())
30 + #if ($xcontext.userReference)
31 + #set ($discard = $digest.update($services.model.serialize($xcontext.userReference, 'default').getBytes('UTF-8')))
32 + #end
33 + #set ($discard = $digest.update($contentAuthor.getBytes('UTF-8')))
34 + #set ($digest = $encoder.encode($digest.digest))
35 + #set ($queryString = $escapetool.url({'reference': $services.model.serialize($document.documentReference, 'default'),
36 + 'filename': $attachment.filename,
37 + 'user': $contentAuthor,
38 + 'key': $digest}))
39 + #set ($url = $xwiki.getDocument('XWiki.PDFViewerService').getExternalURL('get', $queryString))
40 + #end
41 + #end
42 + #end
43 + #end
44 +#end
45 +
46 +#macro(displayFile $file)
47 + #getUrlFromFile($file)
48 + #if ($url)
49 + #set ($pdfViewerConfigDoc = $xwiki.getDocument('PDFViewer.Code.PDFViewerConfiguration'))
50 + #set ($trustedOrigins = $pdfViewerConfigDoc.getValue('trustedOrigins'))
51 + #set ($withCredentials = $pdfViewerConfigDoc.getValue('withCredentials'))
52 + #set ($trustedOrigins = $stringtool.join($trustedOrigins.split('\r\n'), ','))
53 + #set ($queryString = $escapetool.url({
54 + 'file': $url,
55 + 'trustedOrigins': $trustedOrigins,
56 + 'withCredentials': $withCredentials
57 + }))
58 + #set ($pdfviewerurl = $xwiki.getDocument('XWiki.PDFViewerMacro').getAttachmentURL('pdfviewer.zip'))
59 + ## Attachment URL have query parameters for cache issue.
60 + #set ($pdfviewerurl = $pdfviewerurl.split('\?')[0])
61 + {{html clean=false}}
62 + <div>
63 + <!--[if lt IE 10]>
64 + <div class="box warningmessage">PDF Viewer : Not compatible with IE < 10</div>
65 + <![endif]-->
66 + <![if !(lt IE 10)]>
67 + <iframe src="${pdfviewerurl}/pdf-viewer/web/viewer.html?${queryString}#locale=${xcontext.locale}" width="${width}" height="${height}"></iframe>
68 + <![endif]-->
69 + </div>
70 + {{/html}}
71 + #elseif (!$document || $document.isNew())
72 + {{error}}$services.localization.render('pdfviewer.error.nodocument', [$escapetool.html($escapetool.html($docname))]){{/error}}
73 + #else
74 + {{error}}$services.localization.render('pdfviewer.error.noattachment', [$escapetool.html($file), $escapetool.html($services.model.serialize($document.documentReference, 'default'))]){{/error}}
75 + #end
76 +#end
77 +
78 +#macro(isActive)
79 + #set ($activeClass = $NULL)
80 + #set ($isActive = $request.file == $file)
81 + #if ("$!request.file" == '')
82 + #set ($isActive = $foreach.index == 0)
83 + #end
84 +#end
85 +{{/velocity}}
86 +
1 1  {{velocity}}
2 -#set($width = $context.macro.params.width)
3 -#set($height = $context.macro.params.height)
4 -#set($file = $context.macro.params.file)
5 -#if(!$file)
6 -No pdf URL provided
88 +#set ($mainPageReference = $services.model.createDocumentReference('', ['XWiki'], 'PDFViewerService'))
89 +#if (!$services.licensing.licensor.hasLicensureForEntity($mainPageReference))
90 + {{error}}#getMissingLicenseMessage('pdfviewer.extension.name'){{/error}}
7 7  #else
8 -#if($file.startsWith("http"))
9 - #set($url = $file)
10 -#else
11 - #set($url = $doc.getAttachmentURL($file))
92 + #set ($width = $xcontext.macro.params.width)
93 + #set ($height = $xcontext.macro.params.height)
94 + #set ($fileParam = $xcontext.macro.params.file)
95 + #set ($docname = $xcontext.macro.params.document)
96 + #set ($asAuthor = $xcontext.macro.params.asauthor && ($xcontext.macro.params.asauthor == 'true' || $xcontext.macro.params.asauthor == 'yes' || $xcontext.macro.params.asauthor == '1'))
97 + #if (!$fileParam)
98 + {{error}}$services.localization.render('pdfviewer.error.nofile'){{/error}}
99 + #else
100 + #set ($files = $fileParam.split(','))
101 + #if ($files.size() == 1)
102 + #displayFile($files[0])
103 + #else
104 + ## Display each PDF file in its own tab, in the page content.
105 + ##===========
106 + ## Display the Tabs
107 + ##===========
108 + {{html clean="false"}}
109 + <div class="floatcontainer">
110 + <ul class="xwikitabbar">
111 + #foreach ($file in $files)
112 + #isActive
113 + #if ($isActive)
114 + #set ($activeClass = "class='active'")
115 + #end
116 + <li id="$escapetool.xml($file)" $activeClass>
117 + <a href="$doc.getURL('view', "file=$escapetool.url($file)")">$file</a>
118 + </li>
119 + #end
120 + </ul>
121 + </div>
122 + {{/html}}
123 + ##==========================
124 + ## Include the Tab data for the selected Tab
125 + ##==========================
126 + {{html clean="false" wiki="true"}}
127 + <div class='xwikitabpanescontainer'>
128 + #foreach ($file in $files)
129 + #isActive
130 + #if ($isActive)
131 + #displayFile($file)
132 + #break
133 + #end
134 + #end
135 + </div>
136 + {{/html}}
137 + #end
138 + #end
12 12  #end
13 -#set($url = $escapetool.url($url))
14 -#set($pdfviewerurl = $xwiki.getDocument("XWiki.PDFViewerMacro").getAttachmentURL("pdfviewer.zip"))
15 -{{html clean=false}}
16 - <!--[if lt IE 10]>
17 - <div class="box warningmessage">PDF Viewer : Not compatible with IE < 10</div>
18 - <![endif]-->
19 - <![if !(lt IE 10)]>
20 - <iframe src="${pdfviewerurl}/pdf-viewer/web/viewer.html?file=${url}#locale=${context.language}" width="${width}" height="${height}"&></iframe>
21 - <![endif]-->
22 - </script>
23 -{{/html}}
24 -#end
25 25  {{/velocity}}
XWiki.WikiMacroParameterClass[1]
Parameter default value
... ... @@ -1,1 +1,0 @@
1 -100%
Parameter description
... ... @@ -1,0 +1,1 @@
1 +Reference of the document containing the file (not used if file is a URL)
Parameter name
... ... @@ -1,1 +1,1 @@
1 -width
1 +document
XWiki.WikiMacroParameterClass[2]
Parameter default value
... ... @@ -1,1 +1,1 @@
1 -1000
1 +100%
Parameter name
... ... @@ -1,1 +1,1 @@
1 -height
1 +width
XWiki.WikiMacroParameterClass[3]
Parameter default value
... ... @@ -1,0 +1,1 @@
1 +1000
Parameter name
... ... @@ -1,0 +1,1 @@
1 +height
XWiki.WikiMacroParameterClass[4]
Parameter default value
... ... @@ -1,0 +1,1 @@
1 +0
Parameter description
... ... @@ -1,0 +1,1 @@
1 +If this value is true (or 1 or yes) and the user has no access to the document to which the PDF file is attached, the PDF file could still be viewed on behalf of the author of the document containing the macro (if that author has access to the containing document obviously).
Parameter name
... ... @@ -1,0 +1,1 @@
1 +asauthor
This wiki is hosted and managed by iXPath
Powered by XWiki 13.3 debian