Method, device and equipment for PDF translation keeping file layout and storage medium
By extracting text block information and layout attributes from PDF files, and combining a large language model and an adaptive scaling strategy, the problems of layout distortion and reading order disorder in PDF translation are solved, achieving visual consistency and preservation of logical structure in the translated document.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 深圳市和讯华谷信息技术有限公司
- Filing Date
- 2026-03-13
- Publication Date
- 2026-06-12
AI Technical Summary
Existing PDF translation technologies cannot achieve visually natural placement without altering the original text box boundaries, resulting in layout distortion, text overflow, or large blank areas. Furthermore, in complex layouts, reading order may be disrupted, making it difficult to maintain the legal validity and professional aesthetic appeal of the translated document.
Extract the geometric coordinates, text information, and layout attributes of each text block in the PDF file to generate an ordered sequence of text blocks, and use a large language model for block translation; draw an occlusion rectangle consistent with the background on the original PDF page, and use an adaptive scaling strategy to adjust the display of the translation so that the translation fits within the boundaries of the original text blocks.
Ensure that the translated PDF document is visually highly consistent with the original document, achieving a "what you see is what you get" translation effect, maintaining the legal validity and professional layout aesthetics, and reducing the time and cost of secondary layout.
Smart Images

Figure CN122197914A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of computer document processing and machine translation technology, and can be applied to the medical and financial technology fields. In particular, it relates to a PDF translation method, apparatus, device and storage medium that maintains the document layout. Background Technology
[0002] PDF documents, with their fixed layout, cross-platform consistency, and non-editability, have become the core electronic document carrier in professional fields such as academic papers, technical reports, legal contracts, and corporate financial statements. With the increasing demand for multilingual collaboration, users urgently need to accurately translate PDF content into the target language while strictly maintaining the original document's visual presentation. An ideal translation must ensure that the positional relationships and relative layout of all elements, including text, images, tables, and formulas, are perfectly accurate; that line spacing, paragraph indentation, and multi-column structures are fully preserved; and that font style, size, color, and special formatting such as bold and italics are faithfully reproduced. Furthermore, the reading order must be completely consistent with the original text to avoid legal ambiguity or academic misunderstanding caused by content misalignment. This "what you see is what you get" translation capability can guarantee the legal validity of the document's layout in legal compliance scenarios, maintain the aesthetic value of professional typesetting in academic publishing, and significantly reduce the time and design costs of secondary typesetting in the process of corporate internationalization.
[0003] However, existing PDF translation technologies face multiple technical bottlenecks: when the length of the translated text differs significantly from the original, traditional solutions cannot achieve natural filling of the translated text without moving images, table lines, or adjusting text box boundaries, often resulting in text overflowing and covering graphic elements or creating large blank areas, causing the layout structure to collapse; the extraction mechanism of the logical reading order within the PDF is prone to inaccuracy in complex scenarios such as multi-column layouts, mixed text and images, nested tables, and wrapping text, leading to paragraph overlap and logical inversion; translation strategies based on word-by-word segmentation or fixed rules lack semantic contextual understanding capabilities, making it difficult to accurately identify the boundaries of terms, proper nouns, and phrases in languages without spaces; more importantly, when faced with changes in the length of the translated text, existing methods either maintain the original font size, causing content overflow, force uniform scaling, causing a visual "shrinkage" effect, or completely reconstruct the layout, destroying the original design, and consistently fail to simultaneously achieve the triple goals of positional accuracy, font style consistency, and natural visual density. These shortcomings severely restrict the practicality and credibility of translated documents in professional scenarios. Summary of the Invention
[0004] The purpose of this application is to provide a PDF translation method, apparatus, device, and storage medium that preserves the document layout. It has the advantages of accurately maintaining the original layout of the PDF file, avoiding layout damage, and ensuring that the translated document is visually consistent with the original document.
[0005] To address the aforementioned technical problems, embodiments of this application provide a PDF translation method that maintains document layout, including: Extract the geometric coordinates, text information, and layout attributes of each text block in the original PDF file to form an original text block set; Based on the geometric coordinates, the original text blocks in the original text block set are sorted in a visual reading order to generate an ordered text block sequence; The ordered text block sequence and the context information corresponding to the ordered text block sequence are input into the large language model for block segmentation and translation, generating a translated text block sequence corresponding to the original text block; On the page of the original PDF, draw an occlusion rectangle that matches the page background for the geometric coordinate region of each original text block; On the occlusion rectangle, corresponding translation blocks are drawn at the same geometric coordinate positions, and an adaptive scaling strategy is used to adjust the translation display when drawing the translation blocks so that the translation fits within the boundary of the original text block; Save and output a new PDF file containing the translated text blocks.
[0006] To address the aforementioned technical problems, embodiments of this application provide a PDF translation device that maintains document layout, comprising: The text block extraction module is used to extract the geometric coordinates, text information, and layout attributes of each text block in the original PDF file, forming an original text block set; The reading order sorting module is used to perform visual reading order sorting of the original text blocks in the original text block set according to the geometric coordinates, and generate an ordered text block sequence. The intelligent translation module is used to input the ordered text block sequence and the context information corresponding to the ordered text block sequence into the large language model for block segmentation and translation, and generate a translated text block sequence corresponding to the original text block; The background occlusion module is used to draw an occlusion rectangle consistent with the page background for the geometric coordinate area of each original text block on the page of the original PDF. The translation drawing module is used to draw corresponding translation blocks at the same geometric coordinate positions on the occlusion rectangle, and to adjust the translation display using an adaptive scaling strategy when drawing the translation blocks so that the translation fits within the boundary of the original text block; The PDF output module is used to save and output a new PDF file containing the translated text blocks.
[0007] To solve the above-mentioned technical problems, one technical solution adopted by the present invention is to provide a computer device, including one or more processors; and a memory for storing one or more programs, such that the one or more processors implement the PDF translation method for maintaining file layout as described in any one of the above-mentioned methods.
[0008] To solve the above-mentioned technical problems, one technical solution adopted by the present invention is: a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the PDF translation method for maintaining file layout as described above.
[0009] This invention provides a PDF translation method, apparatus, device, and storage medium that preserves document layout. It extracts the geometric coordinates, text information, and layout attributes of each text block in the original PDF file to form an original text block set. Based on the geometric coordinates, the original text blocks in the original text block set are visually sorted in reading order to generate an ordered text block sequence. The ordered text block sequence and its corresponding context information are input into a large language model for segmentation and translation, generating a translated text block sequence corresponding to the original text blocks. On the original PDF page, an occlusion rectangle consistent with the page background is drawn over the geometric coordinate area of each original text block. On the occlusion rectangle, the corresponding translated text block is drawn at the same geometric coordinate position, and an adaptive scaling strategy is used to adjust the translation display so that the translation fits within the boundaries of the original text blocks. A new PDF file containing the translated text blocks is saved and output. This solves the problem of not being able to maintain layout in the prior art, and has the advantages of accurately maintaining the original layout of the PDF file, avoiding layout damage, and ensuring that the translated document is visually consistent with the original document. Attached Figure Description
[0010] To more clearly illustrate the solutions in this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0011] Figure 1 This is a flowchart illustrating the implementation of the PDF translation method for maintaining document layout provided in this application embodiment; Figure 2 yes Figure 1 A flowchart illustrating a specific implementation method of step S1; Figure 3 yes Figure 1 A flowchart illustrating a specific implementation method following step S2; Figure 4 yes Figure 1 A flowchart illustrating a specific implementation method of step S3; Figure 5 yes Figure 1 A flowchart illustrating a specific implementation of step S4; Figure 6 yes Figure 1 A flowchart illustrating a specific implementation of step S5; Figure 7 yes Figure 6 A flowchart illustrating a specific implementation method following step S54; Figure 8 This is a schematic diagram of a PDF translation device that maintains document layout according to an embodiment of this application; Figure 9 This is a schematic diagram of the computer device provided in the embodiments of this application. Detailed Implementation
[0012] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein in the specification of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "comprising" and "having," and any variations thereof, in the specification, claims, and foregoing drawings of this application, are intended to cover non-exclusive inclusion. The terms "first," "second," etc., in the specification, claims, or foregoing drawings of this application are used to distinguish different objects, not to describe a particular order.
[0013] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0014] Traditional PDF translation technologies often suffer from layout distortion, text overflow, or large blank spaces when dealing with variations in translation length, making it difficult to achieve visually natural placement without altering the original text box boundaries. Furthermore, existing technologies rely on the internal logical reading order of the PDF for text extraction, which is prone to disrupting the reading order in complex layouts, resulting in a reversal of the translated content's logic. These issues make it difficult for translated PDF documents to maintain the same legal validity or professional typographical aesthetics as the originals, increasing the time and design costs of secondary typesetting.
[0015] To address this issue, this application proposes a PDF translation method that preserves document layout. The method includes: extracting the geometric coordinates, text information, and layout attributes of each text block in the original PDF file to form an original text block set; visually sorting the original text blocks in the original text block set according to their geometric coordinates to generate an ordered text block sequence; inputting the ordered text block sequence and its corresponding context information into a large language model for block segmentation and translation to generate a translated text block sequence corresponding to the original text blocks; drawing an occlusion rectangle consistent with the page background on the geometric coordinate area of each original text block on the original PDF page; drawing the corresponding translated text block at the same geometric coordinate position on the occlusion rectangle, and using an adaptive scaling strategy to adjust the translation display so that the translation fits within the boundaries of the original text blocks; and saving and outputting a new PDF file containing the translated text blocks. This method aims to overcome the limitations of existing technologies, ensuring that the translated PDF document is visually highly consistent with the original document, achieving a "what you see is what you get" translation effect.
[0016] For ease of understanding, the following explains some key terms in this embodiment: Text block: refers to the smallest independent unit of text content in a PDF file, which usually has clear boundaries, position, size, and associated text content and layout style.
[0017] Geometric coordinates: These refer to the precise position and size information of a text block on a PDF page. They are usually represented by the coordinates of the lower left and upper right corners of a rectangle and are used to determine the spatial layout of the text block on the page.
[0018] Layout attributes: These refer to the visual presentation characteristics of text blocks, such as the rotation angle and drawing mode of the text. These attributes together determine the final display effect of the text blocks on the page.
[0019] Visualized reading order sorting: This refers to the logical rearrangement of text blocks based on their geometric positions on the page, simulating human reading habits, to ensure the continuity of the text content.
[0020] Large language model: refers to an artificial intelligence model built on deep learning technology and trained on massive amounts of text data. It can understand, generate and translate natural language and has the ability to process contextual information.
[0021] Occlusion rectangle: This refers to a rectangular area drawn on the geometric coordinates of the original text block that matches the background color or texture of the page. Its purpose is to cover the original text content and provide a clean background for subsequent translation.
[0022] Adaptive scaling strategy: refers to a method that dynamically adjusts the display parameters of the translation based on the length of the translation, the boundaries of the original text block, and other layout constraints. The aim is to make the translation visually fit naturally within the preset space of the original text block, avoiding overflow or excessive blank space.
[0023] This application effectively solves the problems of layout distortion, disordered reading order, and overflow or blank space in PDF translation by accurately extracting text block information, optimizing reading order, using a large language model for context-aware translation, and combining background occlusion and adaptive scaling strategies. As a result, the translated PDF document can maintain a high degree of visual consistency with the original document, ensuring that in legal, academic, and commercial applications, the document's legal validity, professional aesthetics, and publication efficiency are significantly improved, eliminating the need for secondary formatting.
[0024] The present invention will now be described in detail with reference to the accompanying drawings and embodiments.
[0025] It should be noted that the PDF translation method for maintaining document layout provided in this application embodiment is generally executed by a server, and correspondingly, the PDF translation device for maintaining document layout is generally configured in the server.
[0026] Please see Figure 1 , Figure 1 This illustrates one specific implementation of a PDF translation method that preserves document layout.
[0027] It should be noted that if substantially the same result is obtained, the method of this invention is not based on... Figure 1 Limited to the sequence shown, this method includes the following steps: S1: Extract the geometric coordinates, text information, and layout attributes of each text block in the original PDF file to form an original text block set.
[0028] Specifically, the geometric coordinates, text information, and layout attributes of each text block in the original PDF file are extracted to form an original set of text blocks. In one implementation, Optical Character Recognition (OCR) technology can be used to analyze the image of each page of the original PDF file, identify the text regions on the page, and estimate the boundary coordinates of each text region, the identified text content, and basic font information. However, this method may not be able to accurately obtain the detailed layout attributes of all text blocks, such as the precise rotation angle of the text or complex drawing patterns. In another implementation, text regions on the PDF page can be manually or semi-automatically marked, and their corresponding text content and approximate layout information can be entered; however, this method is less efficient and prone to errors.
[0029] Please see Figure 2 , Figure 2A specific implementation of step S1 is shown below: S11: Obtain the original PDF file. S12: Use a PDF parsing library to parse the original PDF file page by page to obtain the geometric coordinates, text content, font name, font size, font color, rotation angle, and text drawing attributes of each text block.
[0030] Specifically, the text information includes text content, font name, font size, and font color. These attributes are the core elements constituting the visual and semantic core of the text and are crucial for accurately replicating the visual style of the original text. Text content refers to the readable character sequence directly parsed from the PDF text stream, such as "Hello World"; font name refers to the font family identifier used to render the text, such as "Arial," "Times New Roman," or the name of a font subset within the PDF; font size refers to the font size, usually measured in points (pt), which determines the visual height of the text; and font color refers to the displayed color of the text, usually represented by RGB, CMYK, or grayscale values.
[0031] Meanwhile, the layout attributes include rotation angle and text drawing attributes. These attributes define the orientation, style, and rendering method of the text on the page, and are crucial for maintaining the original layout. Rotation angle refers to the amount of rotation of the text block relative to the page coordinate system; for example, text might be rotated 90 degrees to fit vertical layout. Text drawing attributes refer to the text rendering mode and visual effects; for example, they may include whether the text is bold, italic, underlined, strikethrough, and the text fill mode (such as fill, stroke, fill and stroke, etc.).
[0032] When extracting the geometric coordinates, text information, and layout attributes of each text block in the original PDF file to form the original text block set, the original PDF file itself must first be obtained. This is the starting point of the entire processing flow, ensuring the usability of the document to be translated. Obtaining the original PDF file can be achieved in various ways. For example, it can be read from a local storage device (such as a hard drive or solid-state drive) via a file system interface, or downloaded from a remote server or cloud storage service via network protocols (such as HTTP / HTTPS, FTP).
[0033] After obtaining the original PDF file, a PDF parsing library is used to parse the original PDF file page by page to obtain the geometric coordinates, text content, font name, font size, font color, rotation angle, and text drawing attributes of each text block. This step is crucial for accurate extraction, using professional parsing tools to delve into the PDF file structure and obtain the detailed attributes of each text block. Open-source PDF parsing libraries such as Poppler, PDF.js, PyPDF2, or Apache PDFBox can be used. These libraries provide the ability to access underlying PDF objects (such as page dictionaries, content streams, font dictionaries, and graphic state operators), thereby parsing the geometric coordinates (such as bounding boxes), text content, font information (name, size, color), and layout attributes (such as rotation information in the text matrix and text rendering mode) of text blocks. Alternatively, commercial PDF SDKs, such as Adobe PDF Library, can be used, which typically provide more advanced and stable API interfaces, enabling more accurate handling of complex PDF structures and rendering instructions to obtain all the aforementioned detailed attributes. Page-by-page parsing ensures complete coverage of the PDF document content and correct page context association, avoiding confusion or omission of cross-page text blocks.
[0034] This application addresses the issue of potentially missing crucial formatting information during text extraction by specifically defining the constituent elements of text information and layout attributes, and detailing the extraction process. Specifically, it clearly defines text information, including text content, font name, font size, and font color, ensuring accurate replication of the text's font style, such as font type and color, during translation and avoiding visual discrepancies caused by missing information. Simultaneously, it includes rotation angles and text drawing attributes within the layout attributes, handling text rotation and special drawing effects, such as bold or italics, ensuring the translated text's direction and style are consistent with the original. The extraction process involves acquiring the original PDF file and parsing it page by page using a PDF parsing library. This allows for precise extraction of text blocks for each page structure, avoiding cross-page errors. By comprehensively acquiring the geometric coordinates, text content, font name, font size, font color, rotation angle, and text drawing attributes of each text block, it ensures that subsequent steps, such as sorting and translation, are based on complete information. This allows the translated text blocks to accurately match the font, color, size, rotation, and special effects of the original text during drawing, significantly improving the visual consistency and professionalism of the translated PDF file.
[0035] S2: Based on the geometric coordinates, the original text blocks in the original text block set are sorted in a visual reading order to generate an ordered text block sequence.
[0036] Specifically, the original text blocks in the original text block set are visually sorted according to their reading order based on geometric coordinates, generating an ordered sequence of text blocks. For example, they can be simply sorted from top to bottom according to their Y-axis coordinates, and then sorted from left to right according to their X-axis coordinates when the Y-axis coordinates are similar. This sorting method based on simple coordinates may not fully simulate human reading habits when dealing with complex layouts such as multi-column layouts or mixed text and images, leading to deviations in the reading order.
[0037] Please see Figure 3 , Figure 3 A specific implementation method following step S2 is shown below: S21: If the original PDF file includes tables, then the tables in the original PDF file are detected and identified, and the table structure and cell content are extracted. S22: The table content is integrated into the ordered text block sequence in a structured form.
[0038] Specifically, this conditional judgment aims to optimize the processing flow by initiating subsequent table processing mechanisms only when a table is detected, thereby avoiding unnecessary computational overhead on documents without tables and improving overall processing efficiency. This can be achieved by performing a preliminary scan of the PDF document's structure to identify the presence of table-related graphic elements (such as lines and rectangles) or text layout patterns, or by analyzing the document's metadata to predict the presence of tables.
[0039] The steps of detecting and recognizing tables in the original PDF file aim to accurately locate and understand table regions and their internal structures within the PDF document. Specifically, various techniques can be employed. For example, based on the PDF's internal structural information, table borders and cell separators can be identified by analyzing path objects (such as line segments), and the rows and columns of the table can be inferred by combining this with text block alignment and spacing information. Another approach utilizes image processing and machine learning techniques. After rendering the PDF page as an image, a deep learning model (such as a convolutional neural network-based model) is trained to detect table bounding boxes and further identify the table's row and column structure.
[0040] After the table is detected and recognized, the step of extracting the table structure and cell content is responsible for parsing the specific layout information (such as the number of rows, columns, and cell merging) and the text content within each cell from the recognized table area. In practice, this can be achieved by precisely locating the geometric region of each cell based on the table's structural information, and then extracting the corresponding text content from these regions. For complex tables, semantic analysis of the text may also be necessary to ensure the completeness and accuracy of the cell content.
[0041] The purpose of integrating the table content into the ordered sequence of text blocks in a structured form is to seamlessly integrate the table data into the overall reading flow of the document, ensuring that the table content can be processed alongside ordinary text during translation and maintaining the correct logical order. Specifically, the text content of each table cell can be treated as an independent text block and inserted into the appropriate position in the ordered sequence of text blocks according to the reading order of the table (e.g., from left to right, from top to bottom). To preserve the structural information of the table, special metadata or tags can be embedded in these text blocks to indicate which table, row, and cell they belong to, so that the original layout of the table can be reconstructed in subsequent translation and rendering stages.
[0042] This application effectively addresses the issue of tables in original PDF files potentially being ignored, losing their structure, or having their reading order disrupted during translation. By conditionally detecting and recognizing tables in the original PDF file after extracting the original text block set, and extracting their structure and cell content, it ensures that all table information is fully captured. Subsequently, this table content is integrated into an ordered text block sequence in a structured form. This allows the large language model to consider table content along with ordinary text during block segmentation and translation, thus guaranteeing the coherence and accuracy of the translation. Finally, in the translation rendering stage, since the table content has been processed as part of the ordered text block sequence, it can be correctly rendered into the new PDF file along with non-table text blocks. This maintains the original file layout while achieving accurate translation and layout restoration of table content, avoiding layout distortion or information loss caused by improper table processing, and significantly improving the overall quality and usability of the translated PDF document.
[0043] S3: Input the ordered text block sequence and the context information corresponding to the ordered text block sequence into the large language model for block segmentation and translation, and generate the translated text block sequence corresponding to the original text block.
[0044] Specifically, the ordered sequence of text blocks and its corresponding contextual information are input into the large language model for block segmentation and translation, generating a sequence of translated blocks corresponding to the original text blocks. In other words, the extracted text block content can be directly concatenated into a long text string, which is then used as input to the large language model for translation. Upon receiving this long text, the large language model performs block segmentation according to its internal mechanisms and generates the corresponding translation. However, this direct concatenation method may result in the large language model lacking a deep understanding of the context of certain terms or phrases when processing long texts, thus affecting the accuracy and consistency of the translation.
[0045] Please see Figure 4 , Figure 4A specific implementation of step S3 is shown below: S31: Construct structured data from the ordered text block sequence and its corresponding context information. S32: Input the structured data into the large language model for block segmentation and translation, generating a translated text block sequence corresponding to the original text blocks.
[0046] Specifically, the ordered text block sequence and its corresponding context information are constructed into structured data, aiming to organize the original text content and its associated information in a machine-readable and easily parsed format. Structured data typically refers to data with a predefined format and organization, such as representing information through tags, fields, or hierarchical relationships. Its purpose is to provide clear semantic boundaries and contextual dependencies for large language models, thereby avoiding potential comprehension biases when processing unstructured text. In practice, structured data can be constructed in various ways. For example, each ordered text block and its context information can be encapsulated as a JSON object or XML node, containing metadata such as text content, its logical position in the document (e.g., paragraph, heading, list item), and its relationship with adjacent text blocks. Another approach is to use Markdown or a similar semantic markup language, explicitly annotating the text structure and hierarchy through specific syntax (e.g., `#` for headings, `-` for list items), and embedding context information as additional attributes or annotations.
[0047] Subsequently, the structured data is input into the large language model for chunking and translation, generating a sequence of translated chunks corresponding to the original text chunks. The large language model is a pre-trained model based on deep learning, possessing powerful natural language understanding and generation capabilities. In this step, the large language model not only performs the translation task but also intelligently chunks the input structured data. Chunking refers to dividing a continuous stream of text into semantically complete units, such as sentences, paragraphs, or specific semantic groups. Through structured data, the large language model can identify and respect the boundaries of these semantic units, thereby performing more accurate and coherent translations. For example, structured data can be sent to the large language model as a prompt with specific instructions via an API interface, instructing it to chunk and translate based on the structured information. Alternatively, a specifically trained or fine-tuned large language model can be used to directly parse the tags in the structured data and automatically perform semantic chunking and translation based on these tags.
[0048] In this embodiment, ordered text block sequences and contextual information are constructed into structured data, providing a clear and explicit semantic context and structural information for the large language model. This enables the large language model to more accurately identify the logical units and semantic boundaries of the text, effectively avoiding inaccurate translation segmentation or semantic comprehension deviations caused by improper information organization. Based on this, the structured data is input into the large language model for segmentation and translation, fully utilizing the powerful semantic understanding and contextual reasoning capabilities of the large language model, ensuring that the translation process respects the logical structure and semantic integrity of the original text. This not only improves the accuracy and fluency of the translation, but more importantly, the generated translated block sequence corresponds highly with the original text blocks semantically and structurally. This provides a solid foundation for accurately drawing the translated blocks on the original PDF page and maintaining the original layout, effectively solving the problem of content misalignment caused by incorrect text extraction order or insufficient semantic understanding in complex typesetting. Ultimately, this achieves a high degree of consistency between the translated document and the original document in terms of visual appearance and logical structure.
[0049] S4: On the page of the original PDF, draw an occlusion rectangle that matches the page background for the geometric coordinate area of each original text block.
[0050] Specifically, on the original PDF page, draw an occlusion rectangle that matches the page background for the geometric coordinate area of each original text block. For example, you can simply draw a plain white rectangle over the geometric coordinate area of the original text block to cover the original text. This method works well when the original PDF page background is a solid color, but if the page background contains complex patterns, textures, or gradients, the plain white rectangle may clash with the page background, resulting in a visually jarring effect.
[0051] Please see Figure 5 , Figure 5 A specific implementation of step S4 is shown below: S41: Traverse each page of the original PDF and analyze the geometric coordinate region of the original text block to extract the background pixel information of the geometric coordinate region. S42: Draw the occlusion rectangle whose geometric coordinate region matches the page background based on the background pixel information.
[0052] Specifically, to ensure comprehensive processing of the entire original PDF file without overlooking any pages that might contain text blocks, this application employs a method of traversing every page of the original PDF. This step ensures the integrity of the translation and maintains layout consistency across the entire document. Implementation methods may include: accessing each page sequentially using a page iterator provided by a PDF parsing library, or obtaining all page objects by analyzing the PDF document structure tree and processing them sequentially. Subsequently, to accurately identify and locate the specific position and extent of each original text block on the page, this application analyzes the geometric coordinate region of the original text block. Analysis of the geometric coordinate region provides accurate targets for subsequent background information extraction and occlusion rectangle drawing. Implementation methods may include: obtaining the bounding box information of the text block, such as the coordinates of the top-left corner, width, and height; or determining the precise pixel area occupied by the text block through pixel scanning.
[0053] Based on this, this application extracts background pixel information from the geometric coordinate region. This step is crucial for identifying the visual features of the background below or around the text block. Extracting background pixel information ensures that the subsequently drawn occlusion rectangle blends seamlessly with the original page background, avoiding visual abruptness. Implementation methods may include: sampling pixels in the non-text portion within the geometric coordinate region of the text block, for example, sampling pixel colors in blank areas near the text block boundaries or within the text block; or, using image processing techniques to separate the background and foreground (text) of the text block region to obtain pure background pixel data, for example, calculating the most frequently occurring color in the region as the background color, or performing image segmentation on the region to identify the background area. Finally, the occlusion rectangle, consistent with the page background, is drawn based on the background pixel information. This step aims to effectively "erase" the original text by drawing a rectangle matching the background visual features on the geometric coordinate region of the original text block, creating a clean background for the translation. Its function is to eliminate visual interference from the original text and provide a display area for the translation consistent with the style of the original document. Implementation methods may include: using the extracted background color value as the fill color to draw a solid rectangle in the geometric coordinate area of the original text block; or, if the background is a complex texture or gradient, a corresponding part of the original background image can be cropped and used as a texture to fill the occlusion rectangle to achieve a higher level of background consistency.
[0054] This application effectively solves the visual disharmony problem caused by inconsistencies between the occlusion rectangle and the page background during PDF translation, thus maintaining a faithful layout reproduction of the translated document. Specifically, by traversing every page of the original PDF, it ensures that all pages of the entire document are processed, avoiding any omissions and guaranteeing comprehensive processing. Precise analysis of the geometric coordinate region of each original text block allows for targeted extraction of background pixel information at the precise location of each text block. By extracting the background pixel information of the geometric coordinate region, the visual features of the background can be accurately obtained, effectively identifying solid color backgrounds, gradient backgrounds, and complex backgrounds with textures. Based on this, an occlusion rectangle consistent with the page background is drawn based on the extracted background pixel information, allowing the occlusion rectangle to seamlessly integrate into the original page background, completely eliminating visual abruptness and providing a smooth and visually unified transition area for the subsequent drawing of translated text blocks. This approach ensures that the overall visual continuity and aesthetics of the page are maintained after the original text is covered, thus creating ideal conditions for the display of the translation without compromising the original layout design, and greatly improving the visual quality and user experience of the translated PDF document.
[0055] S5: On the occlusion rectangle, draw the corresponding translation block at the same geometric coordinate position, and when drawing the translation block, use an adaptive scaling strategy to adjust the translation display so that the translation fits within the boundary of the original text block.
[0056] Specifically, on the occlusion rectangle, corresponding translation blocks are drawn at the same geometric coordinates. An adaptive scaling strategy is used to adjust the translation display while drawing the translation blocks, ensuring the translation fits within the boundaries of the original text blocks. One approach is to initially attempt to draw the translation using the same font size as the original text blocks. If the width or height of the translation exceeds the boundaries of the original text blocks, the font size is proportionally reduced until it fully fits the boundaries of the original text blocks. However, this simple proportional reduction strategy may result in excessively small font sizes, affecting the reading experience, or, when the translation is short, large blank areas appear within the original text blocks, affecting visual density.
[0057] Please see Figure 6 , Figure 6 A specific implementation of step S5 is shown below: S51: On the occluding rectangle, draw and insert corresponding translation blocks as transparent text layers at the same geometric coordinate positions. S52: When inserting the translation blocks, maintain the font height of the translation blocks at the same height as the original text of the original text block, and adjust the character spacing of the translation blocks. S53: If the translation of the translation block exceeds the boundary of the original text block, adjust the translation of the translation block by proportionally reducing the font size. S54: If the height difference between the translation and the original text is higher than a preset threshold, enlarge the font size of the translation or increase the character spacing of the translation to make the translation fit within the boundary of the original text block.
[0058] Specifically, "drawing and inserting the corresponding translation block as a transparent text layer at the same geometric coordinate position on the occluding rectangle" aims to ensure that the translation visually and accurately replaces the original text without disrupting the page background or other elements. One implementation is to add the translation as a new text object to the area overlapping the geometric coordinate position of the original text block during the PDF document rendering process, and set its rendering mode to transparent or use a specific blending mode, allowing it to cover the original content while still maintaining text selectability. Another implementation is to insert the translation as a separate text annotation onto the PDF page, placing the annotation at the precise position of the original text block and configuring it with a transparent background, thus achieving a seamless visual replacement.
[0059] "Maintaining the font height of the translated block to be the same as the original text block's height when inserting the translated block, and adjusting the character spacing of the translated block" is the first step of the adaptive scaling strategy, the core of which is to prioritize maintaining the vertical layout stability of the original document. One implementation is to first obtain the font height of the original text block when rendering the translation, and use this height as the initial font height of the translation. Then, based on the actual length of the translation and the width of the original text block, the character spacing (character spacing) of the translation is dynamically calculated and adjusted. For example, if the translation is short, the character spacing is appropriately increased to fill the horizontal space; if the translation is long, the character spacing is appropriately decreased to compress the text, making it fit the original width as closely as possible without changing the line height. Another implementation is to use the text positioning and spacing adjustment functions provided by the PDF rendering library to precisely control the horizontal position of each character, thereby achieving fine-tuning of the character spacing and ensuring that the translation fills the horizontal space of the original text block as much as possible while maintaining the original font height.
[0060] "If the translated text of the translation block exceeds the boundary of the original text block, then adjust the translated text of the translation block by proportionally reducing the font size" is an effective means of handling cases where the translation is too long. One implementation is to check whether the translated text still exceeds the width or height boundary of the original text block after initial rendering and adjusting the character spacing. If it does, calculate a proportional scaling factor that ensures the translated text can be completely contained within the boundary of the original text block after reducing the font size, and then re-render the translation using this scaling factor. Another implementation is to use an iterative method, each time reducing the translated text size proportionally by a preset step size (e.g., 0.5 points) and re-measuring the size of the translated text until the translated text completely fits the boundary of the original text block or reaches a preset minimum readable font size.
[0061] The measure "If the height difference between the translated text and the original text exceeds a preset threshold, then the font size of the translated text is increased or the letter spacing of the translated text is increased to make the translated text fit within the boundaries of the original text block" aims to optimize situations where the translated text is too short, resulting in excessive visual blank space. One implementation method is to assess the actual vertical space or visual density occupied by the translated text within the original text block after initial rendering. If the translated text appears too sparse, i.e., its visual height or fill rate differs significantly from the original text (exceeding a preset threshold), the font size of the translated text can be appropriately increased to make it visually fuller. Another implementation method is to further increase the letter spacing of the translated text without changing the font size, extending it horizontally and thus improving the overall visual density. These two methods can be used individually or in combination to achieve the best visual adaptation effect.
[0062] This application effectively solves the problem of the translated text failing to fit the boundaries of the original text blocks when the length of the translated text does not match the length of the original text. Specifically, on the original PDF page, a masking rectangle consistent with the page background is first drawn to ensure that the original text content is completely covered, providing a clean canvas for the translation. Subsequently, the translated text block is drawn and inserted as a transparent text layer at the same geometric coordinate position. This not only ensures that the translated text visually accurately replaces the original text, but also avoids interference with other elements on the page through the transparency layer, while maintaining the selectability of the text. When drawing the translated text, the font height of the translated text block is kept the same as the height of the original text block, and the character spacing is adjusted to adapt to the width of the original text. This preserves the line height and vertical layout of the original document to the greatest extent, avoiding layout errors caused by height changes. When the length of the translated text exceeds the boundaries of the original text block, the system intelligently reduces the font size proportionally to ensure that all translated content is displayed completely, avoiding text overflow or overlap, thereby maintaining the neatness of the layout. Conversely, if the height difference between the translation and the original text (i.e., the visual density difference) exceeds a preset threshold, it indicates that the translation is too short, resulting in excessive blank space. In this case, increasing the font size or sizing of the translation can effectively fill the blank space, improve visual density, and allow the translation to blend more naturally into the original layout, avoiding the abruptness caused by the translation being too short. Overall, this adaptive scaling strategy, while maintaining the "what you see is what you get" of the original layout, achieves seamless replacement and natural display of the translation, greatly improving the visual quality and user experience of the translated PDF document.
[0063] Please see Figure 7 , Figure 7 A specific implementation of step S54 is shown below: S55: Maintain the font color, weight, and font family of the translated text block consistent with the corresponding original text block. S56: When the target font is unavailable, perform a visual effect comparison between the original text block and multiple alternative fonts, and determine the target alternative font based on the comparison results.
[0064] Specifically, maintaining consistency in font color, weight, and font family between the translated text and the corresponding original text is a technical feature designed to ensure a high degree of visual style consistency between the translated and original text. When generating the translated text, the system retrieves the font color, weight (e.g., regular, bold, italic), and font family (e.g., SimSun, Times New Roman) of the original text. These attributes are then precisely applied to the corresponding translated text. This can be achieved by directly inheriting the CSS style properties or font metadata of the original text, or by passing these attributes as parameters to the font rendering engine during translation. In this way, even if the length or font size of the translated text is adjusted due to adaptive scaling, its core visual style elements are faithfully reproduced, avoiding visual abruptness or a decrease in document professionalism caused by mismatched font attributes.
[0065] Meanwhile, when the target font is unavailable, a visual effect comparison is performed between the original text block and multiple alternative fonts, and the target alternative font is determined based on the comparison results. This technical feature provides an intelligent font fallback mechanism to deal with situations where the original font is missing in the target environment. When the system detects that the font used by the original text block is unavailable in the current rendering environment, it will not simply use the default font, but will initiate an alternative font selection process. Specifically, this can be implemented in several ways: One way is based on the comparison of font metrics. The system can extract key metrics of the original font, such as character height, uppercase letter height, stroke width, character width distribution, etc., and then compare these metrics with the corresponding metrics of multiple preset alternative fonts, selecting the alternative font with the smallest difference in metrics as the target alternative font. Another way is based on the visual comparison of rendered images. The system can select a representative text (e.g., a phrase containing common characters or characters from a specific language), render it using the original font (if rendering can be simulated) and each alternative font, and then quantify the visual similarity of the rendering results using image processing techniques (such as pixel-level comparison, Structural Similarity Index (SSIM), etc.) to determine the alternative font that is closest in visual effect to the original font. In this way, even if the original font is missing, the visual consistency and typographical aesthetics of the translation can be maintained to the maximum extent, avoiding layout chaos or a decline in reading experience caused by improper font replacement.
[0066] This application effectively solves the problems of insufficient faithful reproduction of font attributes and visual inconsistencies when the target font is unavailable, which may occur under adaptive scaling strategies. Specifically, by maintaining consistency between the font color, weight, and font family of the translated text blocks and the corresponding original text blocks, it ensures that the translated text is visually highly consistent with the style of the original document, avoiding visual infidelity caused by format deviations, thereby maintaining the professionalism and aesthetics of the document. Simultaneously, when the original font is unavailable, this application provides an intelligent and robust font fallback mechanism by comparing the visual effects of the original text blocks with multiple alternative fonts and determining the target alternative font. This allows the translated text to select the alternative font that best approximates the visual effect of the original font for rendering, even under font-constrained conditions, avoiding the typesetting distortion and decreased reading experience that may result from using the default font. By combining the aforementioned adaptive scaling strategy, this application not only ensures that the translation can be accurately adapted to the boundaries of the original text block, but also ensures the faithful reproduction of the translation in terms of font style, color, and weight, as well as intelligent handling when fonts are missing. This achieves a higher level of visual consistency in the translated PDF file, making it "what you see is what you get," and greatly improving the user experience and document usability.
[0067] S6: Save and output a new PDF file containing the translated blocks.
[0068] Specifically, after all the translation blocks are drawn, the modified PDF page content is saved as a new PDF file. The new PDF file retains all the graphics, images, lines, backgrounds and other non-text elements of the original PDF, and only adds a transparent text layer to carry the translation, thus achieving a translation effect that is completely consistent with the original PDF in terms of visual layout, typesetting structure and reading order, and the translated content is searchable and copyable.
[0069] In one specific embodiment, the translation of a typical English paper PDF (two-column layout, including title, author, abstract, figures, tables, superscripts and subscripts, formulas, headers and footers, and footnotes) into Chinese is used as an example to illustrate the specific implementation process and technical effects of the present invention.
[0070] The steps are as follows: 1. Open the original Chinese PDF file to be translated, and extract the precise geometric coordinates, original text content, font, size, color, rotation angle, and all other layout attributes of each text block page by page.
[0071] 2. Based on the geometric coordinates of each text block, a visual reading order reconstruction algorithm based on horizontal and vertical projection and regional connectivity is used to reorder all text blocks to obtain a text sequence that fully conforms to the actual reading order of the human eye, such as from top to bottom, from left to right, text wrapping around images, and footnotes placed after the text.
[0072] 3. Organize the above ordered text sequence and its positional context information into structured data and input it into the large language model. The large language model automatically determines the units that need to be translated as a whole based on semantic coherence, performs intelligent merging and complete translation, and returns the translated text sequence that corresponds one-to-one with the original text blocks.
[0073] 4. Traverse each page of the original PDF. For each rectangular area containing the original text block, first draw a masking block that is completely consistent with the page background of that area to achieve seamless coverage of the original text.
[0074] 5. Within identical rectangular areas, insert the corresponding translation as a transparent text layer. Use an adaptive scaling strategy during insertion. First, try to keep the original font size unchanged and only make minor adjustments to the letter spacing to make the length of the translation fit the original area; If it still exceeds the limit, reduce the font size proportionally until the translation fits perfectly within the original rectangle; If the translation is significantly shorter than the original text, the font size should be enlarged or the spacing between characters increased to maintain the same visual density as the original text. The font color, weight, and font family of the translated text should be consistent with the original text.
[0075] 6. Save and export a new PDF file.
[0076] Please refer to Figure 8 As a response to the above Figure 1 The implementation of the method shown in this application provides an embodiment of a PDF translation device that maintains document layout. This device embodiment is similar to... Figure 1 Corresponding to the method embodiments shown, this device can be specifically applied to various electronic devices.
[0077] like Figure 8 As shown, the PDF translation device that maintains document layout in this embodiment includes: a text block extraction module 71, a reading order sorting module 72, an intelligent translation module 73, a background occlusion module 74, a translation drawing module 75, and a PDF output module 76, wherein: The text block extraction module 71 is used to extract the geometric coordinates, text information and layout attributes of each text block in the original PDF file to form an original text block set; The reading order sorting module 72 is used to perform visual reading order sorting of the original text blocks in the original text block set according to the geometric coordinates, and generate an ordered text block sequence. The intelligent translation module 73 is used to input the ordered text block sequence and the context information corresponding to the ordered text block sequence into the large language model for block segmentation and translation, and generate a translated text block sequence corresponding to the original text block; Background occlusion module 74 is used to draw an occlusion rectangle consistent with the page background for the geometric coordinate area of each original text block on the page of the original PDF. The translation drawing module 75 is used to draw corresponding translation blocks at the same geometric coordinate positions on the occlusion rectangle, and to adjust the translation display using an adaptive scaling strategy when drawing the translation blocks so that the translation fits within the boundary of the original text block; PDF output module 76 is used to save and output a new PDF file containing the translated blocks.
[0078] Furthermore, the text information includes text content, font name, font size, and font color; the layout attributes include rotation angle and text drawing attributes; the text block extraction module 71 includes: The file acquisition unit is used to acquire the original PDF file; The parsing unit is used to parse the original PDF file page by page using a PDF parsing library to obtain the geometric coordinates, text content, font name, font size, font color, rotation angle, and text drawing attributes of each text block.
[0079] Furthermore, the intelligent translation module 73 includes: A structured data construction unit is used to construct structured data from the ordered text block sequence and the context information corresponding to the ordered text block sequence. The translation block sequence generation unit is used to input the structured data into the large language model for block segmentation and translation, and generate a translation block sequence corresponding to the original text block.
[0080] Furthermore, the background occlusion module 74 includes: The background pixel information extraction unit is used to traverse each page of the original PDF and analyze the geometric coordinate region of the original text block to extract the background pixel information of the geometric coordinate region. An occlusion rectangle generation unit is used to draw an occlusion rectangle whose geometric coordinate region is consistent with the page background based on the background pixel information.
[0081] Furthermore, the translation rendering module 75 includes: The translation block insertion unit is used to draw and insert the corresponding translation block in the form of a transparent text layer at the same geometric coordinate position on the occlusion rectangle; The character spacing adjustment unit is used to maintain the font height of the translation block and the original text height of the original text block the same when the translation block is inserted, by adjusting the character spacing of the translation block; The font size reduction unit is used to adjust the translation of the translation block by proportionally reducing the font size if the translation of the translation block exceeds the boundary of the original text block. An adaptation unit is used to enlarge the font size of the translation or increase the character spacing of the translation if the height difference between the translation and the original text is higher than a preset threshold, so that the translation fits within the boundary of the original text block.
[0082] Furthermore, the adapter unit also includes: The font preservation unit maintains the font color, weight, and font family of the translated block consistent with the corresponding original text block. The backup font confirmation unit is used to compare the visual effects of the original text block with multiple backup fonts when the target font is unavailable, and to determine the target backup font based on the comparison results.
[0083] Furthermore, the reading order sorting module 72 also includes: The cell content extraction module is used to detect and identify tables in the original PDF file if the original PDF file contains tables, and extract the table structure and cell content. The table content insertion module is used to integrate the table content into the ordered text block sequence in a structured form.
[0084] It should be noted that any AI models, software tools, or components not belonging to this company appearing in the embodiments of this application are merely illustrative examples and do not represent actual use. All user personal information involved in the embodiments of this application has been obtained by authorized entities (who have known and consented) or fully authorized by all parties through various legal and compliant means. The collection, storage, use, processing, transmission, provision, and disclosure of the information, data, and signals involved all comply with relevant laws and regulations and do not violate public order and good morals.
[0085] To address the aforementioned technical problems, embodiments of this application also provide a computer device. Please refer to [link / reference needed]. Figure 9 , Figure 9 This is a basic structural block diagram of the computer device in this embodiment.
[0086] Computer device 8 includes a memory 81, a processor 82, and a network interface 83 that are interconnected via a system bus. It should be noted that... Figure 9Only a computer device 8 with three components—memory 81, processor 82, and network interface 83—is shown. It should be understood that implementing all shown components is not required; more or fewer components may be implemented alternatively. Those skilled in the art will understand that this computer device is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions. Its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), and embedded devices.
[0087] Computer devices can include desktop computers, laptops, handheld computers, and cloud servers. These devices allow for human-computer interaction with users through keyboards, mice, remote controls, touchpads, or voice-activated devices.
[0088] The memory 81 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 81 may be an internal storage unit of the computer device 8, such as the hard disk or memory of the computer device 8. In other embodiments, the memory 81 may also be an external storage device of the computer device 8, such as a plug-in hard disk, SmartMedia Card (SMC), Secure Digital (SD) card, flash card, etc., equipped on the computer device 8. Of course, the memory 81 may include both the internal storage unit and its external storage device of the computer device 8. In this embodiment, the memory 81 is typically used to store the operating system and various application software installed on the computer device 8, such as the program code of a PDF translation method that maintains the file layout. In addition, the memory 81 may also be used to temporarily store various types of data that have been output or will be output.
[0089] In some embodiments, processor 82 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip. This processor 82 is typically used to control the overall operation of the computer device 8. In this embodiment, processor 82 is used to run program code stored in memory 81 or process data, for example, to run the program code of the PDF translation method that maintains the document layout described above, to implement various embodiments of the PDF translation method that maintains the document layout.
[0090] The network interface 83 may include a wireless network interface or a wired network interface, which is typically used to establish a communication connection between the computer device 8 and other electronic devices.
[0091] This application also provides another embodiment, namely, providing a computer-readable storage medium storing a computer program that can be executed by at least one processor to cause the at least one processor to perform the steps of the PDF translation method for maintaining document layout as described above.
[0092] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods of the various embodiments of this application.
[0093] Obviously, the embodiments described above are merely some embodiments of this application, not all embodiments. The accompanying drawings show preferred embodiments of this application, but do not limit the scope of this application. This application can be implemented in many different forms; rather, these embodiments are provided to provide a more thorough and comprehensive understanding of the disclosure of this application. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing specific embodiments, or make equivalent substitutions for some of the technical features. Any equivalent structures made using the content of this application's specification and drawings, directly or indirectly applied to other related technical fields, are similarly within the scope of protection of this application.
Claims
1. A PDF translation method that preserves document layout, characterized in that, include: Extract the geometric coordinates, text information, and layout attributes of each text block in the original PDF file to form an original text block set; Based on the geometric coordinates, the original text blocks in the original text block set are sorted in a visual reading order to generate an ordered text block sequence; The ordered text block sequence and the context information corresponding to the ordered text block sequence are input into the large language model for block segmentation and translation, generating a translated text block sequence corresponding to the original text block; On the page of the original PDF, draw an occlusion rectangle that matches the page background for the geometric coordinate region of each original text block; On the occlusion rectangle, corresponding translation blocks are drawn at the same geometric coordinate positions, and an adaptive scaling strategy is used to adjust the translation display when drawing the translation blocks so that the translation fits within the boundary of the original text block; Save and output a new PDF file containing the translated text blocks.
2. The PDF translation method for maintaining document layout as described in claim 1, characterized in that, The text information includes text content, font name, font size, and font color; the layout attributes include rotation angle and text drawing attributes. The process involves extracting the geometric coordinates, text information, and layout attributes of each text block from the original PDF file to form an original text block set, including: Obtain the original PDF file; The original PDF file is parsed page by page using a PDF parsing library to obtain the geometric coordinates, text content, font name, font size, font color, rotation angle, and text drawing attributes of each text block.
3. The PDF translation method for maintaining document layout as described in claim 1, characterized in that, The step of inputting the ordered text block sequence and the corresponding context information into a large language model for block segmentation and translation to generate a translated text block sequence corresponding to the original text block includes: The ordered text block sequence and the corresponding context information are used to construct structured data. The structured data is input into the large language model for segmentation and translation, generating a sequence of translated text blocks corresponding to the original text blocks.
4. The PDF translation method for maintaining document layout as described in claim 1, characterized in that, The step of drawing an occlusion rectangle consistent with the page background for the geometric coordinate region of each original text block on the page of the original PDF includes: Traverse each page of the original PDF and analyze the geometric coordinate region of the original text block to extract the background pixel information of the geometric coordinate region; The occlusion rectangle, whose geometric coordinates are consistent with the page background, is drawn based on the background pixel information.
5. The PDF translation method for maintaining document layout as described in claim 1, characterized in that, The step of drawing corresponding translation blocks at the same geometric coordinate positions on the occlusion rectangle, and adjusting the translation display using an adaptive scaling strategy when drawing the translation blocks to make the translation fit within the boundaries of the original text blocks, includes: On the occlusion rectangle, draw and insert corresponding translation blocks in the form of transparent text layers at the same geometric coordinate positions; When inserting the translation block, the font height of the translation block is kept the same as the original text height of the original text block, and the character spacing of the translation block is adjusted. If the translation of the translation block exceeds the boundary of the original text block, the translation of the translation block is adjusted by proportionally reducing the font size; If the height difference between the translated text and the original text is higher than a preset threshold, the font size of the translated text is enlarged or the character spacing of the translated text is increased so that the translated text fits within the boundary of the original text block.
6. The PDF translation method for maintaining document layout as described in claim 5, characterized in that, If the height difference between the translated text and the original text exceeds a preset threshold, the method further includes enlarging the font size of the translated text or increasing the character spacing of the translated text to fit within the boundaries of the original text block. The font color, weight, and font family of the translated text block should be consistent with the corresponding original text block. When the target font is unavailable, the visual effect is compared with multiple alternative fonts based on the original text block, and the target alternative font is determined based on the comparison results.
7. The PDF translation method for maintaining document layout as described in any one of claims 1 to 6, characterized in that, After visually sorting the original text blocks in the original text block set according to the geometric coordinates to generate an ordered text block sequence, the method further includes: If the original PDF file contains tables, then the tables in the original PDF file are detected and identified, and the table structure and cell content are extracted. The table content is incorporated into the ordered sequence of text blocks in a structured form.
8. A PDF translation device that maintains document layout, characterized in that, include: The text block extraction module is used to extract the geometric coordinates, text information, and layout attributes of each text block in the original PDF file, forming an original text block set; The reading order sorting module is used to perform visual reading order sorting of the original text blocks in the original text block set according to the geometric coordinates, and generate an ordered text block sequence. The intelligent translation module is used to input the ordered text block sequence and the context information corresponding to the ordered text block sequence into the large language model for block segmentation and translation, and generate a translated text block sequence corresponding to the original text block; The background occlusion module is used to draw an occlusion rectangle consistent with the page background for the geometric coordinate area of each original text block on the page of the original PDF. The translation drawing module is used to draw corresponding translation blocks at the same geometric coordinate positions on the occlusion rectangle, and to adjust the translation display using an adaptive scaling strategy when drawing the translation blocks so that the translation fits within the boundary of the original text block; The PDF output module is used to save and output a new PDF file containing the translated text blocks.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the PDF translation method for maintaining document layout as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the PDF translation method for maintaining document layout as described in any one of claims 1 to 7.