承接 garant/file-preview-generator-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

garant/file-preview-generator-bundle

Composer 安装命令:

composer require garant/file-preview-generator-bundle

包简介

This Symfony bundle provides classes to generate preview image for office files like .doc, .docx, .xls and others. It contains client and server that lets use it both locally and remotely

README 文档

README

This bundle provides classes to generate preview image for office files like .doc, .docx, .xls and others. It contains client and server that let use the bundle both locally and remotely.

System requirements (for Microsoft Windows)

A) Microsoft Office must be installed. Also you need to configure COM-objects. From the Start menu, click Run and type Dcomcnfg.exe. In Component Services, click Console root, expand Component Services, expand Computers, then My Computer, then DCOM Configuration Find entity named Microsoft Word 97-2003 Document. Right click on it, then Properties. In the tab Identity choose This user and enter correct admin login and password. Save changes.

B) Install GhostScript

C) Install ImageMagic All *.dll file in folder modules/coders inside your ImageMagic directory copy to ImageMagic directory and C:\Windows\System32 and C:\Windows\SysWOW64 All *.dll file in folder modules/filters inside your ImageMagic directory copy to ImageMagic directory C:\Windows\System32 and C:\Windows\SysWOW64

D) Find and download archive php_imagick-3.4.1-7.0-ts-vc14-x64

Copy all CORE.dll's from it to C:\Windows\System32 and C:\Windows\SysWOW64

Copy php_imagick.dll to ext folder in your php directory

E) Add MAGICK_HOME to your environment PATH

F) Edit php.ini file in your php directory

Uncomment or add next lines in Windows extensions section:

extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_exif.dll
extension=php_openssl.dll
extension=php_com_dotnet.dll
extension=php_imagick.dll

;...

memory_limit = 1024M

G) Reboot (here it's really important!)

Installation

With composer

This bundle can be installed using composer:

composer require garant/file-preview-generator-bundle

Register the bundle

<?php

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(

        // ...
        new Liip\ImagineBundle\LiipImagineBundle(),
        // ...
        new Garant\GarantFilePreviewGeneratorBundle\GarantFilePreviewGeneratorBundle(),
    );

	// ...
}

Configuration

You can add remote servers:

garant_file_preview_generator:
    #
    # Available algorithms: random, round_robin
    #server_select_algorithm: random
    #
    # Remote servers are used to generate file preview
    # To start generator server use "garant:file-preview-generator:server-start <server_name>" command
    #servers:
    #    local_unix:
    #        host: 0.0.0.0
    #        port: 9010
    #
    #    remote_windows:
    #        host: 192.168.10.201
    #        port: 9010
    #    
    #    remote_windows_secure:
    #        protocol: https 
    #        host: 192.168.10.201
    #        port: 9011

Optionally you can configure Liip imagine filters to post process preview images:

liip_imagine:
    filter_sets:
        avatar_square:
            filters:
                # Transforms 150x140 to 120x120, while cropping the width
                thumbnail: { size: [120, 120], mode: outbound }

Console commands

If remote server is configured you can start it. Call this command on remote server:

bin/console garant:file-preview-generator:server-start <server_name>

Also you can start server with -vvv flag to check memory usage and get other information about conversion process.

You can start some generators simultaneously and automatically restart processes using embedded supervisor:

bin/console garant:file-preview-generator:supervisor-start

Services

To generate preview you can use specific generator. Use the generator factory to create a generator that you need:

garant_file_preview_generator.remote_client - Remote client. 
garant_file_preview_generator.generator_factory - Factory service.

Example

$temp_file = new \SplFileObject('test.docx');

$factory = $this->container->get('garant_file_preview_generator.generator_factory');
$generator = $factory->get($temp_file, AbstractGenerator::PREVIEW_FORMAT_JPEG);
$jpeg_preview_file = $generator->generate($temp_file, AbstractGenerator::PREVIEW_FORMAT_JPEG);
if(!$jpeg_preview_file){
    $this->get('logger')->err('Preview attachment: Preview generation error');
    throw new \RuntimeException('Preview generation error');
}

dump($jpeg_preview_file);

// Generate filtered preview
$generator->setFilter('avatar_square');
$jpeg_preview_file = $generator->generate($temp_file, AbstractGenerator::PREVIEW_FORMAT_JPEG);

dump($jpeg_preview_file);

// Generate preview in PDF or other format
// see AbstractGenerator class constants
$generator = $factory->get($temp_file, AbstractGenerator::PREVIEW_FORMAT_PDF);
$pdf_preview_file = $generator->generate($temp_file, AbstractGenerator::PREVIEW_FORMAT_PDF);

// Optionally, you can convert range of pages
// $generator->setPageRange('0-2');
// Or set number of pages
// $generator->setPageCount(3);

dump($pdf_preview_file);

统计信息

  • 总下载量: 390
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固