-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a51e8de
commit 905b5ba
Showing
10 changed files
with
786 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace diecoding\pdfjs; | ||
|
||
use yii\helpers\ArrayHelper; | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @author Die Coding (Sugeng Sulistiyawan) <[email protected]> | ||
* @copyright 2020 Die Coding | ||
* @license MIT | ||
* @link https://www.diecoding.com | ||
* @version 1.0.0 | ||
*/ | ||
class Module extends \yii\base\Module | ||
{ | ||
/** | ||
* | ||
* @var array $buttons | ||
*/ | ||
public $buttons = []; | ||
|
||
/** | ||
* | ||
* @var array $waterMark | ||
*/ | ||
public $waterMark = []; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public $controllerNamespace = 'diecoding\pdfjs\controllers'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
|
||
$waterMarkDefault = [ | ||
'text' => '', | ||
'alpha' => '0.5', | ||
'color' => 'red' | ||
]; | ||
|
||
if (!empty($this->waterMark)) { | ||
$this->waterMark = ArrayHelper::merge($waterMarkDefault, $this->waterMark); | ||
} else { | ||
$this->waterMark = $waterMarkDefault; | ||
} | ||
|
||
$this->buttons = ArrayHelper::merge([ | ||
'presentationMode' => true, | ||
'openFile' => true, | ||
'print' => true, | ||
'download' => true, | ||
'viewBookmark' => true, | ||
'secondaryToolbarToggle' => true, | ||
], $this->buttons); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace diecoding\pdfjs; | ||
|
||
use Yii; | ||
use yii\helpers\Html; | ||
use yii\helpers\Url; | ||
use yii\helpers\ArrayHelper; | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @author Die Coding (Sugeng Sulistiyawan) <[email protected]> | ||
* @copyright 2020 Die Coding | ||
* @license MIT | ||
* @link https://www.diecoding.com | ||
* @version 1.0.0 | ||
*/ | ||
class PdfJs extends \yii\base\Widget | ||
{ | ||
/** | ||
* | ||
* @var string $url | ||
*/ | ||
public $url; | ||
|
||
/** | ||
* | ||
* @var array $options | ||
*/ | ||
public $options = []; | ||
|
||
/** | ||
* | ||
* @var array $buttons | ||
*/ | ||
public $buttons = []; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
$this->view->registerAssetBundle(PdfJsAsset::className()); | ||
|
||
$module = new Module(); | ||
$buttons = $module->buttons; | ||
$this->buttons = ArrayHelper::merge($buttons, $this->buttons); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function run() | ||
{ | ||
if (!array_key_exists('style', $this->options)) { | ||
$this->options['style'] = 'border:solid 2px #404040; width:' . $this->width . '; height:' . $this->height . ';'; | ||
} | ||
|
||
return $this->render('viewer', [ | ||
'options' => $this->options, | ||
'url' => $this->url, | ||
'buttons' => $this->buttons, | ||
'id' => $this->id | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace diecoding\pdfjs; | ||
|
||
use yii\web\AssetBundle; | ||
use yii\web\View; | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @author Die Coding (Sugeng Sulistiyawan) <[email protected]> | ||
* @copyright 2020 Die Coding | ||
* @license MIT | ||
* @link https://www.diecoding.com | ||
* @version 1.0.0 | ||
*/ | ||
class PdfJsAsset extends AssetBundle | ||
{ | ||
|
||
/** | ||
* @var string $sourcePath | ||
*/ | ||
public $sourcePath = '@bower/pdfjs-dist'; | ||
|
||
/** | ||
* @var array $css | ||
*/ | ||
public $css = [ | ||
'web/pdf_viewer.css', | ||
]; | ||
|
||
/** | ||
* @var array $js | ||
*/ | ||
public $js = [ | ||
'build/pdf.min.js', | ||
// 'build/pdf.worker.min.js', | ||
'web/pdf_viewer.js', | ||
]; | ||
|
||
/** | ||
* @var array $depends | ||
*/ | ||
public $depends = [ | ||
'yii\web\YiiAsset', | ||
]; | ||
|
||
/** | ||
* @var array $jsOptions | ||
*/ | ||
public $jsOptions = [ | ||
'position' => View::POS_HEAD | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
function PDFJSIframeform(url) { | ||
var object = this; | ||
object.time = new Date().getTime(); | ||
object.form = $( | ||
'<form action="' + | ||
url + | ||
'" target="iframe' + | ||
object.time + | ||
'" method="post" style="display:none;" id="form' + | ||
object.time + | ||
'" name="form' + | ||
object.time + | ||
'"></form>' | ||
); | ||
|
||
object.addParameter = function (parameter, value) { | ||
$("<input type='hidden' />") | ||
.attr("name", parameter) | ||
.attr("value", value) | ||
.appendTo(object.form); | ||
}; | ||
|
||
object.send = function () { | ||
var iframe = $( | ||
'<iframe data-time="' + | ||
object.time + | ||
'" style="display:none;" id="iframe' + | ||
object.time + | ||
'"></iframe>' | ||
); | ||
$("body").append(iframe); | ||
$("body").append(object.form); | ||
object.form.submit(); | ||
iframe.load(function () { | ||
$("#form" + $(this).data("time")).remove(); | ||
$(this).remove(); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace diecoding\pdfjs\controllers; | ||
|
||
use diecoding\pdfjs\Module; | ||
use Yii; | ||
use yii\helpers\ArrayHelper; | ||
use yii\web\Controller; | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @author Die Coding (Sugeng Sulistiyawan) <[email protected]> | ||
* @copyright 2020 Die Coding | ||
* @license MIT | ||
* @link https://www.diecoding.com | ||
* @version 1.0.0 | ||
*/ | ||
class DefaultController extends Controller | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public $layout = 'main'; | ||
|
||
/** | ||
* Renders the index view for the module | ||
* @return string | ||
*/ | ||
public function actionIndex() | ||
{ | ||
$module = new Module(); | ||
$buttons = $module->buttons; | ||
$waterMark = $module->waterMark; | ||
if (Yii::$app->request->isPost) { | ||
|
||
$widgitButtonConfig = Yii::$app->request->post(); | ||
if (isset(Yii::$app->request->csrfParam)) { | ||
unset($widgitButtonConfig[Yii::$app->request->csrfParam]); | ||
} | ||
|
||
foreach ($widgitButtonConfig as $key => $value) { | ||
$widgitButtonConfig[$key] = trim($value) == '0' ? false : true; | ||
} | ||
$buttons = ArrayHelper::merge($buttons, $widgitButtonConfig); | ||
} | ||
|
||
return $this->render('index', [ | ||
'buttons' => $buttons, | ||
'waterMark' => $waterMark, | ||
]); | ||
} | ||
} |
Oops, something went wrong.