evermore format conversion Service based Yongzhong DCS It supports the high-quality conversion between files in different formats, and can realize the high-quality conversion between PDF documents and Word, Excel, PPT and pictures. The PDF document conversion perfectly retains the layout and format of the original document, with excellent conversion effect and fast conversion speed, providing efficient file format conversion ability.
First, become a developer and apply for an application. On the homepage of Yongzhong cloud service platform( https://open.yozocloud.cn )Click "apply for adding" to fill in the information and submit it. Then click "management center" in the upper right corner of the page, click "apply for adding a new application" to apply for an application, and then you will get the appId and appKey in the figure below.
Then read Format conversion development document . The development document on the official website contains all interfaces to be used for docking services, and also gives return examples for reference. It also summarizes the common problems encountered in the use process.
The following are the specific access steps:
Step 1: import the jar package to generate the signature. The official website provides SDKs for several popular programming languages. You can download the corresponding SDKs and demo s according to your own development language to generate signatures. The JAVA SDK is used here.
SDK download address: https://cms.yozocloud.cn/info/file/getResource/81
DEMO download address: https://cms.yozocloud.cn/info/file/getResource/82
public static String APPID = "XXXX"; public static String APPKEY = "XXXXXX"; public static String CONVERTTYPE = "7"; //excel turn pdf /** * Get signature information * * @param map Parameter k-v * @return autograph * @throws Exception abnormal */ String getSign(Map<String,String[]> map) throws Exception { map.put("appId",new String[]{APPID}); AppAuthenticator authenticator=new UaaAppAuthenticator(UaaConstant.SIGN,null,UaaConstant.APPID); String sign = authenticator.generateSign(APPKEY, map); System.out.println("sign = " + sign); return sign; }
Step 2: upload files. Here, I use RestTemplate to send a Post request. Note that when uploading a file, the file type must be multipartFile, otherwise an error will be reported: message: unknown server error ^ ^ ^.
/** * Upload file */ Map<String, String[]> params = new HashMap<>(); String sign = getSign(params); String url = "http://dmc.yozocloud.cn/api/file/upload?appId={0}&sign={1}"; url = url.replace("{0}", APPID).replace("{1}", sign); System.out.println("url:" + url); //Upload file String filePath = "C:"; String fileName = "11111.xlsx"; //Set request header HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType("multipart/form-data"));//The file type is multipartFile type //Set the request body. Note that LinkedMultiValueMap FileSystemResource fileSystemResource = new FileSystemResource(filePath + "/" + fileName); MultiValueMap<String, Object> form = new LinkedMultiValueMap<>(); form.add("file", fileSystemResource); RestTemplate restTemplate1 = new RestTemplate(); restTemplate1.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); ResponseEntity<String> response1 = restTemplate1.exchange(url, HttpMethod.POST, new HttpEntity<>(form, headers), String.class);//Prevent the return information from being garbled System.out.println("The returned information is: " + response1.getBody()); //Get returned fileVersionId JSONObject data = JSONObject.parseObject(response1.getBody()).getJSONObject("data"); String fileVersionId = data.getString("fileVersionId");
Step 3: call the conversion interface. Each time you call the interface, use these parameters to generate a sign, except for multipartFile. Do not pass null or empty string for unused parameters.
/** * Call conversion interface */ Map<String, String[]> paramMap = new HashMap<>(); paramMap.put("fileVersionId", new String[]{fileVersionId}); paramMap.put("convertType", new String[]{CONVERTTYPE}); String s = getSign(paramMap);//Generate signature String converurl = "http://eic.yozocloud.cn/api/convert/file?appId={0}&sign={1}&fileVersionId={2}&convertType={3}"; converurl = converurl.replace("{0}", APPID).replace("{1}", s).replace("{2}",fileVersionId).replace("{3}",CONVERTTYPE); RestTemplate restTemplate2 = new RestTemplate(); restTemplate2.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); ResponseEntity<String> response2 = restTemplate2.postForEntity(converurl, null, String.class); System.out.println("The returned information is: " + response2.getBody());
Under normal conditions, the conversion type is set correctly, the file is uploaded correctly, and the return information after calling the format conversion interface is as follows:
Step 4: call the download interface to download and view. After the conversion interface is called and the operation is returned successfully, the converted file version Id will be received at the set callback address, as follows:
Use the received new file version Id to generate the signature again and call the download interface( http://dmc.yozocloud.cn/api/file/download ), the address can be directly put into the browser address bar to download and view.
source file
File after format conversion
be careful:
- The user must fill in the correct data callback address in the development information of format conversion to receive the new file version id, and add a POST interface under the data callback URL. The interface name is set to: / 3rd/edit/callBack;
Code example of interface receiving conversion callback data
- The convertType parameter of format conversion must correspond correctly, otherwise "the document format does not match the conversion type" will be returned when calling the interface.