Blame view
sources/lib/private/preview/office-fallback.php
3.13 KB
|
31b7f2792
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
<?php
/**
* Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OC\Preview;
/* //There is no (good) php-only solution for converting 2003 word documents to pdfs / pngs ...
class DOC extends Provider {
public function getMimeType() {
return '/application\/msword/';
}
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
require_once('');
}
}
\OC\Preview::registerProvider('OC\Preview\DOC');
*/
class DOCX extends Provider {
public function getMimeType() {
return '/application\/vnd.openxmlformats-officedocument.wordprocessingml.document/';
}
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
require_once('phpdocx/classes/TransformDoc.inc');
$tmpDoc = $fileview->toTmpFile($path);
$transformdoc = new \TransformDoc();
$transformdoc->setStrFile($tmpDoc);
$transformdoc->generatePDF($tmpDoc);
$pdf = new \imagick($tmpDoc . '[0]');
$pdf->setImageFormat('jpg');
unlink($tmpDoc);
$image = new \OC_Image($pdf);
return $image->valid() ? $image : false;
}
}
\OC\Preview::registerProvider('OC\Preview\DOCX');
class MSOfficeExcel extends Provider {
public function getMimeType() {
return null;
}
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
require_once('PHPExcel/Classes/PHPExcel.php');
require_once('PHPExcel/Classes/PHPExcel/IOFactory.php');
$absPath = $fileview->toTmpFile($path);
$tmpPath = \OC_Helper::tmpFile();
$rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/dompdf';
\PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
$phpexcel = new \PHPExcel($absPath);
$excel = \PHPExcel_IOFactory::createWriter($phpexcel, 'PDF');
$excel->save($tmpPath);
$pdf = new \imagick($tmpPath . '[0]');
$pdf->setImageFormat('jpg');
unlink($absPath);
unlink($tmpPath);
$image = new \OC_Image();
$image->loadFromData($pdf);
return $image->valid() ? $image : false;
}
}
class XLS extends MSOfficeExcel {
public function getMimeType() {
return '/application\/vnd.ms-excel/';
}
}
\OC\Preview::registerProvider('OC\Preview\XLS');
class XLSX extends MSOfficeExcel {
public function getMimeType() {
return '/application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/';
}
}
\OC\Preview::registerProvider('OC\Preview\XLSX');
/* //There is no (good) php-only solution for converting powerpoint documents to pdfs / pngs ...
class MSOfficePowerPoint extends Provider {
public function getMimeType() {
return null;
}
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
return false;
}
}
class PPT extends MSOfficePowerPoint {
public function getMimeType() {
return '/application\/vnd.ms-powerpoint/';
}
}
\OC\Preview::registerProvider('OC\Preview\PPT');
class PPTX extends MSOfficePowerPoint {
public function getMimeType() {
return '/application\/vnd.openxmlformats-officedocument.presentationml.presentation/';
}
}
\OC\Preview::registerProvider('OC\Preview\PPTX');
*/
|