Document Conversion

Update time: 2021/12/03 09:26:22

Document Conversion

Users can upload documents in PPT, PPTX, or PDF format to the server and the server provides features such as converting files into images, saving user document lists, deleting, and querying documents. The file upload and download feature is provided by the NOS service: nim_nos_upload_ex/nim_nos_download/nim_nos_download_ex.

Register the notification callback for conversion results

Register the notification callback for conversion result. For asynchronous conversion on the server, the client can not get the result before being notified.

@param[in] json_extension - Invalid extension field
@param[in] cb - See nim_doc_trans_def.h for result callback. The successfully returned json_extension includes a history.
@param[in] user_data - Custom user data of APP. SDK only transfers the data to callback feature cb and will not execute processing!
@return void: No value is returned.
typedef void(*nim_doctrans_reg_notify_cb)(const char *json_extension, nim_doctrans_opt_cb_func cb, const void *user_data);

Sample codes:

C++

void OnDocInfoCallback(int32_t code, const DocTransInfo& doc_info)
{

}

void foo()
{
	nim::DocTrans::RegNotifyCb(&OnDocInfoCallback);
}

C#

NIM.DocTransition.DocTransApi.RegisterNotifyCallback(DocTransDelegate cb)

C

void CallbackDocTrans(int32_t code, const char *json_extension, const void *user_data)
{
	···
}

typedef void(*void nim_doctrans_reg_notify_cb)(const char *json_extension, nim_doctrans_opt_cb_func cb, const void *user_data);

void foo()
{
	nim_doctrans_reg_notify_cb func = (nim_doctrans_reg_notify_cb) GetProcAddress(hInst, "nim_doctrans_reg_notify_cb");
	func("", &CallbackDocTrans, nullptr);
}

Query document information

Query document information by document ID

@param[in] ID - Document id
@param[in] json_extension - Invalid extension field
@param[in] cb - See nim_doc_trans_def.h for result callback. The successfully returned json_extension includes a history.
@param[in] user_data - Custom user data of APP. SDK only transfers the data to callback feature cb and will not execute processing!
@return void: No value is returned.
typedef void(*nim_doctrans_get_info)(const char *id, const char *json_extension, nim_doctrans_opt_cb_func cb, const void *user_data);

Sample codes:

C++

C++    void OnDocInfoCallback(int32_t code, const DocTransInfo& doc_info)
    {
    
    }
    
    void foo()
    {
    	nim::DocTrans::GetInfo("id...", "", const DocInfoCallback& cb);
    }

C#

C#    private void QueryTransInfoById(string id)
    {
    	NIM.DocTransition.DocTransApi.GetTransitionInfo(id, OnGetTransInfo);
    }
    
    private void OnGetTransInfo(int code, DocTransInfo info)
    {
    	//TODO: Process the result of querying documents
    }

C

C    void CallbackDocTrans(int32_t code, const char *json_extension, const void *user_data)
    {
    	···
    }
    
    typedef void(*nim_doctrans_get_info)(const char *id, const char *json_extension, nim_doctrans_opt_cb_func cb, const void *user_data);
    
    void foo()
    {
    	nim_doctrans_get_info func = (nim_doctrans_get_info) GetProcAddress(hInst, "nim_doctrans_get_info");
    	func("id...", "", &CallbackDocTrans, nullptr);
    }

Query document information with page break

Query document information list

@param[in] id		Query start docId. If it is null, it indicates to search from the start and documents are sorted by the start time of transcoding in a descending order.
@param[in] limit	Limit of queried documents. The current limit is 30.
@param[in] json_extension - Invalid extension field
@param[in] cb		See nim_doc_trans_def.h for result callback. The successfully returned json_extension includes the list of histories.
@param[in] user_data - Custom user data of APP. SDK only transfers the data to callback feature cb and will not execute processing!
@return void: No value is returned.
typedef void(*nim_doctrans_get_info_list)(const char *id, int32_t limit, const char *json_extension, nim_doctrans_opt_cb_func cb, const void *user_data);

Sample codes:

C++

C++    void OnDocInfosCallback(int32_t code, int32_t count, const std::list<DocTransInfo>& doc_infos)
    {
    
    }
    
    void foo()
    {
    	nim::DocTrans::GetInfoList("", 30, "", const OnDocInfosCallback& cb);
    }

C#

C#    /// <summary>
    /// Query document information by document id
    /// </summary>
    /// <param name="id">		Query start docId. If it is null, it indicates to search from the start and documents are sorted by the start time of transcoding in a descending order.</param>
    /// <param name="limit">	Limit of queried documents. The current limit is 30.</param>
    /// <param name="cb"></param>
    NIM.DocTransition.DocTransApi.GetTransitionInfoList(string id, int limit, GetTransListDelegate cb)

C

C    void CallbackDocTrans(int32_t code, const char *json_extension, const void *user_data)
    {
    	···
    }
    
    typedef void(*nim_doctrans_get_info_list)(const char *id, int32_t limit, const char *json_extension, nim_doctrans_opt_cb_func cb, const void *user_data);
    
    void foo()
    {
    	nim_doctrans_get_info_list func = (nim_doctrans_get_info_list) GetProcAddress(hInst, "nim_doctrans_get_info_list");
    	func("", 30, "", &CallbackDocTrans, nullptr);
    }

Delete document information

Delete the corresponding server record based on document id. For documents that are being transcoded, after this deletion you will not be notified of the transcoding results.

@param[in] ID - Document id
@param[in] json_extension - Invalid extension field
@param[in] cb		See nim_doc_trans_def.h for result callback. The returned json_extension is invalid.
@param[in] user_data - Custom user data of APP. SDK only transfers the data to callback feature cb and will not execute processing!
@return void: No value is returned.
typedef void(*nim_doctrans_del_info)(const char *id, const char *json_extension, nim_doctrans_opt_cb_func cb, const void *user_data);

Sample codes:

C++

void OnDocInfoCallback(int32_t code, const DocTransInfo& doc_info)
{

}

void foo()
{
	nim::DocTrans::DeleteInfo("id...", "", const OnDocInfoCallback& cb);
}

C#

/// <summary>
/// The server history is deleted by document id. If the document that is being transcoded is deleted, the transcoding result will not be notified.
/// </summary>
/// <param name="id">Document id</param>
/// <param name="cb"></param>
NIM.DocTransition.DocTransApi.DeleteTransition(string id, DocTransDelegate cb)

C

void CallbackDocTrans(int32_t code, const char *json_extension, const void *user_data)
{
	···
}

typedef void(*nim_doctrans_del_info)(const char *id, const char *json_extension, nim_doctrans_opt_cb_func cb, const void *user_data);

void foo()
{
	nim_doctrans_del_info func = (nim_doctrans_del_info) GetProcAddress(hInst, "nim_doctrans_del_info");
	func("id...", "", &CallbackDocTrans, nullptr);
}

Download URL of a source document

Concatenate the download URL of document source

@param[in] url_prefix	url prefix in document information
@param[in] file_type	Type of document source
@return char * - download URL of returned document source. The upper developers must invoke the interface for releasing memory nim_global.h for release.
typedef char *(*nim_doctrans_get_source_file_url)(const char *url_prefix, NIMDocTranscodingFileType file_type);

Sample codes:

C++

C++    std::string foo()
    {
    	return nim::DocTrans::GetSourceFileUrl("http....", kNIMDocTranscodingFileTypePPT);
    }

C#

C#    private void GetSourUrl(DocTransInfo info)
    {
    	var sourceUrl = NIM.DocTransition.DocTransApi.GetSourceFileUrl(info.UrlPrefix, info.SourceFileType);
    }

C

C    typedef char *(*nim_doctrans_get_source_file_url)(const char *url_prefix, NIMDocTranscodingFileType file_type);
    typedef	void (*nim_global_free_buf)(void *data);
    
    void foo()
    {
    	nim_doctrans_get_source_file_url func = (nim_doctrans_get_source_file_url) GetProcAddress(hInst, "nim_doctrans_get_source_file_url");
    	nim_global_free_buf free_func = (nim_global_free_buf) GetProcAddress(hInst, "nim_global_free_buf");
    	const char *url = func("http....", kNIMDocTranscodingFileTypePPT);
    
    	....
    
    	free_func((void *)url);
    }

download URL of an image

Concatenate the download URL of an image

@param[in] url_prefix	url prefix in document information
@param[in] img_type		Image type of document transcoding
@param[in] quality		Required image sharpness
@param[in] page_num		Image page (starting from 1)
@return char * - download URL of returned document image. The upper developers must invoke the interface for releasing memory nim_global.h for release.
typedef char *(*nim_doctrans_get_page_url)(const char *url_prefix, NIMDocTranscodingImageType img_type, NIMDocTranscodingQuality quality, int32_t page_num);

Sample codes:

C++

C++    std::string foo()
    {
    	return nim::DocTrans::GetPageUrl("http....", kNIMDocTranscodingImageTypeJPG, kNIMDocTranscodingQualityHigh, 1);
    }

C#

C#    private void GetSourUrl(DocTransInfo info)
    {
    	var destUrl = NIM.DocTransition.DocTransApi.GetPageUrl(info.UrlPrefix, info.DestImageType,NIMDocTranscodingQuality.kNIMDocTranscodingQualityHigh, info.PageNum);
    }

C

C    typedef char *(*nim_doctrans_get_page_url)(const char *url_prefix, NIMDocTranscodingImageType img_type, NIMDocTranscodingQuality quality, int32_t page_num);
    typedef	void (*nim_global_free_buf)(void *data);
    
    void foo()
    {
    	nim_doctrans_get_page_url func = (nim_doctrans_get_page_url) GetProcAddress(hInst, "nim_doctrans_get_page_url");
    	nim_global_free_buf free_func = (nim_global_free_buf) GetProcAddress(hInst, "nim_global_free_buf");
    	const char *url = func("http....", kNIMDocTranscodingImageTypeJPG, kNIMDocTranscodingQualityHigh, 1);
    
    	....
    
    	free_func((void *)url);
    }
Was this page helpful?
Yes
No
  • Document Conversion
  • Register the notification callback for conversion results
  • Query document information
  • Query document information with page break
  • Delete document information
  • Download URL of a source document
  • download URL of an image