浏览我们的产品

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

安装

该软件包在PyPI可用,可以通过执行以下命令通过pip安装:

pip install groupdocs-viewer-cloud

PyPI - Version PyPI - Downloads Python-GroupDocsCloud


要求

依赖关系

SDK自动安装以下软件包:

PackageConstraint
urllib3>= 1.15
six>= 1.10
certifi
python-dateutil

快速入门

获取您的 API 凭证

要使用GroupDocs.Viewer Cloud,请在GroupDocs.Cloud仪表板注册并获取您的Client IDClient Secret

初始化API

使用以下代码开始使用GroupDocs.Viewer Cloud SDK for Python:

import groupdocs_viewer_cloud

# Get your ClientId and ClientSecret at https://dashboard.groupdocs.cloud
client_id = "YourClientId"
client_secret = "YourClientSecret"

# Create API configuration
configuration = groupdocs_viewer_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"

# Create instance of the View API
view_api = groupdocs_viewer_cloud.ViewApi.from_config(configuration)

将文档渲染为 HTML

初始化后,使用此基本示例从云存储呈现文档:

import groupdocs_viewer_cloud

client_id = "YourClientId"
client_secret = "YourClientSecret"

view_api = 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/sample.docx"
view_options.view_format = "HTML"

request = groupdocs_viewer_cloud.CreateViewRequest(view_options)
response = view_api.create_view(request)

print("Document rendered: " + str(len(response.pages)) + " pages")

通过本快速入门指南,您已准备好开始在 Python 应用程序中使用 GroupDocs.Viewer Cloud 渲染文档。欲了解更多详情,请访问文档

获取支持的文件格式

通过查看器 API 检索可用的受支持文件格式的完整列表。

import groupdocs_viewer_cloud

info_api = groupdocs_viewer_cloud.InfoApi.from_keys("YourClientId", "YourClientSecret")

try:
    response = info_api.get_supported_file_formats()

    print("Supported file-formats:")
    for fmt in response.formats:
        print("{0} ({1})".format(fmt.file_format, fmt.extension))
except groupdocs_viewer_cloud.ApiException as e:
    print("Exception when calling get_supported_file_formats: {0}".format(e.message))

将文档渲染为 PDF

此示例演示如何使用 GroupDocs.Viewer Cloud API 将 Word 文档呈现为 PDF 格式。

import groupdocs_viewer_cloud

view_api = groupdocs_viewer_cloud.ViewApi.from_keys("YourClientId", "YourClientSecret")

view_options = groupdocs_viewer_cloud.ViewOptions()
view_options.file_info = groupdocs_viewer_cloud.FileInfo()
view_options.file_info.file_path = "SampleFiles/sample.docx"
view_options.view_format = "PDF"
view_options.render_options = groupdocs_viewer_cloud.PdfOptions()

request = groupdocs_viewer_cloud.CreateViewRequest(view_options)
response = view_api.create_view(request)

print("Document rendered to PDF: " + response.file.path)

将电子表格呈现为 HTML

此代码示例使用 GroupDocs.Viewer Cloud API 将 Excel 电子表格转换为 HTML。

import groupdocs_viewer_cloud

view_api = groupdocs_viewer_cloud.ViewApi.from_keys("YourClientId", "YourClientSecret")

view_options = groupdocs_viewer_cloud.ViewOptions()
view_options.file_info = groupdocs_viewer_cloud.FileInfo()
view_options.file_info.file_path = "SampleFiles/sample.xlsx"
view_options.view_format = "HTML"
view_options.render_options = groupdocs_viewer_cloud.HtmlOptions()

request = groupdocs_viewer_cloud.CreateViewRequest(view_options)
response = view_api.create_view(request)

print("Spreadsheet rendered to HTML: " + str(len(response.pages)) + " pages")

使用响应式 HTML 布局渲染文档

将文档呈现为响应式 HTML,以适应各种屏幕尺寸和设备。

import groupdocs_viewer_cloud

view_api = groupdocs_viewer_cloud.ViewApi.from_keys("YourClientId", "YourClientSecret")

view_options = groupdocs_viewer_cloud.ViewOptions()
view_options.file_info = groupdocs_viewer_cloud.FileInfo()
view_options.file_info.file_path = "SampleFiles/sample.docx"
view_options.view_format = "HTML"
view_options.render_options = groupdocs_viewer_cloud.HtmlOptions()
view_options.render_options.is_responsive = True

request = groupdocs_viewer_cloud.CreateViewRequest(view_options)
response = view_api.create_view(request)

print("Responsive HTML rendered: " + str(len(response.pages)) + " pages")

渲染选定的页面

仅转换文档的特定页面,在仅需要文档的一部分时节省处理时间。

import groupdocs_viewer_cloud

view_api = groupdocs_viewer_cloud.ViewApi.from_keys("YourClientId", "YourClientSecret")

view_options = groupdocs_viewer_cloud.ViewOptions()
view_options.file_info = groupdocs_viewer_cloud.FileInfo()
view_options.file_info.file_path = "SampleFiles/sample.docx"
view_options.view_format = "HTML"
view_options.render_options = groupdocs_viewer_cloud.HtmlOptions()
view_options.render_options.pages_to_render = [2, 3]

request = groupdocs_viewer_cloud.CreateViewRequest(view_options)
response = view_api.create_view(request)

print("Selected pages rendered: " + str(len(response.pages)) + " pages")

渲染带有跟踪更改的 Word 文档

渲染 Word 文档,包括输出 HTML 中的跟踪更改。

import groupdocs_viewer_cloud

view_api = groupdocs_viewer_cloud.ViewApi.from_keys("YourClientId", "YourClientSecret")

view_options = groupdocs_viewer_cloud.ViewOptions()
view_options.file_info = groupdocs_viewer_cloud.FileInfo()
view_options.file_info.file_path = "SampleFiles/with_tracked_changes.docx"
view_options.view_format = "HTML"
view_options.render_options = groupdocs_viewer_cloud.HtmlOptions()
view_options.render_options.word_processing_options = groupdocs_viewer_cloud.WordProcessingOptions()
view_options.render_options.word_processing_options.render_tracked_changes = True

request = groupdocs_viewer_cloud.CreateViewRequest(view_options)
response = view_api.create_view(request)

print("Tracked changes rendered: " + str(len(response.pages)) + " pages")

获取文档信息

在渲染之前检索文档元数据,例如页数。

import groupdocs_viewer_cloud

info_api = groupdocs_viewer_cloud.InfoApi.from_keys("YourClientId", "YourClientSecret")

view_options = groupdocs_viewer_cloud.ViewOptions()
view_options.file_info = groupdocs_viewer_cloud.FileInfo()
view_options.file_info.file_path = "SampleFiles/sample.docx"

request = groupdocs_viewer_cloud.GetInfoRequest(view_options)
result = info_api.get_info(request)

print("Document pages: " + str(len(result.pages)))

无需云存储即可转换和下载

直接渲染本地文档并接收输出文件,无需先上传到云存储。

import groupdocs_viewer_cloud

view_api = groupdocs_viewer_cloud.ViewApi.from_keys("YourClientId", "YourClientSecret")

with open("sample.docx", "rb") as file:
    request = groupdocs_viewer_cloud.ConvertAndDownloadRequest("jpg", file)
    output_path = view_api.convert_and_download(request)

print("Convert and download completed: " + output_path)

GitHub 上的示例项目

GroupDocs.Viewer Cloud Python 示例 存储库包含可立即运行的示例,涵盖:

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

如何运行示例

  1. 克隆或下载示例存储库 2.进入Examples目录
  2. 编辑RunExamples.py并设置client_idclient_secret 4.运行pip install groupdocs-viewer-cloud -U 5.执行python RunExamples.py

欲了解更多详情,请访问入门


Product Docs Swagger Examples Blog Support Dashboard


标签

Document Rendering API | Python 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



 简体中文