HTML Preview

This requires two calls - the first to build the HTML page and the second to obtain the URL for the page.

1. Build the Preview

URL: /segments/remote_load_page_preview
Post Data: session_id, target_id, page_num, scale

session_id

The unique key returned in the initial login call.

target_id

The value of target_lang_id obtained when the PDF was uploaded.

page_num

The page number in the original PDF upon which the preview should be based. Page numbers start at 1 which is also the default if the parameter is not supplied.

scale

By default the page is rendered at 150% of its original size (based on PDF resolution of 72dpi). Supply alternative percentages in order to achieve a zoom functionality.

Returns

On success, a JSON structure containing progress information.
On failure the HTTP status code will be set to something other than 200.

The JSON structure will contain amongst other things, the following fields:

task_id

The unique id of the task which corresponds to a separate thread on the server. Use this id to obtain status information about the task via the remote_task_status call.

2. Get the Preview URL

URL: /segments/remote_get_page_preview_url
Post Data: session_id, target_id, page_num, scale

session_id

The unique key returned in the initial login call.

target_id

The value of target_lang_id obtained when the PDF was uploaded.

page_num

The page number in the original PDF upon which the preview should be based. Page numbers start at 1 which is also the default if the parameter is not supplied.

scale

By default the page is rendered at 150% of its original size (based on PDF resolution of 72dpi). Supply alternative percentages in order to achieve a zoom functionality.

Returns

On success, a JSON structure containing details of the preview.
On failure the HTTP status code will be set to something other than 200 and the content will describe the error.

The JSON structure will contain a 3-tuple of (url, width, height):

url

The URL for the HTML preview. The preview remains on the transpdf server.

width, height

The dimensions of the rendered image generated for the preview.

Notes

Generate a simple HTML preview of a single page of the translated PDF.

The preview is not a complete HTML page but just a <div> containing an image plus an image map. The image map contains area definitions for the locations of every paragraph on the page.

This information could be used in a graphical user interface to link paragraphs (whose ID's are given in the XLIFF) to their locations on the page and vice-versa. The second demonstration in main.py includes an example in which each paragraph area is highlighted as the mouse hovers over the page.

Example content of the HTML preview:

<div id="pagerender_div">
       <img id="pagerender_image"
               src="https://transpdf.iceni.com/media/pdfs/2016/04/14/land/fr-fr/page-0001.jpg"
               width="1216.0635" height="892.914" usemap="#pagerender" alt="" />
       <map name="pagerender">
               <area shape="rect" coords="1172,51,1182,90" alt="38"/>
               <area shape="rect" coords="55,28,551,65" alt="37"/>
               <area shape="rect" coords="925,365,1098,389" alt="36"/>
               <area shape="rect" coords="650,339,880,376" alt="32"/>
               <area shape="rect" coords="650,379,899,560" alt="33"/>
               ...
       </map>
</div>

The alt tag in each image map area defines the corresponding paragraph ID taken from the XLIFF.