├── src ├── Constant │ ├── CPDFLanguage.php │ ├── CPDFDocumentAI.php │ ├── CPDFDocumentEditor.php │ ├── CPDFURL.php │ └── CPDFConversion.php ├── Resource │ ├── CPDFTaskResource.php │ └── CPDFFileResource.php ├── Util │ └── CPDFUtil.php ├── Exception │ └── CPDFException.php └── Client │ ├── CPDFHttpClient.php │ └── CPDFClient.php ├── composer.json ├── samples ├── CSVToPDF.php ├── PNGToPDF.php ├── RTFToPDF.php ├── TXTToPDF.php ├── TrimCorrection.php ├── HTMLToPDF.php ├── PDFToTXT.php ├── PPTToPDF.php ├── WordToPDF.php ├── ExcelToPDF.php ├── PDFToPNG.php ├── StampInspection.php ├── LayoutAnalysis.php ├── ImageSharpeningEnhancement.php ├── DeleteWatermark.php ├── OCR.php ├── PDFToCSV.php ├── PDFToJPG.php ├── FormRecognizer.php ├── PDFCompression.php ├── PDFDelete.php ├── PDFExtract.php ├── PDFSplit.php ├── PDFToRTF.php ├── PDFToPPT.php ├── PDFRotation.php ├── PDFToHTML.php ├── PDFToWord.php ├── PDFInsert.php ├── PDFToExcel.php ├── PDFMerge.php └── AddWatermark.php └── README.md /src/Constant/CPDFLanguage.php: -------------------------------------------------------------------------------- 1 | taskId = $taskId; 12 | } 13 | 14 | 15 | } -------------------------------------------------------------------------------- /src/Util/CPDFUtil.php: -------------------------------------------------------------------------------- 1 | step = $step; 16 | parent::__construct($message, $code, $previous); 17 | } 18 | 19 | public function __toString() 20 | { 21 | return "$this->code# step:$this->step; message:$this->message"; 22 | } 23 | } -------------------------------------------------------------------------------- /src/Constant/CPDFURL.php: -------------------------------------------------------------------------------- 1 | =7.0", 15 | "guzzlehttp/guzzle": ">=6.5", 16 | "ext-json": "*", 17 | "ext-curl": "*" 18 | }, 19 | "require-dev" : { 20 | "guzzlehttp/guzzle": ">=6.5" 21 | }, 22 | "minimum-stability": "stable", 23 | "autoload": { 24 | "psr-4": {"ComPDFKit\\": "src"} 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Constant/CPDFConversion.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::CSV_TO_PDF); 13 | 14 | //Upload files 15 | $fileInfo = $client->addFile('test.csv')->uploadFile($taskInfo['taskId']); 16 | 17 | //execute Task 18 | $client->executeTask($taskInfo['taskId']); 19 | 20 | //query TaskInfo 21 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 22 | 23 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 24 | sleep(5); 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | } 27 | 28 | print_r($taskInfo); 29 | } catch (CPDFException $e) { 30 | echo $e->getMessage(); 31 | } -------------------------------------------------------------------------------- /samples/PNGToPDF.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::PNG_TO_PDF); 13 | 14 | //Upload files 15 | $fileInfo = $client->addFile('test.png')->uploadFile($taskInfo['taskId']); 16 | 17 | //execute Task 18 | $client->executeTask($taskInfo['taskId']); 19 | 20 | //query TaskInfo 21 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 22 | 23 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 24 | sleep(5); 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | } 27 | 28 | print_r($taskInfo); 29 | } catch (CPDFException $e) { 30 | echo $e->getMessage(); 31 | } -------------------------------------------------------------------------------- /samples/RTFToPDF.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::RTF_TO_PDF); 13 | 14 | //Upload files 15 | $fileInfo = $client->addFile('test.rtf')->uploadFile($taskInfo['taskId']); 16 | 17 | //execute Task 18 | $client->executeTask($taskInfo['taskId']); 19 | 20 | //query TaskInfo 21 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 22 | 23 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 24 | sleep(5); 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | } 27 | 28 | print_r($taskInfo); 29 | } catch (CPDFException $e) { 30 | echo $e->getMessage(); 31 | } -------------------------------------------------------------------------------- /samples/TXTToPDF.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::TXT_TO_PDF); 13 | 14 | //Upload files 15 | $fileInfo = $client->addFile('test.txt')->uploadFile($taskInfo['taskId']); 16 | 17 | //execute Task 18 | $client->executeTask($taskInfo['taskId']); 19 | 20 | //query TaskInfo 21 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 22 | 23 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 24 | sleep(5); 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | } 27 | 28 | print_r($taskInfo); 29 | } catch (CPDFException $e) { 30 | echo $e->getMessage(); 31 | } -------------------------------------------------------------------------------- /samples/TrimCorrection.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentAI::DEWARP); 13 | 14 | //Upload files 15 | $fileInfo = $client->addFile('test.jpg')->uploadFile($taskInfo['taskId']); 16 | 17 | //execute Task 18 | $client->executeTask($taskInfo['taskId']); 19 | 20 | //query TaskInfo 21 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 22 | 23 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 24 | sleep(5); 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | } 27 | 28 | print_r($taskInfo); 29 | } catch (CPDFException $e) { 30 | echo $e->getMessage(); 31 | } -------------------------------------------------------------------------------- /samples/HTMLToPDF.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::HTML_TO_PDF); 13 | 14 | //Upload files 15 | $fileInfo = $client->addFile('test.html')->uploadFile($taskInfo['taskId']); 16 | 17 | //execute Task 18 | $client->executeTask($taskInfo['taskId']); 19 | 20 | //query TaskInfo 21 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 22 | 23 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 24 | sleep(5); 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | } 27 | 28 | print_r($taskInfo); 29 | } catch (CPDFException $e) { 30 | echo $e->getMessage(); 31 | } -------------------------------------------------------------------------------- /samples/PDFToTXT.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::PDF_TO_TXT); 14 | 15 | //Upload files 16 | $fileInfo = $client->addFile('test.pdf')->uploadFile($taskInfo['taskId']); 17 | 18 | //execute Task 19 | $client->executeTask($taskInfo['taskId']); 20 | 21 | //query TaskInfo 22 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 23 | 24 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 25 | sleep(5); 26 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 27 | } 28 | 29 | print_r($taskInfo);die; 30 | }catch (CPDFException $e){ 31 | echo $e->getMessage(); 32 | } -------------------------------------------------------------------------------- /samples/PPTToPDF.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::PPTX_TO_PDF); 13 | 14 | //Upload files 15 | $fileInfo = $client->addFile('test.pptx')->uploadFile($taskInfo['taskId']); 16 | 17 | //execute Task 18 | $client->executeTask($taskInfo['taskId']); 19 | 20 | //query TaskInfo 21 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 22 | 23 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 24 | sleep(5); 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | } 27 | 28 | print_r($taskInfo); 29 | } catch (CPDFException $e) { 30 | echo $e->getMessage(); 31 | } -------------------------------------------------------------------------------- /samples/WordToPDF.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::DOCX_TO_PDF); 13 | 14 | //Upload files 15 | $fileInfo = $client->addFile('test.docx')->uploadFile($taskInfo['taskId']); 16 | 17 | //execute Task 18 | $client->executeTask($taskInfo['taskId']); 19 | 20 | //query TaskInfo 21 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 22 | 23 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 24 | sleep(5); 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | } 27 | 28 | print_r($taskInfo); 29 | } catch (CPDFException $e) { 30 | echo $e->getMessage(); 31 | } -------------------------------------------------------------------------------- /samples/ExcelToPDF.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::XLSX_TO_PDF); 13 | 14 | //Upload files 15 | $fileInfo = $client->addFile('test.xlsx')->uploadFile($taskInfo['taskId']); 16 | 17 | //execute Task 18 | $client->executeTask($taskInfo['taskId']); 19 | 20 | //query TaskInfo 21 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 22 | 23 | 24 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 25 | sleep(5); 26 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 27 | } 28 | 29 | print_r($taskInfo); 30 | } catch (CPDFException $e) { 31 | echo $e->getMessage(); 32 | } -------------------------------------------------------------------------------- /samples/PDFToPNG.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::PDF_TO_PNG); 14 | 15 | // Upload files 16 | $fileInfo = $client->addFile('test.pdf')->uploadFile($taskInfo['taskId']); 17 | 18 | //execute Task 19 | $client->executeTask($taskInfo['taskId']); 20 | 21 | //query TaskInfo 22 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 23 | 24 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 25 | sleep(5); 26 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 27 | } 28 | 29 | print_r($taskInfo);die; 30 | }catch (CPDFException $e){ 31 | echo $e->getMessage(); 32 | } -------------------------------------------------------------------------------- /samples/StampInspection.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentAI::DETECTIONSTAMP); 13 | 14 | //Upload files 15 | $fileInfo = $client->addFile('test.jpg')->uploadFile($taskInfo['taskId']); 16 | 17 | //execute Task 18 | $client->executeTask($taskInfo['taskId']); 19 | 20 | //query TaskInfo 21 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 22 | 23 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 24 | sleep(5); 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | } 27 | 28 | print_r($taskInfo); 29 | } catch (CPDFException $e) { 30 | echo $e->getMessage(); 31 | } -------------------------------------------------------------------------------- /samples/LayoutAnalysis.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentAI::LAYOUTANALYSIS); 13 | 14 | //Upload files 15 | $fileInfo = $client->addFile('test.jpg')->uploadFile($taskInfo['taskId']); 16 | 17 | //execute Task 18 | $client->executeTask($taskInfo['taskId']); 19 | 20 | //query TaskInfo 21 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 22 | 23 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 24 | sleep(5); 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | } 27 | 28 | print_r($taskInfo);die; 29 | } catch (CPDFException $e) { 30 | echo $e->getMessage(); 31 | } -------------------------------------------------------------------------------- /samples/ImageSharpeningEnhancement.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentAI::MAGICCOLOR); 13 | 14 | //Upload files 15 | $fileInfo = $client->addFile('test.jpg')->uploadFile($taskInfo['taskId']); 16 | 17 | //execute Task 18 | $client->executeTask($taskInfo['taskId']); 19 | 20 | //query TaskInfo 21 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 22 | 23 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 24 | sleep(5); 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | } 27 | 28 | print_r($taskInfo);die; 29 | } catch (CPDFException $e) { 30 | echo $e->getMessage(); 31 | } -------------------------------------------------------------------------------- /samples/DeleteWatermark.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentEditor::DEL_WATERMARK); 14 | 15 | //Upload files 16 | $fileInfo = $client->addFile('test.pdf')->uploadFile($taskInfo['taskId']); 17 | 18 | //execute Task 19 | $client->executeTask($taskInfo['taskId']); 20 | 21 | //query TaskInfo 22 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 23 | 24 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 25 | sleep(5); 26 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 27 | } 28 | 29 | print_r($taskInfo); 30 | } catch (CPDFException $e) { 31 | echo $e->getMessage(); 32 | } -------------------------------------------------------------------------------- /samples/OCR.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentAI::OCR); 13 | 14 | // File handling parameter settings 15 | $file = $client->addFile('test.jpg') 16 | ->setLang('auto'); 17 | 18 | //Upload files 19 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 20 | 21 | //execute Task 22 | $client->executeTask($taskInfo['taskId']); 23 | 24 | //query TaskInfo 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | 27 | 28 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 29 | sleep(5); 30 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 31 | } 32 | 33 | print_r($taskInfo);die; 34 | } catch (CPDFException $e) { 35 | echo $e->getMessage(); 36 | } -------------------------------------------------------------------------------- /samples/PDFToCSV.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::PDF_TO_CSV); 13 | 14 | // File handling parameter settings 15 | $file = $client->addFile('test.pdf') 16 | ->setIsCsvMerge('1'); 17 | 18 | //Upload files 19 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 20 | 21 | //execute Task 22 | $client->executeTask($taskInfo['taskId']); 23 | 24 | //query TaskInfo 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | 27 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 28 | sleep(5); 29 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 30 | } 31 | 32 | print_r($taskInfo);die; 33 | } catch (CPDFException $e) { 34 | echo $e->getMessage(); 35 | } -------------------------------------------------------------------------------- /samples/PDFToJPG.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::PDF_TO_JPG); 14 | 15 | // File handling parameter settings 16 | $file = $client->addFile('test.pdf') 17 | ->setImgDpi('300'); 18 | 19 | //Upload files 20 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 21 | 22 | //execute Task 23 | $client->executeTask($taskInfo['taskId']); 24 | 25 | //query TaskInfo 26 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 27 | 28 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 29 | sleep(5); 30 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 31 | } 32 | 33 | print_r($taskInfo);die; 34 | }catch (CPDFException $e){ 35 | echo $e->getMessage(); 36 | } -------------------------------------------------------------------------------- /samples/FormRecognizer.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentAI::TABLEREC); 13 | 14 | // File handling parameter settings 15 | $file = $client->addFile('test.jpg') 16 | ->setLang('auto'); 17 | 18 | //Upload files 19 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 20 | 21 | //execute Task 22 | $client->executeTask($taskInfo['taskId']); 23 | 24 | //query TaskInfo 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | 27 | 28 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 29 | sleep(5); 30 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 31 | } 32 | 33 | print_r($taskInfo);die; 34 | } catch (CPDFException $e) { 35 | echo $e->getMessage(); 36 | } -------------------------------------------------------------------------------- /samples/PDFCompression.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentEditor::COMPRESS); 13 | 14 | // File handling parameter settings 15 | $file = $client->addFile('test.pdf') 16 | ->setQuality('50'); 17 | 18 | //Upload files 19 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 20 | 21 | //execute Task 22 | $client->executeTask($taskInfo['taskId']); 23 | 24 | //query TaskInfo 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | 27 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 28 | sleep(5); 29 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 30 | } 31 | 32 | print_r($taskInfo); 33 | } catch (CPDFException $e) { 34 | echo $e->getMessage(); 35 | } -------------------------------------------------------------------------------- /samples/PDFDelete.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentEditor::DELETE); 13 | 14 | //File handling parameter settings 15 | $file = $client->addFile('test.pdf') 16 | ->setPageOptions(['1', '2']); 17 | 18 | //Upload files 19 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 20 | 21 | //execute Task 22 | $client->executeTask($taskInfo['taskId']); 23 | 24 | //query TaskInfo 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | 27 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 28 | sleep(5); 29 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 30 | } 31 | 32 | print_r($taskInfo); 33 | } catch (CPDFException $e) { 34 | echo $e->getMessage(); 35 | } -------------------------------------------------------------------------------- /samples/PDFExtract.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentEditor::EXTRACT); 13 | 14 | // File handling parameter settings 15 | $file = $client->addFile('test.pdf') 16 | ->setPageOptions(['1', '2']); 17 | 18 | //Upload files 19 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 20 | 21 | //execute Task 22 | $client->executeTask($taskInfo['taskId']); 23 | 24 | //query TaskInfo 25 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 26 | 27 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 28 | sleep(5); 29 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 30 | } 31 | 32 | print_r($taskInfo); 33 | } catch (CPDFException $e) { 34 | echo $e->getMessage(); 35 | } -------------------------------------------------------------------------------- /samples/PDFSplit.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentEditor::SPLIT); 14 | 15 | // File handling parameter settings 16 | $file = $client->addFile('test.pdf') 17 | ->setPageOptions(['1', '2-3']); 18 | 19 | //Upload files 20 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 21 | 22 | //execute Task 23 | $client->executeTask($taskInfo['taskId']); 24 | 25 | //query TaskInfo 26 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 27 | 28 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 29 | sleep(5); 30 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 31 | } 32 | 33 | print_r($taskInfo); 34 | } catch (CPDFException $e) { 35 | echo $e->getMessage(); 36 | } -------------------------------------------------------------------------------- /samples/PDFToRTF.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::PDF_TO_RTF); 14 | 15 | // File handling parameter settings 16 | $file = $client->addFile('test.pdf') 17 | ->setIsContainImg('1') 18 | ->setIsContainAnnot('1'); 19 | 20 | //Upload files 21 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 22 | 23 | //execute Task 24 | $client->executeTask($taskInfo['taskId']); 25 | 26 | //query TaskInfo 27 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 28 | 29 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 30 | sleep(5); 31 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 32 | } 33 | 34 | print_r($taskInfo);die; 35 | }catch (CPDFException $e){ 36 | echo $e->getMessage(); 37 | } -------------------------------------------------------------------------------- /samples/PDFToPPT.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::PDF_TO_PPT); 14 | 15 | // File handling parameter settings 16 | $file = $client->addFile('test.pdf') 17 | ->setIsContainImg('1') 18 | ->setIsContainAnnot('1'); 19 | 20 | //Upload files 21 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 22 | 23 | //execute Task 24 | $client->executeTask($taskInfo['taskId']); 25 | 26 | //query TaskInfo 27 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 28 | 29 | 30 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 31 | sleep(5); 32 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 33 | } 34 | 35 | print_r($taskInfo);die; 36 | }catch (CPDFException $e){ 37 | echo $e->getMessage(); 38 | } -------------------------------------------------------------------------------- /samples/PDFRotation.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentEditor::ROTATION); 14 | 15 | // File handling parameter settings 16 | $file = $client->addFile('test.pdf') 17 | ->setPageOptions(['1', '2']) 18 | ->setRotation('90'); 19 | 20 | //Upload files 21 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 22 | 23 | //execute Task 24 | $client->executeTask($taskInfo['taskId']); 25 | 26 | //query TaskInfo 27 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 28 | 29 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 30 | sleep(5); 31 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 32 | } 33 | 34 | print_r($taskInfo); 35 | } catch (CPDFException $e) { 36 | echo $e->getMessage(); 37 | } -------------------------------------------------------------------------------- /samples/PDFToHTML.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::PDF_TO_HTML); 14 | 15 | // File handling parameter settings 16 | $file = $client->addFile('test.pdf') 17 | ->setPageOptions('2') 18 | ->setIsContainImg('1') 19 | ->setIsContainAnnot('1'); 20 | 21 | //Upload files 22 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 23 | 24 | //execute Task 25 | $client->executeTask($taskInfo['taskId']); 26 | 27 | //query TaskInfo 28 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 29 | 30 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 31 | sleep(5); 32 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 33 | } 34 | 35 | print_r($taskInfo);die; 36 | }catch (CPDFException $e){ 37 | echo $e->getMessage(); 38 | } -------------------------------------------------------------------------------- /samples/PDFToWord.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::PDF_TO_WORD); 14 | 15 | // File handling parameter settings 16 | $file = $client->addFile('test.pdf') 17 | ->setIsContainAnnot('1') 18 | ->setIsContainImg('1') 19 | ->setIsFlowLayout('1'); 20 | 21 | //Upload files 22 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 23 | 24 | //execute Task 25 | $client->executeTask($taskInfo['taskId']); 26 | 27 | //query TaskInfo 28 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 29 | 30 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 31 | sleep(5); 32 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 33 | } 34 | 35 | print_r($taskInfo);die; 36 | }catch (CPDFException $e){ 37 | echo $e->getMessage(); 38 | } -------------------------------------------------------------------------------- /samples/PDFInsert.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentEditor::INSERT); 13 | 14 | // File handling parameter settings 15 | $file = $client->addFile('test.pdf') 16 | ->setTargetPage('1') 17 | ->setWidth('500') 18 | ->setHeight('800') 19 | ->setNumber('2'); 20 | 21 | //Upload files 22 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 23 | 24 | //execute Task 25 | $client->executeTask($taskInfo['taskId']); 26 | 27 | //query TaskInfo 28 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 29 | 30 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 31 | sleep(5); 32 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 33 | } 34 | 35 | print_r($taskInfo); 36 | } catch (CPDFException $e) { 37 | echo $e->getMessage(); 38 | } -------------------------------------------------------------------------------- /samples/PDFToExcel.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFConversion::PDF_TO_EXCEL); 13 | 14 | // File handling parameter settings 15 | $file = $client->addFile('test.pdf') 16 | ->setIsContainAnnot('1') 17 | ->setIsContainImg('1') 18 | ->setContentOptions('2') 19 | ->setWorksheetOptions('1'); 20 | 21 | //Upload files 22 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 23 | 24 | //execute Task 25 | $client->executeTask($taskInfo['taskId']); 26 | 27 | //query TaskInfo 28 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 29 | 30 | while ($taskInfo['taskStatus'] != 'TaskFinish'){ 31 | sleep(5); 32 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 33 | } 34 | 35 | print_r($taskInfo);die; 36 | } catch (CPDFException $e) { 37 | echo $e->getMessage(); 38 | } -------------------------------------------------------------------------------- /samples/PDFMerge.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentEditor::MERGE); 13 | 14 | // File handling parameter settings 15 | $fileOne = $client->addFile('test.pdf') 16 | ->setPageOptions(['1', '2']); 17 | 18 | //Upload files 19 | $fileInfoOne = $fileOne->uploadFile($taskInfo['taskId']); 20 | 21 | // File handling parameter settings 22 | $fileTwo = $client->addFile('test.pdf') 23 | ->setPageOptions(['2']); 24 | 25 | //Upload files 26 | $fileInfoTwo = $fileTwo->uploadFile($taskInfo['taskId']); 27 | 28 | //execute Task 29 | $client->executeTask($taskInfo['taskId']); 30 | 31 | //query TaskInfo 32 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 33 | 34 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 35 | sleep(5); 36 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 37 | } 38 | 39 | print_r($taskInfo); 40 | } catch (CPDFException $e) { 41 | echo $e->getMessage(); 42 | } -------------------------------------------------------------------------------- /src/Client/CPDFHttpClient.php: -------------------------------------------------------------------------------- 1 | $stack]); 30 | 31 | $url = $this->baseUrl . $url; 32 | 33 | $body = ['headers' => $headers, 'timeout' => 60]; 34 | if(!empty($options)){ 35 | if(isset($options['multipart'])){ 36 | $body['multipart'] = $options['multipart']; 37 | }else{ 38 | if($method == CPDFURL::HTTP_METHOD_POST){ 39 | $body['headers']['Content-Type'] = 'application/json'; 40 | $body['json'] = $options; 41 | }elseif($method == CPDFURL::HTTP_METHOD_GET){ 42 | $body['headers']['Content-Type'] = 'application/json'; 43 | $body['query'] = $options; 44 | } 45 | } 46 | } 47 | 48 | try{ 49 | $response = $client->request($method, $url, $body); 50 | }catch (GuzzleException $e){ 51 | $message = 'HTTP Client Error: ' . $e->getMessage(); 52 | throw new CPDFException($step, $message); 53 | } 54 | 55 | if($response->getStatusCode() != 200){ 56 | $message = 'HTTP Server Error'; 57 | throw new CPDFException($step, $message, $response->getStatusCode()); 58 | } 59 | 60 | $result = json_decode($response->getBody()->getContents(), true); 61 | 62 | if($result['code'] != 200){ 63 | throw new CPDFException($step, $result['msg'], $result['code']); 64 | } 65 | 66 | return $result['data']; 67 | } 68 | } -------------------------------------------------------------------------------- /samples/AddWatermark.php: -------------------------------------------------------------------------------- 1 | createTask(CPDFDocumentEditor::ADD_WATERMARK); 19 | 20 | //File handling parameter settings 21 | $file = $client->addFile('test.pdf') 22 | ->setTextColor('#59c5bb') 23 | ->setType('text') 24 | ->setContent('text') 25 | ->setScale('1') 26 | ->setOpacity('0.5') 27 | ->setRotation('0.785') 28 | ->setTargetPages('1-2') 29 | ->setVertalign('center') 30 | ->setHorizalign('left') 31 | ->setXOffset('100') 32 | ->setYOffset('100') 33 | ->setFullScreen('1') 34 | ->setHorizontalSpace('10') 35 | ->setVerticalSpace('10'); 36 | 37 | //Upload files 38 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 39 | 40 | //execute Task 41 | $client->executeTask($taskInfo['taskId']); 42 | 43 | //query TaskInfo 44 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 45 | 46 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 47 | sleep(5); 48 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 49 | } 50 | 51 | print_r($taskInfo); 52 | }catch (CPDFException $e) { 53 | echo $e->getMessage(); 54 | } 55 | } 56 | 57 | function addWatermarkTextImage(){ 58 | $client = new CPDFClient('public_key', 'secret_key'); 59 | 60 | try{ 61 | //Create a task 62 | $taskInfo = $client->createTask(CPDFDocumentEditor::ADD_WATERMARK); 63 | 64 | //File handling parameter settings 65 | $file = $client->addFile('test.pdf') 66 | ->setType('image') 67 | //Set Watermark Image 68 | ->setImagePath('3.jpg') 69 | ->setScale('0.5') 70 | ->setOpacity('0.5') 71 | ->setRotation('45') 72 | ->setTargetPages('1-2') 73 | ->setVertalign('center') 74 | ->setHorizalign('left') 75 | ->setXOffset('50') 76 | ->setYOffset('50') 77 | ->setFullScreen('1') 78 | ->setHorizontalSpace('100') 79 | ->setVerticalSpace('100') 80 | ->setFront('1'); 81 | 82 | //Upload files 83 | $fileInfo = $file->uploadFile($taskInfo['taskId']); 84 | 85 | //execute Task 86 | $client->executeTask($taskInfo['taskId']); 87 | 88 | //query TaskInfo 89 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 90 | 91 | while ($taskInfo['taskStatus'] != 'TaskFinish') { 92 | sleep(5); 93 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 94 | } 95 | 96 | print_r($taskInfo); 97 | }catch (CPDFException $e) { 98 | echo $e->getMessage(); 99 | } 100 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ComPDFKit API in PHP 2 | 3 | ## Introduction 4 | 5 | [ComPDFKit](https://www.compdf.com/) offers powerful and steady PDF libraries and complete PDF functions to build PDF viewer and editor, which allows to preview, edit, annotate, sign, encrypt and decrypt PDF files. 6 | 7 | [ComPDFKit API](https://api.compdf.com/api-reference/overview) provides a variety of PHP API tools that allow you to create an efficient document processing workflow in a single API call. 8 | 9 | ComPDFKit API allows you to get 1000 files processing monthly now! Just [sign up](https://api.compdf.com/signup) for a free trial and enjoy comprehensive PDF functions. 10 | 11 | ### Related 12 | 13 | - ComPDFKit API - Java Library: [ComPDFKit API - Java Library](https://github.com/ComPDFKit/compdfkit-api-java) 14 | - ComPDFKit API - Swift Library: [ComPDFKit API - Swift Library](https://github.com/ComPDFKit/compdfkit-api-swift) 15 | - ComPDFKit API - Python Library: [ComPDFKit API - Python Library](https://github.com/ComPDFKit/compdfkit-api-python) 16 | - ComPDFKit API - C#.NET Library: [ComPDFKit API - C#.NET Library](https://github.com/ComPDFKit/compdfkit-api-.net) 17 | 18 | ## Requirements 19 | 20 | Programming Environment: PHP Version 7.0 and higher. 21 | 22 | Dependencies: Composer. 23 | 24 | ## Installation 25 | 26 | You can install the library via Composer. Run the following command. 27 | 28 | ``` shell script 29 | composer require compdfkit/compdfkit-api-php 30 | ``` 31 | 32 | Alternatively, you can add "compdfkit/compdfkit-api-php": "^1.2.4" to your ***"composer.json"*** file and then run it. 33 | 34 | ``` shell script 35 | composer update 36 | ``` 37 | 38 | If you are not using a PHP framework with autoload feature, you need to use the code below to autoload. 39 | 40 | ```php 41 | require_once('vendor/autoload.php'); 42 | ``` 43 | 44 | ## Usage 45 | 46 | ### Create An API Client 47 | 48 | First of all, please create an API client to complete the authentication. You need to [sign in](https://api.compdf.com/login) your ComPDFKit API account to get your **publicKey** and **secretKey** at the [dashboard](https://api-dashboard.compdf.com/api/keys). If you are new to ComPDFKit, click here to [sign up](https://api.compdf.com/signup) for a free trial to process 1,000 documents per month for free. 49 | 50 | - Project public Key: You can find the public key in the **API Keys** section of your ComPDFKit API account. 51 | 52 | - Project secret Key: You can find the secret Key in the **API Keys** section of your ComPDFKit API account. 53 | 54 | ```php 55 | $client = new CPDFClient('public_key', 'secret_key'); 56 | ``` 57 | 58 | ### Create A Task 59 | 60 | A task ID is automatically generated for you based on the type of PDF tool you choose. You can provide the callback notification URL. After the task processing is completed, we will notify you of the task result through the callback interface. You can perform other operations according to the request result, such as checking the status of the task, uploading files, starting the task, or downloading the result file. 61 | 62 | ```php 63 | // Create a client 64 | $client = new CPDFClient('public_key', 'secret_key'); 65 | 66 | // Create a task 67 | // Create an example of a PDF TO WORD task 68 | $taskInfo = $client->createTask(CPDFConversion::PDF_TO_WORD); 69 | ``` 70 | 71 | ### Upload Files 72 | 73 | Upload the original file and bind the file to the task ID. The field parameter is used to pass the JSON string to set the processing parameters for the file. Each file will generate automatically a unique filekey. Please note that a maximum of five files can be uploaded for a task ID and no files can be uploaded for that task after it has started. 74 | 75 | ```php 76 | // Create a client 77 | $client = new CPDFClient('public_key', 'secret_key'); 78 | 79 | // Create a task 80 | // Create an example of a PDF TO WORD task 81 | $taskInfo = $client->createTask(CPDFConversion::PDF_TO_WORD); 82 | 83 | // Upload files 84 | $file = $client->addFile('test.pdf')->uploadFile($taskInfo['taskId']); 85 | ``` 86 | 87 | ### Execute the Task 88 | 89 | After the file upload is completed, call this interface with the task ID to process the files. 90 | 91 | ```php 92 | // Create a client 93 | $client = new CPDFClient('public_key', 'secret_key'); 94 | 95 | // Create a task 96 | // Create an example of a PDF TO WORD task 97 | $taskInfo = $client->createTask(CPDFConversion::PDF_TO_WORD); 98 | 99 | // Upload files 100 | $file = $client->addFile('test.pdf')->uploadFile($taskInfo['taskId']); 101 | 102 | // execute Task 103 | $client->executeTask($taskInfo['taskId']); 104 | ``` 105 | 106 | ### Get The Task Info 107 | 108 | Request task status and file-related meta data based on the task ID. 109 | 110 | ```php 111 | // Create a client 112 | $client = new CPDFClient('public_key', 'secret_key'); 113 | 114 | // Create a task 115 | // Create an example of a PDF TO WORD task 116 | $taskInfo = $client->createTask(CPDFConversion::PDF_TO_WORD); 117 | 118 | // Upload files 119 | $file = $client->addFile('test.pdf')->uploadFile($taskInfo['taskId']); 120 | 121 | // Execute Task 122 | $client->executeTask($taskInfo['taskId']); 123 | 124 | // Query TaskInfo 125 | $taskInfo = $client->getTaskInfo($taskInfo['taskId']); 126 | ``` 127 | 128 | ## Examples 129 | 130 | There are many examples in the **samples** folder, which show the main features of the ComPDFKit API and how to use them, such as watermarking PDFs, converting PDF to Word, Excel, JPG, PNG, etc. You can copy the code to your project and run it directly. To learn more about the ComPDFKit API, please visit our [API Reference](https://api.compdf.com/api-reference/overview). 131 | 132 | ## Free Trial 133 | 134 | [ComPDFKit API](https://api.compdf.com/) is a powerful API that can be used to create an efficient document processing workflow in a single API call. 135 | 136 | If you do not have a ComPDFKit API account, you can [sign up for a free trial](https://api.compdf.com/signup) to process 1,000 documents per month for free. 137 | 138 | Once you have a ComPDFKit API account, you can obtain your **publicKey** and **secretKey** in the [dashboard](https://api-dashboard.compdf.com/api/keys). 139 | 140 | ## Support 141 | 142 | [ComPDFKit](https://www.compdf.com/) has a professional R&D team that produces comprehensive technical documentation and guides to help developers. Also, you can get an immediate response when reporting your problems to our support team. 143 | 144 | For detailed information, please visit our [Guides page](https://api.compdf.com/api/docs/guides). 145 | 146 | Stay updated with the latest improvements through our [Changelog](https://www.compdf.com/api/changelog-compdfkit-api). 147 | 148 | For technical assistance, please reach out to our [Technical Support](https://www.compdf.com/support). 149 | 150 | To get more details and an accurate quote, please contact our [Sales Team](https://www.compdf.com/contact-sales). 151 | 152 | ## License 153 | 154 | * The code is available as open source under the terms of the [Apache-2.0 License](https://opensource.org/license/apache-2-0). -------------------------------------------------------------------------------- /src/Client/CPDFClient.php: -------------------------------------------------------------------------------- 1 | publicKey = $publicKey; 28 | $this->secretKey = $secretKey; 29 | 30 | $this->httpClient = new CPDFHttpClient(); 31 | } 32 | 33 | /** 34 | * @param $accessToken 35 | * @param $expireIn 36 | */ 37 | public function setAccessToken($accessToken, $expireIn){ 38 | $this->accessToken = $accessToken; 39 | $this->expireTime = CPDFUtil::getMillisecond() + $expireIn * 1000 - 5; 40 | } 41 | 42 | /** 43 | * @return mixed 44 | * @throws CPDFException 45 | */ 46 | public function getAccessToken(){ 47 | $time = CPDFUtil::getMillisecond(); 48 | 49 | if(!$this->accessToken || $time > $this->expireTime){ 50 | $this->refreshToken(); 51 | } 52 | 53 | return $this->accessToken; 54 | } 55 | 56 | /** 57 | * @throws CPDFException 58 | */ 59 | public function refreshToken(){ 60 | $tokenInfo = $this->getComPDFKitAuth(); 61 | $this->setAccessToken($tokenInfo['accessToken'], $tokenInfo['expiresIn']); 62 | } 63 | 64 | /** 65 | * @return mixed 66 | * @throws CPDFException 67 | */ 68 | public function getComPDFKitAuth(){ 69 | $options = ['publicKey' => $this->publicKey, 'secretKey' => $this->secretKey]; 70 | 71 | return $this->httpClient->send('POST', CPDFURL::API_V1_OAUTH_TOKEN, [], $options); 72 | } 73 | 74 | /** 75 | * @return mixed 76 | * @throws CPDFException 77 | */ 78 | public function getSupportTools(){ 79 | return $this->httpClient->send('GET', CPDFURL::API_V1_TOOL_SUPPORT); 80 | } 81 | 82 | /** 83 | * @return array 84 | * @throws CPDFException 85 | */ 86 | public function getAuthorization(){ 87 | return ['Authorization' => 'Bearer ' . $this->getAccessToken()]; 88 | } 89 | 90 | /** 91 | * @param $fileKey 92 | * @param null $language 1:English, 2:Chinese 93 | * @return mixed 94 | * @throws CPDFException 95 | */ 96 | public function getFileInfoByKey($fileKey, $language = null){ 97 | $options = ['fileKey'=>$fileKey]; 98 | if($language){ 99 | $options['language'] = $language; 100 | } 101 | 102 | return $this->httpClient->send(CPDFURL::HTTP_METHOD_GET, CPDFURL::API_V1_FILE_INFO, $this->getAuthorization(), $options); 103 | } 104 | 105 | /** 106 | * @return mixed 107 | * @throws CPDFException 108 | */ 109 | public function getAssetInfo(){ 110 | return $this->httpClient->send(CPDFURL::HTTP_METHOD_GET, CPDFURL::API_V1_ASSET_INFO, $this->getAuthorization()); 111 | } 112 | 113 | /** 114 | * @param string $page 115 | * @param string $size 116 | * @return mixed 117 | * @throws CPDFException 118 | */ 119 | public function getTaskList($page, $size){ 120 | $options = ['page'=>$page, 'size'=>$size]; 121 | 122 | return $this->httpClient->send(CPDFURL::HTTP_METHOD_GET, CPDFURL::API_V1_TASK_LIST, $this->getAuthorization(), $options); 123 | } 124 | 125 | /** 126 | * @param $executeType 127 | * @param int $language 1:English, 2:Chinese 128 | * @return CPDFClient 129 | * @throws CPDFException 130 | */ 131 | public function createTask($executeType, $language = null){ 132 | $url = str_replace('{executeTypeUrl}', $executeType, CPDFURL::API_V1_CREATE_TASK); 133 | 134 | $options = []; 135 | 136 | if($language){ 137 | $options['language'] = $language; 138 | } 139 | 140 | $result = $this->httpClient->send(CPDFURL::HTTP_METHOD_GET, $url, $this->getAuthorization(), $options); 141 | $taskId = $result['taskId']; 142 | 143 | $this->taskResource = new CPDFTaskResource($taskId); 144 | 145 | return $result; 146 | } 147 | 148 | /** 149 | * @param $filepath 150 | * @return CPDFFileResource 151 | */ 152 | public function addFile($filepath){ 153 | $fileSource = new CPDFFileResource($filepath, $this); 154 | $this->fileResources[] = $fileSource; 155 | 156 | return $fileSource; 157 | } 158 | 159 | /** 160 | * @param $taskId 161 | * @param $filePath 162 | * @param null $password 163 | * @param array $params 164 | * @param int $language 165 | * @return mixed 166 | * @throws CPDFException 167 | */ 168 | public function uploadFile($taskId, $filePath, $password = null, $params = [], $language = null){ 169 | if(!file_exists($filePath)){ 170 | throw new CPDFException('uploadFile', 'File does not exist.'); 171 | } 172 | 173 | $options = [ 174 | 'multipart' => [ 175 | [ 176 | 'name' => 'taskId', 177 | 'contents' => $taskId, 178 | ], 179 | [ 180 | 'name' => 'file', 181 | 'contents' => Utils::tryFopen($filePath, 'r'), 182 | 'filename' => $filePath, 183 | 'headers' => [ 184 | 'Content-Type' => '' 185 | ] 186 | ] 187 | ] 188 | ]; 189 | 190 | if(isset($params['type']) && $params['type'] == 'image' && isset($params['imagePath'])){ 191 | $options['multipart'][] = [ 192 | 'name' => 'image', 193 | 'contents' => Utils::tryFopen($params['imagePath'], 'r'), 194 | 'filename' => $params['imagePath'], 195 | 'headers' => [ 196 | 'Content-Type' => '' 197 | ] 198 | ]; 199 | unset($params['imagePath']); 200 | } 201 | 202 | if($password){ 203 | $options['multipart'][] = ['name' => 'password', 'contents' => $password]; 204 | } 205 | 206 | if(!empty($params)){ 207 | $options['multipart'][] = ['name' => 'parameter', 'contents' => json_encode($params)]; 208 | } 209 | 210 | if($language){ 211 | $options['multipart'][] = ['name' => 'language', 'contents' => $language]; 212 | } 213 | 214 | return $this->httpClient->send(CPDFURL::HTTP_METHOD_POST, CPDFURL::API_V1_UPLOAD_FILE, $this->getAuthorization(), $options); 215 | } 216 | 217 | /** 218 | * @param $taskId 219 | * @param null $language 1:English, 2:Chinese 220 | * @return CPDFClient 221 | * @throws CPDFException 222 | */ 223 | public function executeTask($taskId, $language = null){ 224 | $options = ['taskId' => $taskId]; 225 | 226 | if($language){ 227 | $options['language'] = $language; 228 | } 229 | 230 | $this->httpClient->send(CPDFURL::HTTP_METHOD_GET, CPDFURL::API_V1_EXECUTE_TASK, $this->getAuthorization(), $options); 231 | return $this; 232 | } 233 | 234 | /** 235 | * @param $taskId 236 | * @param null $language 1:English, 2:Chinese 237 | * @return mixed 238 | * @throws CPDFException 239 | */ 240 | public function getTaskInfo($taskId, $language = null){ 241 | $options = ['taskId' => $taskId]; 242 | 243 | if($language){ 244 | $options['language'] = $language; 245 | } 246 | 247 | return $this->httpClient->send(CPDFURL::HTTP_METHOD_GET, CPDFURL::API_V1_TASK_INFO, $this->getAuthorization(), $options); 248 | } 249 | } -------------------------------------------------------------------------------- /src/Resource/CPDFFileResource.php: -------------------------------------------------------------------------------- 1 | client = $client; 23 | $this->filepath = $filepath; 24 | } 25 | 26 | /** 27 | * @param string $type Watermark type (text: text type watermark, image: image type watermark) 28 | * @return $this 29 | */ 30 | public function setType($type){ 31 | $this->options['type'] = $type; 32 | 33 | return $this; 34 | } 35 | 36 | /** 37 | * @param string $scale zoom (image type attribute) 38 | * @return $this 39 | */ 40 | public function setScale($scale){ 41 | $this->options['scale'] = $scale; 42 | 43 | return $this; 44 | } 45 | 46 | /** 47 | * @param string $opacity Transparency 0~1 48 | * @return $this 49 | */ 50 | public function setOpacity($opacity){ 51 | $this->options['opacity'] = $opacity; 52 | 53 | return $this; 54 | } 55 | 56 | /** 57 | * @param string $rotation Rotation angle, a positive number means counterclockwise rotation 58 | * @return $this 59 | */ 60 | public function setRotation($rotation){ 61 | $this->options['rotation'] = $rotation; 62 | 63 | return $this; 64 | } 65 | 66 | /** 67 | * @param string $targetPages Page number, page number from start, for example: 1,2,4,6 68 | * @return $this 69 | */ 70 | public function setTargetPages($targetPages){ 71 | $this->options['targetPages'] = $targetPages; 72 | 73 | return $this; 74 | } 75 | 76 | /** 77 | * @param string $vertalign Vertical alignment: top, center, bottom 78 | * @return $this 79 | */ 80 | public function setVertalign($vertalign){ 81 | $this->options['vertalign'] = $vertalign; 82 | 83 | return $this; 84 | } 85 | 86 | /** 87 | * @param string $horizalign Horizontal alignment: left, center, right 88 | * @return $this 89 | */ 90 | public function setHorizalign($horizalign){ 91 | $this->options['horizalign'] = $horizalign; 92 | 93 | return $this; 94 | } 95 | 96 | /** 97 | * @param string $xoffset horizontal offset 98 | * @return $this 99 | */ 100 | public function setXOffset($xoffset){ 101 | $this->options['xoffset'] = $xoffset; 102 | 103 | return $this; 104 | } 105 | 106 | /** 107 | * @param string $yoffset vertical offset 108 | * @return $this 109 | */ 110 | public function setYOffset($yoffset){ 111 | $this->options['yoffset'] = $yoffset; 112 | 113 | return $this; 114 | } 115 | 116 | /** 117 | * @param string $imagePath Image watermark path 118 | * @return $this 119 | */ 120 | public function setImagePath($imagePath){ 121 | $this->options['imagePath'] = $imagePath; 122 | 123 | return $this; 124 | } 125 | 126 | /** 127 | * @param string $content Text watermark text 128 | * @return $this 129 | */ 130 | public function setContent($content){ 131 | $this->options['content'] = $content; 132 | 133 | return $this; 134 | } 135 | 136 | /** 137 | * @param string $textColor Text color, eg: #FFFFFF 138 | * @return $this 139 | */ 140 | public function setTextColor($textColor){ 141 | $this->options['textColor'] = $textColor; 142 | 143 | return $this; 144 | } 145 | 146 | /** 147 | * @param string $front Setting watermark layer 148 | * "0" false: No need to pin it to the top 149 | * "1" true: Pin it to the top 150 | * null No need to pin it to the top 151 | * @return $this 152 | */ 153 | public function setFront($front){ 154 | $this->options['front'] = $front; 155 | 156 | return $this; 157 | } 158 | 159 | /** 160 | * @param string $fullScreen Whether to fill the entire page 161 | * @return $this 162 | */ 163 | public function setFullScreen($fullScreen){ 164 | $this->options['fullScreen'] = $fullScreen; 165 | 166 | return $this; 167 | } 168 | 169 | /** 170 | * @param string $horizontalSpace horizontal spacing 171 | * @return $this 172 | */ 173 | public function setHorizontalSpace($horizontalSpace){ 174 | $this->options['horizontalSpace'] = $horizontalSpace; 175 | 176 | return $this; 177 | } 178 | 179 | /** 180 | * @param string $verticalSpace vertical spacing 181 | * @return $this 182 | */ 183 | public function setVerticalSpace($verticalSpace){ 184 | $this->options['verticalSpace'] = $verticalSpace; 185 | 186 | return $this; 187 | } 188 | 189 | /** 190 | * @param string $extension Extended information, base 64 encoding 191 | * @return $this 192 | */ 193 | public function setExtension($extension){ 194 | $this->options['extension'] = $extension; 195 | 196 | return $this; 197 | } 198 | 199 | /** 200 | * @param mixed $pageOptions 201 | * @return $this 202 | */ 203 | public function setPageOptions($pageOptions){ 204 | $this->options['pageOptions'] = $pageOptions; 205 | 206 | return $this; 207 | } 208 | 209 | /** 210 | * @param string $targetPage page number 211 | * @return $this 212 | */ 213 | public function setTargetPage($targetPage){ 214 | $this->options['targetPage'] = $targetPage; 215 | 216 | return $this; 217 | } 218 | 219 | /** 220 | * @param string $width Page width (default 595) 221 | * @return $this 222 | */ 223 | public function setWidth($width){ 224 | $this->options['width'] = $width; 225 | 226 | return $this; 227 | } 228 | 229 | /** 230 | * @param string $height page height (842) 231 | * @return $this 232 | */ 233 | public function setHeight($height){ 234 | $this->options['height'] = $height; 235 | 236 | return $this; 237 | } 238 | 239 | /** 240 | * @param string $number Number of pages to insert (default 1) 241 | * @return $this 242 | */ 243 | public function setNumber($number){ 244 | $this->options['number'] = $number; 245 | 246 | return $this; 247 | } 248 | 249 | /** 250 | * @param string $quality Compressed document quality in the range 0-100, e.g. 50 251 | * @return $this 252 | */ 253 | public function setQuality($quality){ 254 | $this->options['quality'] = $quality; 255 | 256 | return $this; 257 | } 258 | 259 | /** 260 | * @param string $contentOptions extractContentOptions(1:OnlyText、2:OnlyTable、3:AllContent) 261 | * @return $this 262 | */ 263 | public function setContentOptions($contentOptions){ 264 | $this->options['contentOptions'] = $contentOptions; 265 | 266 | return $this; 267 | } 268 | 269 | /** 270 | * @param string $worksheetOptions createWorksheetOptions(1:ForEachTable、2:ForEachPage、3:ForTheDocument) 271 | * @return $this 272 | */ 273 | public function setWorksheetOptions($worksheetOptions){ 274 | $this->options['worksheetOptions'] = $worksheetOptions; 275 | 276 | return $this; 277 | } 278 | 279 | /** 280 | * @param string $isCsvMerge Whether to merge CSV (1: Yes, 0: No) 281 | * @return $this 282 | */ 283 | public function setIsCsvMerge($isCsvMerge){ 284 | $this->options['isCsvMerge'] = $isCsvMerge; 285 | 286 | return $this; 287 | } 288 | 289 | /** 290 | * @param string $lang language:Supported types and definitions. 291 | *

292 | * auto - automatic classification language. 293 | * english - English. 294 | * chinese - Simplified Chinese. 295 | * chinese_tra - Traditional Chinese. 296 | * korean - Korean. 297 | * japanese - Japanese. 298 | * latin - Latin. 299 | * devanagari - Sanskrit alphabet. 300 | * @return CPDFFileResource 301 | */ 302 | public function setLang($lang){ 303 | $this->options['lang'] = $lang; 304 | 305 | return $this; 306 | } 307 | 308 | /** 309 | * @param string $isContainAnnot Typesetting method (1: flow layout, 0: box layout) Default box layout 310 | * @return $this 311 | */ 312 | public function setIsContainAnnot($isContainAnnot){ 313 | $this->options['isContainAnnot'] = $isContainAnnot; 314 | 315 | return $this; 316 | } 317 | 318 | /** 319 | * @param string $isContainImg Whether to include pictures (1: yes, 0: no) 320 | * @return $this 321 | */ 322 | public function setIsContainImg($isContainImg){ 323 | $this->options['isContainImg'] = $isContainImg; 324 | 325 | return $this; 326 | } 327 | 328 | /** 329 | * @param string $isFlowLayout Whether to include comments (1: Yes, 0: No) 330 | * @return $this 331 | */ 332 | public function setIsFlowLayout($isFlowLayout){ 333 | $this->options['isFlowLayout'] = $isFlowLayout; 334 | 335 | return $this; 336 | } 337 | 338 | /** 339 | * @param string $imgDpi Value range 72-1500 (default 300) 340 | * @return $this 341 | */ 342 | public function setImgDpi($imgDpi){ 343 | $this->options['imgDpi'] = $imgDpi; 344 | 345 | return $this; 346 | } 347 | 348 | /** 349 | * @param $taskId 350 | * @param null $password 351 | * @param null $language 1:English, 2:Chinese 352 | * @return CPDFClient 353 | * @throws CPDFException 354 | */ 355 | public function uploadFile($taskId, $password = null, $language = null){ 356 | $fileInfo = $this->client->uploadFile($taskId, $this->filepath, $password, $this->options, $language); 357 | $this->fileKey = $fileInfo['fileKey']; 358 | $this->fileUrl = $fileInfo['fileUrl']; 359 | 360 | return $fileInfo; 361 | } 362 | } --------------------------------------------------------------------------------