Browse our Products

If so you can download any of the below versions for testing. The product will function as normal except for an evaluation limitation. At the time of purchase we provide a license file via email that will allow the product to work in its full capacity. If you would also like an evaluation license to test without any restrictions for 30 days, please follow the directions provided here.


Product Docs Swagger Examples Blog Support Dashboard

Installation

The package is available at Packagist and it can be installed via Composer by executing following command:

composer require groupdocscloud/groupdocs-viewer-cloud

Packagist Version Packagist Downloads PHP-GroupDocsCloud


Requirements

  • PHP 8.1 or later
  • Composer
  • PHP extensions — curl, json, mbstring
  • GroupDocs Cloud credentials — Client ID and Client Secret from the Dashboard

Dependencies

The SDK requires the following packages:

PackageConstraint
guzzlehttp/guzzle^6.5.8 or ^7.4.5
ext-curl*
ext-json*
ext-mbstring*

Quick Start

Get your API credentials

To use GroupDocs.Viewer Cloud, sign up at GroupDocs.Cloud Dashboard and get your Client ID and Client Secret.

Initialize the API

Use the following code to start using the GroupDocs.Viewer Cloud SDK for PHP:

<?php

require_once(__DIR__ . '/vendor/autoload.php');

// Get your ClientId and ClientSecret at https://dashboard.groupdocs.cloud
$configuration = new GroupDocs\Viewer\Configuration();
$configuration->setAppSid("YourClientId");
$configuration->setAppKey("YourClientSecret");
$configuration->setApiBaseUrl("https://api.groupdocs.cloud");

$viewApi = new GroupDocs\Viewer\ViewApi($configuration);

See the full example in Utils.php.

Convert and download a document (direct, no cloud storage)

Once initialized, use this basic example to convert a local document to JPG and receive the result directly.

<?php

require_once(__DIR__ . '/vendor/autoload.php');

use GroupDocs\Viewer\Model\Requests;

$configuration = new GroupDocs\Viewer\Configuration();
$configuration->setAppSid("YourClientId");
$configuration->setAppKey("YourClientSecret");
$configuration->setApiBaseUrl("https://api.groupdocs.cloud");

$viewApi = new GroupDocs\Viewer\ViewApi($configuration);

$format = "jpg";
$filePath = __DIR__ . "/sample.docx";
$request = new Requests\convertAndDownloadRequest($format, $filePath);

$result = $viewApi->convertAndDownload($request);

echo "Document converted: " . $result->getSize() . "\n";

See the full example in ConvertAndDownload.php.

Render a Document with Responsive HTML

This example renders a Word document from cloud storage as responsive HTML.

<?php

require_once(__DIR__ . '/vendor/autoload.php');

use GroupDocs\Viewer\Model;
use GroupDocs\Viewer\Model\Requests;

$configuration = new GroupDocs\Viewer\Configuration();
$configuration->setAppSid("YourClientId");
$configuration->setAppKey("YourClientSecret");
$configuration->setApiBaseUrl("https://api.groupdocs.cloud");

$viewApi = new GroupDocs\Viewer\ViewApi($configuration);

$viewOptions = new Model\ViewOptions();

$fileInfo = new Model\FileInfo();
$fileInfo->setFilePath("SampleFiles/sample.docx");
$viewOptions->setFileInfo($fileInfo);
$viewOptions->setViewFormat(Model\ViewOptions::VIEW_FORMAT_HTML);

$renderOptions = new Model\HtmlOptions();
$renderOptions->setIsResponsive(true);
$viewOptions->setRenderOptions($renderOptions);

$request = new Requests\createViewRequest($viewOptions);
$response = $viewApi->createView($request);

echo "Responsive HTML rendered: " . count($response->getPages()) . "\n";

See the full example in HtmlViewerResponsiveLayout.php.

Render Selected Pages

This example renders only pages 1 and 3.

<?php

require_once(__DIR__ . '/vendor/autoload.php');

use GroupDocs\Viewer\Model;
use GroupDocs\Viewer\Model\Requests;

$configuration = new GroupDocs\Viewer\Configuration();
$configuration->setAppSid("YourClientId");
$configuration->setAppKey("YourClientSecret");
$configuration->setApiBaseUrl("https://api.groupdocs.cloud");

$viewApi = new GroupDocs\Viewer\ViewApi($configuration);

$viewOptions = new Model\ViewOptions();

$fileInfo = new Model\FileInfo();
$fileInfo->setFilePath("SampleFiles/sample.docx");
$viewOptions->setFileInfo($fileInfo);
$viewOptions->setViewFormat(Model\ViewOptions::VIEW_FORMAT_HTML);

$renderOptions = new Model\HtmlOptions();
$renderOptions->setPagesToRender([1, 3]);
$viewOptions->setRenderOptions($renderOptions);

$request = new Requests\createViewRequest($viewOptions);
$response = $viewApi->createView($request);

echo "Selected pages rendered: " . count($response->getPages()) . "\n";

See the full example in RenderSelectedPages.php.

Get Supported File Formats

Retrieve the supported file formats.

<?php

require_once(__DIR__ . '/vendor/autoload.php');

$configuration = new GroupDocs\Viewer\Configuration();
$configuration->setAppSid("YourClientId");
$configuration->setAppKey("YourClientSecret");
$configuration->setApiBaseUrl("https://api.groupdocs.cloud");

$infoApi = new GroupDocs\Viewer\InfoApi($configuration);

$response = $infoApi->getSupportedFileFormats();

echo "Number of formats = " . count($response->getFormats()) . "\n";

See the full example in GetSupportedFormats.php.

Examples on GitHub

The GroupDocs.Viewer Cloud PHP Examples repository includes ready-to-run examples covering:

CategoryExamples
Basic UsageSupported formats, document info, attachments, convert and download
HTML ViewerResponsive layout, minify HTML, exclude fonts, limit image size, optimize for printing
Image ViewerAdjust image size, JPG quality, text overlay, text coordinates
PDF ViewerProtect PDF, adjust JPG quality
Common Rendering OptionsWatermarks, flip and rotate pages, comments, consecutive pages, hidden pages, notes, selected pages, custom fonts, reorder pages, replace missing font
Loading OptionsProtected documents, specify encoding
Rendering by File TypeArchive, CAD, email, Lotus Notes, MS Project, Outlook, PDF, spreadsheet, text, Visio, Word

How to run the examples

  1. Clone or download the examples repository
  2. Edit Examples/Utils.php and set your Client Id and Client Secret
  3. Go to the Examples directory
  4. Run composer update
  5. Execute php RunExamples.php

For more details, visit Getting Started.


Product Docs Swagger Examples Blog Support Dashboard


Tags

Document Rendering API | PHP Cloud API | GroupDocs.Viewer Cloud | REST API | HTML Rendering | PDF Conversion | Image Rendering | Document Viewing | Multi-Page Rendering | Document Streaming | CAD Rendering | E-Mail Message Rendering | Visio Rendering | MS Project Rendering | Outlook Data Rendering | Spreadsheet Rendering | Word Processing Rendering | Custom View Options | Responsive HTML | Attachment Rendering | Secure API Access | Cloud Storage Integration



 English