PDF 转 HTML
使用 PDF 转 HTML 工具,您可以将 PDF 文件转换为 HTML 文件。以下示例展示了如何使用 Java、PHP、C#、Python 和 Swift 语言上传测试 PDF 文件并将其转换为 HTML 文件。
Java
// Create a client
CPDFClient client = new CPDFClient(publicKey,secretKey);
// Create a task
// Create an example of a PDF tO Html task
CPDFCreateTaskResult result = client.createTask(CPDFConversionEnum.PDF_TO_HTML);
// Get a task id
String taskId = result.getTaskId();
// File handling parameter settings
CPDFToHtmlParameter fileParameter = new CPDFToHtmlParameter();
fileParameter.setIsContainAnnot("1");
fileParameter.setIsContainImg("1");
fileParameter.setPageOptions("2");
// Upload files
client.uploadFile(new File("test.pdf"), taskId, fileParameter);
// Execute task
client.executeTask(taskId);
// query TaskInfo
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
PHP
// Create a client
$client = new CPDFClient('public_key', 'secret_key');
// Create a task
// Create an example of a PDF tO Html task
$taskInfo = $client->createTask(CPDFConversion::PDF_TO_HTML);
// File handling parameter settings
$file = $client->addFile('test.pdf')
->setPageOptions('2')
->setIsContainImg('1')
->setIsContainAnnot('1');
// Upload files
$fileInfo = $file->uploadFile($taskInfo['taskId']);
// Execute task
$client->executeTask($taskInfo['taskId']);
// Query TaskInfo
$taskInfo = $client->getTaskInfo($taskInfo['taskId']);
C#
// Create a client
CPDFClient client = new CPDFClient(publicKey,secretKey);
// Create a task
// Create an example of a PDF tO Html task
CPDFCreateTaskResult result = client.CreateTask(CPDFConversionEnum.PDF_TO_HTML);
// Get a task id
string taskId = result.TaskId;
// File handling parameter settings
CPDFToHtmlParameter fileParameter = new CPDFToHtmlParameter();
fileParameter.IsContainImg = "1";
fileParameter.IsContainAnnot = "1";
fileParameter.PageOptions = "2";
// Upload files
client.UploadFile(new FileInfo("test.pdf"), taskId, fileParameter);
// Execute task
client.ExecuteTask(taskId);
// Query TaskInfo
CPDFTaskInfoResult taskInfo = client.GetTaskInfo(taskId);
Python
# Create a client
client = CPDFClient(public_key, secret_key)
# Create a task
# Create an example of a PDF tO Html task
create_task_result = client.create_task(CPDFConversionEnum.PDF_TO_HTML)
# Get a task id
task_id = create_task_result.task_id
# File handling parameter settings
file_parameter = CPDFToHtmlParameter()
file_parameter.is_contain_img = CPDFToHtmlParameter.IS_CONTAIN_IMG
file_parameter.is_contain_annot = CPDFToHtmlParameter.IS_CONTAIN_ANNOT
file_parameter.page_options = CPDFToHtmlParameter.SINGLE_PAGE_NAVIGATION_BY_BOOKMARKS
# Upload files
client.upload_file('test.pdf', task_id, file_parameter)
# Execute task
client.execute_task(task_id)
# Query TaskInfo
task_info = client.get_task_info(task_id)
Swift
// Create a client
let client: CPDFClient = CPDFClient(publicKey: public_key, secretKey: secret_key)
Task { @MainActor in
// Create a task
// Create an example of a PDF tO Html task
let taskModel = await client.createTask(url: CPDFConversion.PDF_TO_HTML)
// Get a task id
let taskId = taskModel?.taskId ?? ""
// Upload files
let path = Bundle.main.path(forResource: "test", ofType: "pdf")
let uploadFileModel = await client.uploadFile(filepath: path ?? "", password: "", params: [
CPDFFileUploadParameterKey.pageOptions.string() : "2",
CPDFFileUploadParameterKey.isContainAnnot.string() : "1",
CPDFFileUploadParameterKey.isContainImg.string() : "1"
], taskId: taskId)
// Execute task
let _ = await client.processFiles(taskId: taskId)
// Query TaskInfo
let taskInfoModel = await client.getTaskInfo(taskId: taskId)
}
所需参数:
pageOptions:1:
SinglePage
,2:SinglePageNavigationByBookmarks
,3:MultiplePages
,4:MultiplePagesSplitByBookmarks
。isContainImg
:是否包含图片(1:是,0:否)。isContainAnnot
:是否包含评论(1:是,0:否)。
结果:
文件类型 | 说明 |
---|---|
.zip | 完成后的 HTML 文件夹。 |