|
| 1 | +// Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved. |
| 2 | +// |
| 3 | +// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW |
| 4 | +// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT. |
| 5 | +// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES. |
| 6 | +// This notice may not be removed from this file. |
| 7 | + |
| 8 | +package com.compdfkit; |
| 9 | + |
| 10 | + |
| 11 | +import com.compdfkit.client.CPDFClient; |
| 12 | +import com.compdfkit.constant.CPDFConstant; |
| 13 | +import com.compdfkit.constant.CPDFLanguageConstant; |
| 14 | +import com.compdfkit.enums.CPDFConversionEnum; |
| 15 | +import com.compdfkit.param.CIMGToTxtParameter; |
| 16 | +import com.compdfkit.pojo.comPdfKit.CPDFCreateTaskResult; |
| 17 | +import com.compdfkit.pojo.comPdfKit.CPDFFileInfo; |
| 18 | +import com.compdfkit.pojo.comPdfKit.CPDFTaskInfoResult; |
| 19 | +import com.compdfkit.pojo.comPdfKit.CPDFUploadFileResult; |
| 20 | + |
| 21 | +import java.io.File; |
| 22 | +import java.io.FileInputStream; |
| 23 | +import java.io.FileNotFoundException; |
| 24 | + |
| 25 | +public class IMGToTxt { |
| 26 | + |
| 27 | + private static final String publicKey = ""; |
| 28 | + private static final String secretKey = ""; |
| 29 | + private static final CPDFClient client = new CPDFClient(publicKey,secretKey); |
| 30 | + |
| 31 | + public static void main(String[] args) throws FileNotFoundException { |
| 32 | + IMGToTxt.imgToCsv(); |
| 33 | + } |
| 34 | + |
| 35 | + public static void imgToCsv() throws FileNotFoundException { |
| 36 | + // create Task |
| 37 | + CPDFCreateTaskResult createTaskResult = client.createTask(CPDFConversionEnum.IMAGE_TO_TXT, CPDFLanguageConstant.ENGLISH); |
| 38 | + // taskId |
| 39 | + String taskId = createTaskResult.getTaskId(); |
| 40 | + // upload File |
| 41 | + File file = new File("sample/test.png"); |
| 42 | + String filePassword = ""; |
| 43 | + CIMGToTxtParameter fileParameter = new CIMGToTxtParameter(); |
| 44 | + CPDFUploadFileResult uploadFileResult = client.uploadFile(new FileInputStream(file),taskId,filePassword,fileParameter,file.getName(), CPDFLanguageConstant.ENGLISH); |
| 45 | + String fileKey = uploadFileResult.getFileKey(); |
| 46 | + // perform tasks |
| 47 | + client.executeTask(taskId, CPDFLanguageConstant.ENGLISH); |
| 48 | + // get task processing information |
| 49 | + CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId); |
| 50 | + // determine whether the task status is "TaskFinish" |
| 51 | + if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) { |
| 52 | + System.out.println(taskInfo); |
| 53 | + // get the final file processing information |
| 54 | + CPDFFileInfo fileInfo = client.getFileInfo(fileKey); |
| 55 | + System.out.println(fileInfo); |
| 56 | + // if the task is finished, cancel the scheduled task |
| 57 | + }else { |
| 58 | + System.out.println("Task incomplete processing"); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments