GroupDocs.Viewer Cloud allows you to optimize the output PDF file for a web browser or to reduce the file size by optimizing resources. Optimization for a web allows a browser to display the first pages of a PDF file when you open the document, instead of waiting for the entire file to download. Resource optimization allows you to reduce the size of the output PDF file. While optimizing, GroupDocs.Viewer may reduce the image size or quality, remove notes or form fields, remove objects, fonts, or personal information from a document, and so on.
See PdfOptimizationOptions for more information.
The following code sample shows how to adjust image quality in the output PDF document.
API Usage
There are steps that usage of GroupDocs.Viewer Cloud consists of:
Upload input document into cloud storage
Render document or get document info
Download rendered document from storage
Steps 1 and 3 are storage operations, please refer to this File API documentation for usage details.
Swagger UI lets you call this REST API directly from the browser.
cURL example
# First get JSON Web Token# Place your Client Id and Client Secret in environment variables CLIENT_ID and CLIENT_SECRET.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"# Get document informationcurl -v "https://api.groupdocs.cloud/v2.0/viewer/view"\
-X POST \
-H "Content-Type: application/json"\
-H "Accept: application/json"\
-H "Authorization: Bearer $JWT_TOKEN"\
-d '{
"FileInfo": {
"FilePath": "SampleFiles/with_jpg_image.pptx"
},
"ViewFormat": "PDF",
"RenderOptions": {
"PdfOptimizationOptions": {
"CompressImages": true,
"ImageQuality": 80
}
}
}'
# First get JSON Web Token# Set your Client Id and Client Secret in environment variables CLIENT_ID and CLIENT_SECRET.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"# Get document informationcurl.exe-v"https://api.groupdocs.cloud/v2.0/viewer/view"`-XPOST`-H"Content-Type: application/json"`-H"Accept: application/json"`-H"Authorization: Bearer $env:JWT_TOKEN"`-d"{
'FileInfo': {
'FilePath': 'SampleFiles/with_jpg_image.pptx'
},
'ViewFormat': 'PDF',
'RenderOptions': {
'PdfOptimizationOptions': {
'CompressImages': true,
'ImageQuality': 80
}
}
}"
REM First get JSON Web TokenREM Set your Client Id and Client Secret in environment variables CLIENT_ID and CLIENT_SECRET.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"REM Get document informationcurl -v "https://api.groupdocs.cloud/v2.0/viewer/view"^
-X POST ^
-H "Content-Type: application/json"^
-H "Accept: application/json"^
-H "Authorization: Bearer %JWT_TOKEN%"^
-d "{\"FileInfo\":{\"FilePath\":\"SampleFiles/with_jpg_image.pptx\"},\"ViewFormat\":\"PDF\",\"RenderOptions\":{\"PdfOptimizationOptions\":{\"CompressImages\":true,\"ImageQuality\":80}}}"
The API is completely independent of your operating system, database system or development language. We provide and support API SDKs in many development languages in order to make it even easier to integrate. You can see our available SDKs list here.
// For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-dotnet-samplesstringMyClientSecret="";// Get Client Id and Client Secret from https://dashboard.groupdocs.cloudstringMyClientId="";// Get Client Id and Client Secret from https://dashboard.groupdocs.cloudvarconfiguration=newConfiguration(MyClientId,MyClientSecret);varapiInstance=newViewApi(configuration);varviewOptions=newViewOptions{FileInfo=newFileInfo{FilePath="SampleFiles/with_jpg_image.pptx"},ViewFormat=ViewOptions.ViewFormatEnum.PDF,RenderOptions=newPdfOptions{PdfOptimizationOptions=newPdfOptimizationOptions{CompressImages=true,ImageQuality=80}}};varresponse=apiInstance.CreateView(newCreateViewRequest(viewOptions));
// For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-php-samples
useGroupDocs\Viewer\Model;useGroupDocs\Viewer\Model\Requests;$ClientId="";// Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
$ClientSecret="";// Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
$configuration=newGroupDocs\Viewer\Configuration();$configuration->setAppSid($ClientId);$configuration->setAppKey($ClientSecret);$apiInstance=newGroupDocs\Viewer\ViewApi($configuration);$viewOptions=newModel\ViewOptions();$fileInfo=newModel\FileInfo();$fileInfo->setFilePath("SampleFiles/with_jpg_image.pptx");$viewOptions->setFileInfo($fileInfo);$viewOptions->setViewFormat(Model\ViewOptions::VIEW_FORMAT_PDF);$renderOptions=newModel\PdfOptions();$pdfOptimizationOptions=newModel\PdfOptimizationOptions();$pdfOptimizationOptions->setCompressImages(true);$pdfOptimizationOptions->setImageQuality(80);$renderOptions->setPdfOptimizationOptions($pdfOptimizationOptions);$viewOptions->setRenderOptions($renderOptions);$request=newRequests\CreateViewRequest($viewOptions);$response=$apiInstance->createView($request);
// For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-java-samples
stringMyClientSecret="";// Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
stringMyClientId="";// Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
Configurationconfiguration=newConfiguration(MyClientId,MyClientSecret);ViewApiapiInstance=newViewApi(configuration);FileInfofileInfo=newFileInfo();fileInfo.setFilePath("SampleFiles/with_jpg_image.pptx");ViewOptionsviewOptions=newViewOptions();viewOptions.setFileInfo(fileInfo);viewOptions.setViewFormat(ViewFormatEnum.PDF);PdfOptionsrenderOptions=newPdfOptions();PdfOptimizationOptionspdfOptimizationOptions=newPdfOptimizationOptions();pdfOptimizationOptions.setCompressImages(true);pdfOptimizationOptions.setImageQuality(80);renderOptions.setPdfOptimizationOptions(pdfOptimizationOptions);viewOptions.setRenderOptions(renderOptions);ViewResultresponse=apiInstance.createView(newCreateViewRequest(viewOptions));
# For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-ruby-samplesrequire'groupdocs_viewer_cloud'$client_id="XXXX-XXXX-XXXX-XXXX"# Get Client Id and Client Secret from https://dashboard.groupdocs.cloud$client_secret="XXXXXXXXXXXXXXXX"# Get Client Id and Client Secret from https://dashboard.groupdocs.cloudapiInstance=GroupDocsViewerCloud::ViewApi.from_keys($client_id,$client_secret)viewOptions=GroupDocsViewerCloud::ViewOptions.newviewOptions.file_info=GroupDocsViewerCloud::FileInfo.newviewOptions.file_info.file_path="SampleFiles/with_jpg_image.pptx"viewOptions.view_format="PDF"viewOptions.render_options=GroupDocsViewerCloud::PdfOptions.newviewOptions.render_options.pdf_optimization_options=GroupDocsViewerCloud::PdfOptimizationOptions.newviewOptions.render_options.pdf_optimization_options.compress_images=trueviewOptions.render_options.pdf_optimization_options.image_quality=80request=GroupDocsViewerCloud::CreateViewRequest.new(viewOptions)response=apiInstance.create_view(request)
// For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-node-samples
global.viewer#require("groupdocs-viewer-cloud");global.clientId="XXXX-XXXX-XXXX-XXXX";// Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
global.clientSecret="XXXXXXXXXXXXXXXX";// Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
global.viewApi=viewer_cloud.ViewApi.fromKeys(clientId,clientSecret);letfileInfo=newviewer_cloud.FileInfo();fileInfo.filePath="SampleFiles/with_jpg_image.pptx";letviewOptions=newviewer_cloud.ViewOptions();viewOptions.fileInfo=fileInfo;viewOptions.viewFormat=viewer_cloud.ViewOptions.ViewFormatEnum.PDF;viewOptions.renderOptions=newviewer_cloud.PdfOptions();viewOptions.renderOptions.pdfOptimizationOptions=newviewer_cloud.PdfOptimizationOptions();viewOptions.renderOptions.pdfOptimizationOptions.compressImages=true;viewOptions.renderOptions.pdfOptimizationOptions.imageQuality=80;letrequest=newviewer_cloud.CreateViewRequest(viewOptions);letresponse=awaitviewApi.createView(request);
# For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-python-samplesimportgroupdocs_viewer_cloudclient_id="XXXX-XXXX-XXXX-XXXX"# Get Client Id and Client Secret from https://dashboard.groupdocs.cloudclient_secret="XXXXXXXXXXXXXXXX"# Get Client Id and Client Secret from https://dashboard.groupdocs.cloudapiInstance=groupdocs_viewer_cloud.ViewApi.from_keys(client_id,client_secret)view_options=groupdocs_viewer_cloud.ViewOptions()view_options.file_info=groupdocs_viewer_cloud.FileInfo()view_options.file_info.file_path="SampleFiles/with_jpg_image.pptx"view_options.view_format="PDF"view_options.render_options=groupdocs_viewer_cloud.PdfOptions()view_options.render_options.pdf_optimization_options=groupdocs_viewer_cloud.PdfOptimizationOptions()view_options.render_options.pdf_optimization_options.compress_images=Trueview_options.render_options.pdf_optimization_options.image_quality=80request=groupdocs_viewer_cloud.CreateViewRequest(view_options)response=apiInstance.create_view(request)