Coder Social home page Coder Social logo

office-to-pdf's Introduction

office-to-pdf

Convert any office files to PDF format.

This library use LibreOffice power to convert any office files to PDF format. So, please make sure you have installed LibreOffice on your environment!

Requirements

  • PHP 5.6 or above
  • LibreOffice

Installation

composer require ngekoding/office-to-pdf

Usage

Simple usage

<?php

// Include autoloader
require 'vendor/autoload.php';

use Ngekoding\OfficeToPdf\Converter;

$converter = new Converter();
$converter->convert('path/to/file.docx');

You can also convert other file type (not only .docx), feel free to convert any office file like .pptx, .xlsx, etc...

Setting process timeout

By default processes have a timeout of 60 seconds, but you can change it passing a different timeout (in seconds) to the setTimeout() method:

$converter = new Converter();
$converter->setTimeout(3600);

Docs: Symfony Process Timeout

Setting manually LibreOffice executable path

By default the library will try to find LibreOffice executable based on current operating system.

$converter = new Converter('path/to/libreoffice');

Setting destination folder

By default the PDF result will generated in the same directory as the source file. You can define the destination folder by passing the second parameter.

$converter = new Converter();
$converter->convert('path/to/file.docx', './pdf-outputs');

By default the PDF filename will same with the source file, you can define the output filename by setting the destination folder with filename.

// The result filename will be result.pdf in the same directory as the source file
$converter->convert('path/to/file.docx', 'result.pdf');

// Or save to spesific directory
$converter->convert('path/to/file.docx', './pdf-outputs/result.pdf');

office-to-pdf's People

Contributors

ngekoding avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.