This REST API allows generating preview images of the document pages. The endpoint accepts the document storage path and the preview options as input payload, saves the page images to the storage and returns the information about each image.
With this API you can:
Generate previews of all the document pages or only of the selected ones;
Choose the image format: PNG, JPEG or BMP;
Set the size of the images or keep the original page size;
For protected documents, it is required to provide the password.
Here is the list of properties that can be obtained for each page image:
Page number, starting from 1;
Path of the image in the storage;
Download URL of the image;
Image size in bytes.
The table below contains the full list of properties.
Name
Description
Comment
FileInfo.FilePath
The path of the document, located in the storage.
Required.
FileInfo.StorageName
Storage name
It could be omitted for default storage.
FileInfo.Password
The password to open file
It should be specified only for password-protected documents.
OutputFolder
The folder for the page images.
When not set, the default folder is used.
Format
The image format.
Possible values: PNG, JPEG, BMP. The default value is PNG.
Width
The image width in pixels.
Width and Height must be set together. When not set, the original page size is used.
Height
The image height in pixels.
Width and Height must be set together. When not set, the original page size is used.
PageNumbers
The numbers of the pages to preview, starting from 1.
When empty, all pages are previewed. Pages that do not exist are skipped.
Resource URI
HTTP POST ~~/watermark/preview
Swagger UI lets you call this REST API directly from the browser.
cURL example
# Get JSON Web Token# Ensure CLIENT_ID and CLIENT_SECRET are set in your environment.curl -v "https://api.groupdocs.cloud/connect/token"\
-X POST \
-d "grant_type=client_credentials&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET"\
-H "Content-Type: application/x-www-form-urlencoded"\
-H "Accept: application/json"# Generate document page previews (watermark)curl -v "https://api.groupdocs.cloud/v1.0/watermark/preview"\
-X POST \
-H "Content-Type: application/json"\
-H "Accept: application/json"\
-H "Authorization: Bearer $JWT_TOKEN"\
-d '{
"FileInfo": {
"FilePath": "documents/sample.pdf"
},
"OutputFolder": "previews",
"Format": "PNG",
"PageNumbers": [1, 2]
}'
# Get JSON Web Token# Ensure CLIENT_ID and CLIENT_SECRET are set in environment variables.curl.exe-v"https://api.groupdocs.cloud/connect/token"`-XPOST`-d"grant_type=client_credentials&client_id=$env:CLIENT_ID&client_secret=$env:CLIENT_SECRET"`-H"Content-Type: application/x-www-form-urlencoded"`-H"Accept: application/json"# Generate document page previews (watermark)curl.exe-v"https://api.groupdocs.cloud/v1.0/watermark/preview"`-XPOST`-H"Content-Type: application/json"`-H"Accept: application/json"`-H"Authorization: Bearer $env:JWT_TOKEN"`-d"{
'FileInfo': {
'FilePath': 'documents/sample.pdf'
},
'OutputFolder': 'previews',
'Format': 'PNG',
'PageNumbers': [1, 2]
}"
:: Get JSON Web Token:: Ensure CLIENT_ID and CLIENT_SECRET are set as environment variables.curl -v "https://api.groupdocs.cloud/connect/token"^
-X POST ^
-d "grant_type=client_credentials&client_id=%CLIENT_ID%&client_secret=%CLIENT_SECRET%"^
-H "Content-Type: application/x-www-form-urlencoded"^
-H "Accept: application/json":: Generate document page previews (watermark)curl -v "https://api.groupdocs.cloud/v1.0/watermark/preview"^
-X POST ^
-H "Content-Type: application/json"^
-H "Accept: application/json"^
-H "Authorization: Bearer %JWT_TOKEN%"^
-d "{\"FileInfo\":{\"FilePath\":\"documents/sample.pdf\"},\"OutputFolder\":\"previews\",\"Format\":\"PNG\",\"PageNumbers\":[1,2]}"
Our API is completely independent of your operating system, database system or development language. You can use any language and platform that supports HTTP to interact with our API. However, manually writing client code can be difficult, error-prone and time-consuming. Therefore, we have provided and support API SDKs in many development languages in order to make it easier to integrate with us. If you use SDK, it makes the document page preview API calls for you and lets you use GroupDocs Cloud features in a native way for your preferred language.
usingGroupDocs.Watermark.Cloud.Sdk.Api;usingGroupDocs.Watermark.Cloud.Sdk.Client;usingGroupDocs.Watermark.Cloud.Sdk.Model;usingGroupDocs.Watermark.Cloud.Sdk.Model.Requests;usingSystem;usingSystem.Collections.Generic;usingFileInfo=GroupDocs.Watermark.Cloud.Sdk.Model.FileInfo;namespaceGroupDocs.Watermark.Cloud.Examples.CSharp{/// <summary>/// This example demonstrates how to generate document page previews./// </summary>publicclassPreviewDocumentPages{publicstaticvoidRun(){// Get your Client Id and Client Secret at https://dashboard.groupdocs.cloud (free registration is required).varconfiguration=newConfiguration("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX","XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");varapiInstance=newPreviewApi(configuration);try{varoptions=newPreviewOptions{FileInfo=newFileInfo{FilePath="documents/sample.pdf"},OutputFolder="previews",Format="PNG",PageNumbers=newList<int?>{1,2}};varrequest=newPreviewRequest(options);varresponse=apiInstance.Preview(request);foreach(varpageinresponse.Pages){Console.WriteLine("Page "+page.PageNumber+": "+page.Path+" ("+page.Size+" bytes)");}}catch(Exceptione){Console.WriteLine("Exception while calling api: "+e.Message);}}}}
importjava.util.Arrays;importcom.groupdocs.cloud.watermark.api.*;importcom.groupdocs.cloud.watermark.client.*;importcom.groupdocs.cloud.watermark.model.*;importcom.groupdocs.cloud.watermark.model.requests.*;/**
* This example demonstrates how to generate document page previews.
*/publicclassPreviewDocumentPages{publicstaticvoidmain(String[]args){// Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required).
Configurationconfiguration=newConfiguration("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX","XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");PreviewApiapiInstance=newPreviewApi(configuration);try{FileInfofileInfo=newFileInfo();fileInfo.setFilePath("documents/sample.pdf");PreviewOptionsoptions=newPreviewOptions();options.setFileInfo(fileInfo);options.setOutputFolder("previews");options.setFormat("PNG");options.setPageNumbers(Arrays.asList(1,2));PreviewRequestrequest=newPreviewRequest(options);PreviewResultresponse=apiInstance.preview(request);for(PreviewPagepage:response.getPages()){System.out.println("Page "+page.getPageNumber()+": "+page.getPath()+" ("+page.getSize()+" bytes)");}}catch(ApiExceptione){System.err.println("Exception while calling api:");e.printStackTrace();}}}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.