Description
The document-to-HTML feature supports generating HTML previews for various document types, meeting online requirements for viewing documents across multiple user terminals including PCs and Apps. It is applicable to business scenarios such as online education, enterprise OA, online knowledge bases, and document preview in cloud drives.
Note:
Cloud Infinite encapsulates the JS preview SDK, allowing access to the HTML preview service with just a single URL.
Authorization Description
When a sub-account is used, you must grant the cos:GetObject and cos:HeadObject permissions in the action of the Authorization Policy. For all APIs supported by COS, see COS action. Service Activation
To use this feature, you need to bind Bucket in advance and activate the Cloud Infinite service. To use this feature, you need to activate the document processing service in advance via the console or API. Note:
After Cloud Infinite is bound, if you manually unbind Cloud Infinite from the Bucket, you will not be able to continue using this feature.
Use Limits
When using this interface, please first confirm the relevant restrictions. For details, see Usage Limits. Fee Instructions
Request
Request sample
GET /<ObjectKey>?ci-process=doc-preview&dstType=html HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
Date: GMT Date
Authorization: Auth String
Note:
Authorization: A request header that carries authentication information. If your COS file has private read permission, the request can be verified with this header. For details, see Request Signature. Request header
Request Parameter
|
| Name of the object file, for example folder/document.pdf | | |
| The processing capability of Cloud Infinite; HTML document preview is fixed as doc-preview. | | |
| Output type of the target file. HTML document preview is fixed as html (must be lowercase). | | |
| Enter the type of the target file. For supported file types and limitations, see below Notes section | | |
| Signature for object download. If the object to be previewed has private read permission, a signature is required. For details, see Request Signature. Note: URL encoding is required. | | |
| Whether it can be copied. The default is copyable: <1> indicates copyable; <0> indicates not copyable. | | |
| Watermark text requires URL-safe Base64 encoding, default is empty. | | |
| Watermark RGBA (color and transparency) requires URL-safe Base64 encoding. Default: rgba(192,192,192,0.6). | | |
| Style of the watermark text requires URL-safe Base64 encoding, default: bold 20px Serif. | | |
| Rotation angle of the watermark text, 0 - 360, default 315 degrees | | |
| Horizontal spacing of the watermark text, unit: px, default: 50 | | |
| Vertical spacing of the watermark text, unit: px, default: 100 | | |
Currently supported types of input files include the following formats:
Presentation files: pptx, ppt, pot, potx, pps, ppsx, dps, dpt, pptm, potm, ppsm.
Document files: doc, dot, wps, wpt, docx, dotx, docm, dotm.
Spreadsheet files: xls, xlt, et, ett, xlsx, xltx, xlsb, xlsm, xltm, ets.
Other format files: pdf, lrc, c, cpp, h, asm, s, java, asp, bat, bas, prg, cmd, rtf, txt, log, xml, htm, html.
Size of the input file is limited to 200MB.
Input file page count is limited to 5000 pages.
Word documents default to continuous layout on mobile devices and to page layout on PC.
Request body
The request body of this request is empty.
Response
Response Headers
Response Body
The response body of this API request contains HTML preview content. For the display effect, see Actual Example. Error Codes
This request has no unique error messages. For common error messages, see Error Codes. Practical Case
Case 1: Simple Preview
To preview the PPT file with ObjectKey test.pptx in Bucket examples-1258125638 online, the final URL is as follows:
https://examples-1258125638.cos.ap-guangzhou.myqcloud.com/test.pptx?ci-process=doc-preview&dstType=html
Open the link directly in the browser. The generated preview page is shown in the figure below. For slide documents, you can also perform a full-screen slide show, supporting effects such as animations, triggers, and providing features such as virtual laser pointer, presenter mode.
Case 2: Watermark + Custom Configuration Preview
To preview the PPT file with ObjectKey test.pptx in Bucket examples-1258125638 online.
1. Set non-copyable (copyable = 0).
2. Set test watermark (via URL-safe Base64 encoding resulting in htmlwaterword = dGVzdAog).
3. Set custom configuration parameters (htmlParams is {"mode":"normal","commonOptions":{"isShowHeader":false,"isShowTopArea":true},"pptOptions":{"isSlidesStatusPlay": true}}, encoded via URL-safe Base64 to htmlParams=eyJtb2RlIjoibm9ybWFsIiwiY29tbW9uT3B0aW9ucyI6eyJpc1Nob3dIZWFkZXIiOmZhbHNlLCJpc1Nob3dUb3BBcmVhIjp0cnVlfSwicHB0T3B0aW9ucyI6eyJpc1NsaWRlc1N0YXR1c1BsYXkiOiB0cnVlfX0=).
The final URL is as follows:
https://examples-1258125638.cos.ap-guangzhou.myqcloud.com/test.pptx?ci-process=doc-preview&dstType=html©able=0&htmlwaterword=dGVzdAog&htmlParams=eyJtb2RlIjoibm9ybWFsIiwiY29tbW9uT3B0aW9ucyI6eyJpc1Nob3dIZWFkZXIiOmZhbHNlLCJpc1Nob3dUb3BBcmVhIjp0cnVlfSwicHB0T3B0aW9ucyI6eyJpc1NsaWRlc1N0YXR1c1BsYXkiOiB0cnVlfX0=
Open the link directly in the browser. The generated preview page is shown in the figure below. For slide documents, you can also perform a full-screen slide show, supporting effects such as animations, triggers, and providing features such as virtual laser pointer, presenter mode.
The preview link can also be embedded as an iframe in the business page, as shown below:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0,user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
<meta name="keywords" content="COS,document preview">
<meta name="description" content="">
<title>Tencent Cloud - COS - Document Preview</title>
<style>
html,
body {
padding: 0;
margin: 0;
height: 100%;
touch-action: manipulation;
}
</style>
</head>
<body>
<iframe src="https://examples-1258125638.cos.ap-guangzhou.myqcloud.com/test.pptx?ci-process=doc-preview&dstType=html©able=0&htmlwaterword=dGVzdAog&htmlParams=eyJtb2RlIjoibm9ybWFsIiwiY29tbW9uT3B0aW9ucyI6eyJpc1Nob3dIZWFkZXIiOmZhbHNlLCJpc1Nob3dUb3BBcmVhIjp0cnVlfSwicHB0T3B0aW9ucyI6eyJpc1NsaWRlc1N0YXR1c1BsYXkiOiB0cnVlfX0=" width="100%" height="100%" allowFullScreen="true"></iframe>
</body>
</html>
Case 3: Switch Preview Language to English
To preview the PPT file with ObjectKey test.pptx in Bucket examples-1258125638 online.
Set the htmlParams parameter (htmlParams is {"commonOptions":{"language": "en"}}, encoded via URL-safe Base64 to htmlParams=eyJjb21tb25PcHRpb25zIjp7Imxhbmd1YWdlIjoiZW4ifX0).
The final URL is as follows:
https://examples-1258125638.cos.ap-guangzhou.myqcloud.com/test.pptx?ci-process=doc-preview&dstType=html&htmlParams=eyJjb21tb25PcHRpb25zIjp7Imxhbmd1YWdlIjoiZW4ifX0