nextcloud/lib/preview/office-fallback.php

142 lines
3.1 KiB
PHP
Raw Normal View History

<?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;
2013-06-19 15:40:57 +04:00
/* //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) {
2013-06-19 15:40:57 +04:00
require_once('');
}
}
\OC\Preview::registerProvider('OC\Preview\DOC');
2013-06-19 15:40:57 +04:00
*/
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');
2013-07-30 14:29:12 +04:00
$tmpDoc = $fileview->toTmpFile($path);
$transformdoc = new \TransformDoc();
2013-07-30 14:29:12 +04:00
$transformdoc->setStrFile($tmpDoc);
$transformdoc->generatePDF($tmpDoc);
2013-07-30 14:29:12 +04:00
$pdf = new \imagick($tmpDoc . '[0]');
$pdf->setImageFormat('jpg');
2013-07-30 14:29:12 +04:00
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');
2013-07-30 14:29:12 +04:00
$absPath = $fileview->toTmpFile($path);
$tmpPath = \OC_Helper::tmpFile();
$rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/dompdf';
\PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
2013-07-30 14:29:12 +04:00
$phpexcel = new \PHPExcel($absPath);
$excel = \PHPExcel_IOFactory::createWriter($phpexcel, 'PDF');
2013-07-30 14:29:12 +04:00
$excel->save($tmpPath);
2013-07-30 14:29:12 +04:00
$pdf = new \imagick($tmpPath . '[0]');
$pdf->setImageFormat('jpg');
2013-07-30 14:29:12 +04:00
unlink($absPath);
unlink($tmpPath);
$image = new \OC_Image($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');
2013-06-18 15:53:02 +04:00
/* //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) {
2013-06-12 15:20:59 +04:00
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');
2013-06-18 15:53:02 +04:00
*/