CN114004209A - PDF format data export method and device, electronic equipment and readable storage medium - Google Patents
PDF format data export method and device, electronic equipment and readable storage medium Download PDFInfo
- Publication number
- CN114004209A CN114004209A CN202111274232.2A CN202111274232A CN114004209A CN 114004209 A CN114004209 A CN 114004209A CN 202111274232 A CN202111274232 A CN 202111274232A CN 114004209 A CN114004209 A CN 114004209A
- Authority
- CN
- China
- Prior art keywords
- data
- height
- paging
- exported
- rendering
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 65
- 238000009877 rendering Methods 0.000 claims abstract description 64
- 238000012545 processing Methods 0.000 claims abstract description 33
- 238000004590 computer program Methods 0.000 claims description 12
- 238000006243 chemical reaction Methods 0.000 claims description 6
- 238000004364 calculation method Methods 0.000 claims description 4
- 238000009795 derivation Methods 0.000 claims description 3
- 238000005516 engineering process Methods 0.000 abstract description 12
- 238000013473 artificial intelligence Methods 0.000 abstract description 7
- 230000006870 function Effects 0.000 description 8
- 238000004891 communication Methods 0.000 description 7
- 238000007726 management method Methods 0.000 description 5
- 238000010586 diagram Methods 0.000 description 4
- 239000004973 liquid crystal related substance Substances 0.000 description 4
- 230000008569 process Effects 0.000 description 4
- 230000009466 transformation Effects 0.000 description 4
- 230000004048 modification Effects 0.000 description 3
- 238000012986 modification Methods 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 2
- 230000005540 biological transmission Effects 0.000 description 1
- 238000004422 calculation algorithm Methods 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000013135 deep learning Methods 0.000 description 1
- 238000001514 detection method Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 238000003058 natural language processing Methods 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/10—Text processing
- G06F40/166—Editing, e.g. inserting or deleting
- G06F40/186—Templates
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/957—Browsing optimisation, e.g. caching or content distillation
- G06F16/9577—Optimising the visualization of content, e.g. distillation of HTML documents
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/10—Text processing
- G06F40/12—Use of codes for handling textual entities
- G06F40/151—Transformation
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Audiology, Speech & Language Pathology (AREA)
- Computational Linguistics (AREA)
- General Health & Medical Sciences (AREA)
- Health & Medical Sciences (AREA)
- Artificial Intelligence (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention relates to an artificial intelligence technology, and discloses a PDF format data export method, which comprises the following steps: the method comprises the steps of obtaining table data to be exported, rendering the table data to be exported into a preset auxiliary table, calculating the data height of the table data to be exported based on the auxiliary table, performing paging processing on the table data to be exported by utilizing the data height to obtain paging data, performing batch rendering on the paging data, performing format splicing on the rendered paging data, and obtaining PDF format data. In addition, the invention also relates to a block chain technology, and the table data to be derived can be obtained from the nodes of the block chain. The invention also provides a PDF format data export method and device, electronic equipment and a computer readable storage medium. The invention can solve the problem of inaccurate data when PDF format data is exported.
Description
Technical Field
The invention relates to the technical field of artificial intelligence, in particular to a PDF format data export method and device, electronic equipment and a computer readable storage medium.
Background
With the development of the internet, front-end services become more diversified, the front-end exporting page data in a PDF format is more and more common in the current front-end services, before a big front-end is started, the work of exporting data in a PDF format is finished by a background server, although the background server can realize the function, a lot of problems exist, for example, when the background server exports form data in a PDF format, data paging, a custom style, a custom header and footer become very troublesome work, even if the same data paging is cut off, and the exported PDF form is difficult to reach a preset style.
In the prior art, when data is exported to a PDF format by a front-end technology, only paging of a page to export a PDF file is supported, but the situation that exported data such as data truncation and blank data is inaccurate still exists in the exporting process, and a browser is often jammed in the exporting process.
Disclosure of Invention
The invention provides a method, a device, equipment and a storage medium for exporting PDF format data, and mainly aims to solve the problem of inaccurate data when the PDF format data is exported.
In order to achieve the above object, the present invention provides a method for exporting PDF format data, comprising:
the method comprises the steps of obtaining table data to be exported, and utilizing a preset rendering template to render the table data to be exported into a preset auxiliary table;
calculating the data height of the table data to be derived based on the auxiliary table;
acquiring a preset page size, and performing paging processing on the table data to be exported by using the page size and the data height to obtain paging data;
and rendering the paging data in batches, performing image conversion on the rendered paging data, and performing format splicing on the image-converted paging data to obtain PDF format data.
Optionally, the rendering the table data to be derived into a preset auxiliary table by using a preset rendering template includes:
reading character string information in the table data to be exported by using the rendering template;
splicing the read character string information, and filling the spliced character string information into the auxiliary table based on the rendering template.
Optionally, the calculating the data height of the table data to be derived based on the auxiliary table includes:
constructing a table document object model based on the labels and the attributes of the auxiliary table;
and traversing the data height of each row of data in the auxiliary table by using the table document object model.
Optionally, the performing paging processing on the table data to be exported by using the page size and the data height to obtain paged data includes:
judging whether the data height of the traversed single-row data exceeds the height of the page size;
if the data height of the single line of data exceeds the height of the page size, carrying out scaling processing on the single line of data;
and if the data height of the single-row data does not exceed the height of the page size, accumulating the data height of the single-row data, and performing paging processing on the table data to be exported according to the accumulated height to obtain paging data.
Optionally, the accumulating the data height of the single line of data, and performing paging processing on the table data to be exported according to the accumulated height to obtain paged data includes:
constructing a two-dimensional array, and accumulating the data height of the traversed single-row data to obtain an accumulated height;
judging whether the accumulated height exceeds the height of the page size;
if the accumulated height does not exceed the height of the page size, continuing to execute the step of accumulating the data height of the traversed single-row data, and storing the table data corresponding to the accumulated height as paging data into a sub-array of the two-dimensional array;
and if the accumulated height exceeds the height of the page size, taking the last traversed single-row data as paging data of the next page, and executing the step of accumulating the data height of the traversed single-row data again until all the single-row data are stored in the sub-array of the two-dimensional array.
Optionally, the rendering the paging data in batch, performing image transformation on the rendered paging data, and performing format splicing on the image-transformed paging data to obtain PDF format data includes:
constructing a page table according to the page size, and rendering the paging data of each sub-array in the two-dimensional array into the page table in sequence by using a preset rendering method;
and capturing the page form by using a preset capture plugin to obtain a form image, converting all the form images into PDF format pages, and splicing the PDF format pages according to the sequence of each sub-array in the two-dimensional array to obtain the PDF format data.
Optionally, the obtaining of the table data to be derived includes:
receiving a request address input by a user on a front-end page, and analyzing a domain name of the request address;
and searching the IP address corresponding to the domain name, and receiving the table data to be derived returned by the IP address.
In order to solve the above problem, the present invention further provides a PDF format data exporting apparatus, including:
the data rendering module is used for acquiring the table data to be exported and rendering the table data to be exported into a preset auxiliary table by using a preset rendering template;
the data height calculation module is used for calculating the data height of the table data to be derived based on the auxiliary table;
the data paging module is used for acquiring a preset page size, and paging the table data to be exported by using the page size and the data height to obtain paging data;
and the data splicing module is used for rendering the paging data in batches, converting the rendered paging data into images, and performing format splicing on the converted paging data to obtain PDF format data.
In order to solve the above problem, the present invention also provides an electronic device, including:
a memory storing at least one computer program; and
and the processor executes the computer program stored in the memory to realize the PDF format data export method.
In order to solve the above problem, the present invention also provides a computer-readable storage medium in which at least one computer program is stored, the at least one computer program being executed by a processor in an electronic device to implement the above PDF format data exporting method.
The invention calculates the data height occupied by each row of data in the table data to be exported through establishing an auxiliary table, and pages the data through the calculated data height, which is similar to the way of cutting one data table into a plurality of data tables. Meanwhile, because the batch rendering is carried out, only one page is rendered at each time, the stable operation of the browser is ensured, and the problems of dead jamming and collapse of the browser and data loss when the data volume is large are solved. Therefore, the PDF format data export method, the PDF format data export device, the electronic equipment and the computer readable storage medium can solve the problem of inaccurate data when the PDF format data are exported.
Drawings
Fig. 1 is a schematic flowchart of a PDF format data export method according to an embodiment of the present invention;
fig. 2 is a functional block diagram of a PDF format data exporting apparatus according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of an electronic device for implementing the PDF format data exporting method according to an embodiment of the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The embodiment of the application provides a PDF format data export method. The execution subject of the PDF format data exporting method includes, but is not limited to, at least one of electronic devices such as a server and a terminal that can be configured to execute the method provided by the embodiments of the present application. In other words, the PDF formatted data derivation method may be performed by software installed in a terminal device or a server device, or hardware, and the software may be a block chain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, and the like. The server may be an independent server, or may be a cloud server that provides basic cloud computing services such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a Network service, cloud communication, a middleware service, a domain name service, a security service, a Content Delivery Network (CDN), a big data and artificial intelligence platform, and the like.
Fig. 1 is a schematic flow chart of a PDF format data exporting method according to an embodiment of the present invention. In this embodiment, the PDF format data derivation method includes:
and S1, acquiring the table data to be exported, and utilizing a preset rendering template to render the table data to be exported into a preset auxiliary table.
In the embodiment of the present invention, the table data to be exported may be table text data in various fields, for example, a student achievement table, a commodity inventory table, and the like. The preset auxiliary table is a hidden table rendered in a front-end browser and used for assisting in calculating the data height, the data style and the like of data in the table data to be exported. The rendering refers to splicing data together in a front-end page (such as a browser) by using a template, for example, requesting the back-end interface data, and then binding the data into a specific table or page through a binding syntax of the template, and finally presenting the data to a user.
Specifically, the acquiring the table data to be derived includes:
receiving a request address input by a user on a front-end page, and analyzing a domain name of the request address;
and searching the IP address corresponding to the domain name, and receiving the table data to be derived returned by the IP address.
In the embodiment of the present invention, the request address may be a page address input by a user in an address bar of a front-end browser page, and the input address may be resolved by using a DNS (Domain Name System, Domain Name resolution System) to obtain a Domain Name and search for a corresponding IP, and then a data request is initiated to the IP address to obtain table data fed back by the IP address.
In detail, the rendering the table data to be derived into a preset auxiliary table by using a preset rendering template includes:
reading character string information in the table data to be exported by using the rendering template;
splicing the read character string information, and filling the spliced character string information into the auxiliary table based on the rendering template.
In the embodiment of the present invention, the preset rendering template may be an HTML template. The string information is a table field in the table data to be derived, for example, the string information of the student achievement table includes: table fields of "name", "grade", "gender" and "achievement".
In the embodiment of the invention, a hidden form is rendered in a front-end browser, all the requested form data are rendered in an auxiliary form, and the auxiliary form is used for performing auxiliary calculation, so that the problem that PDF format data are difficult to control when a pure background directly derives can be avoided.
And S2, calculating the data height of the table data to be derived based on the auxiliary table.
Specifically, the calculating the data height of the table data to be derived based on the auxiliary table includes:
constructing a table document object model based on the labels and the attributes of the auxiliary table;
and traversing the data height of each row of data in the auxiliary table by using the table document object model.
In the embodiment of the invention, the form Document Object Model (DOM for short) is an API Document based on a tree, the form DOM provides an access Model for the whole form, the form is taken as a tree structure, each node of the tree represents a form HTML tag or a text item in the tag, the tree structure of the form DOM can accurately describe the correlation between tags in the HTML Document, and the form DOM not only describes the structure of the form, but also defines the attribute of the node Object, and the nodes and contents in the DOM can be conveniently accessed, modified, added and deleted by using the method and the attribute of the Object.
In an alternative embodiment of the present invention, the tags include < capture >, < th >, < then >, < tbody >, < tfoot >, etc., where < capture > represents the table title, < th > represents the name of the row or column of the table, < then > represents the table header, < tbody > represents the table body, and < tfoot > represents the footer; the attributes comprise a summary attribute, a boarder color attribute, a cellpacking attribute and the like, wherein the summary attribute is used for summarizing the content of the whole table, the boarder color attribute is used for setting the color of a frame of the table, and the cellpacking attribute is used for setting the space between cells of the table.
In another optional embodiment of the present invention, after the table document object model is constructed based on the tags and attributes of the auxiliary table, the method further includes: and receiving an adjusting instruction of a user in the table document object model.
In detail, the adjustment instruction may include an add row instruction, a column instruction, a style adjustment instruction, a cell content modification instruction, and the like.
According to the method and the device, the data height of each row of data of the form can be rapidly determined by traversing the form DOM of the auxiliary form, and meanwhile, the form data can be adjusted by adjusting the label or the attribute in the form DOM, so that the form style can be intuitively adjusted, and the feasibility of adjusting the form data is improved.
And S3, acquiring a preset page size, and performing paging processing on the table data to be exported by using the page size and the data height to obtain paging data.
Specifically, the performing paging processing on the table data to be exported by using the page size and the data height to obtain paged data includes:
judging whether the data height of the traversed single-row data exceeds the height of the page size;
if the data height of the single line of data exceeds the height of the page size, carrying out scaling processing on the single line of data;
and if the data height of the single-row data does not exceed the height of the page size, accumulating the data height of the single-row data, and performing paging processing on the table data to be exported according to the accumulated height to obtain paging data.
In an embodiment of the present invention, the preset page size may be a page size of a 4. When the table data to be exported is subjected to paging processing by traversing the data height of the single-line data, if the data height of the current single-line data is larger than the height of the page size to be exported, the current single-line data is subjected to scaling processing, so that the data height of the current single-line data does not exceed the height of the page size.
In detail, the accumulating the data height of the single line of data, and performing paging processing on the table data to be exported according to the accumulated height to obtain paged data includes:
constructing a two-dimensional array, and accumulating the data height of the traversed single-row data to obtain an accumulated height;
judging whether the accumulated height exceeds the height of the page size;
if the accumulated height does not exceed the height of the page size, continuing to execute the step of accumulating the data height of the traversed single-row data, and storing the table data corresponding to the accumulated height as paging data into a sub-array of the two-dimensional array;
and if the accumulated height exceeds the height of the page size, taking the last traversed single-row data as paging data of the next page, and executing the step of accumulating the data height of the traversed single-row data again until all the single-row data are stored in the sub-array of the two-dimensional array.
In the embodiment of the present invention, a two-dimensional array is constructed to store paging data of each paging, wherein each sub-array in the two-dimensional array stores different paging data and paging conditions, for example, the two-dimensional array stores: "page 1: page data 1 "," page 2: page data 2 "," page 3: paging data 3 ", and the like.
Furthermore, the table data to be exported is subjected to paging processing through the data height, so that the condition that the data is cut off when the data is exported can be avoided.
And S4, rendering the paging data in batches, converting the rendered paging data into images, and splicing the converted paging data into PDF format data.
Specifically, the rendering the paging data in batches, performing image transformation on the rendered paging data, and performing format splicing on the image-transformed paging data to obtain PDF format data includes:
constructing a page table according to the page size, and rendering the paging data of each sub-array in the two-dimensional array into the page table in sequence by using a preset rendering method;
and capturing the page form by using a preset capture plugin to obtain a form image, converting all the form images into PDF format pages, and splicing the PDF format pages according to the sequence of each sub-array in the two-dimensional array to obtain the PDF format data.
In the embodiment of the present invention, the preset rendering method may be a requestanamationframe method, where the requestanamationframe method centralizes all DOM operations in each frame, and completes the DOM operations in one redrawing or reflowing, and a time interval of the redrawing or reflowing closely follows a refresh frequency of a browser (which may be 60 frames per second), so as to optimize rendering performance of a front-end browser, and effectively solve a problem of deadlocking caused by a large data volume of the browser. Meanwhile, the preset and screenshot plug-in can be an html2canvas plug-in, the form image is converted into a PDF format page based on a jsspdf method, and all the obtained PDF pages are finally merged and exported to be a PDF file through the jsspdf method.
The invention calculates the data height occupied by each row of data in the table data to be exported through establishing an auxiliary table, and pages the data through the calculated data height, which is similar to the way of cutting one data table into a plurality of data tables. Meanwhile, because the batch rendering is carried out, only one page is rendered at each time, the stable operation of the browser is ensured, and the problems of dead jamming and collapse of the browser and data loss when the data volume is large are solved. Therefore, the PDF format data export method provided by the invention can solve the problem of inaccurate data when the PDF format data is exported.
Fig. 2 is a functional block diagram of a PDF format data exporting apparatus according to an embodiment of the present invention.
The PDF format data exporting apparatus 100 according to the present invention may be installed in an electronic device. According to the implemented functions, the PDF format data exporting apparatus 100 may include a data rendering module 101, a data height calculating module 102, a data paging module 103, and a data splicing module 104. The module of the present invention, which may also be referred to as a unit, refers to a series of computer program segments that can be executed by a processor of an electronic device and that can perform a fixed function, and that are stored in a memory of the electronic device.
In the present embodiment, the functions regarding the respective modules/units are as follows:
the data rendering module 101 is configured to acquire table data to be derived, and render the table data to be derived into a preset auxiliary table by using a preset rendering template;
the data height calculating module 102 is configured to calculate a data height of the table data to be derived based on the auxiliary table;
the data paging module 103 is configured to obtain a preset page size, and perform paging processing on the table data to be exported by using the page size and the data height to obtain paging data;
the data splicing module 104 is configured to render the paging data in batches, perform image transformation on the rendered paging data, and perform format splicing on the image-transformed paging data to obtain PDF format data.
In detail, the specific implementation of each module of the PDF format data exporting apparatus 100 is as follows:
the method comprises the steps of firstly, obtaining table data to be exported, and utilizing a preset rendering template to render the table data to be exported into a preset auxiliary table.
In the embodiment of the present invention, the table data to be exported may be table text data in various fields, for example, a student achievement table, a commodity inventory table, and the like. The preset auxiliary table is a hidden table rendered in a front-end browser and used for assisting in calculating the data height, the data style and the like of data in the table data to be exported. The rendering refers to splicing data together in a front-end page (such as a browser) by using a template, for example, requesting the back-end interface data, and then binding the data into a specific table or page through a binding syntax of the template, and finally presenting the data to a user.
Specifically, the acquiring the table data to be derived includes:
receiving a request address input by a user on a front-end page, and analyzing a domain name of the request address;
and searching the IP address corresponding to the domain name, and receiving the table data to be derived returned by the IP address.
In the embodiment of the present invention, the request address may be a page address input by a user in an address bar of a front-end browser page, and the input address may be resolved by using a DNS (Domain Name System, Domain Name resolution System) to obtain a Domain Name and search for a corresponding IP, and then a data request is initiated to the IP address to obtain table data fed back by the IP address.
In detail, the rendering the table data to be derived into a preset auxiliary table by using a preset rendering template includes:
reading character string information in the table data to be exported by using the rendering template;
splicing the read character string information, and filling the spliced character string information into the auxiliary table based on the rendering template.
In the embodiment of the present invention, the preset rendering template may be an HTML template. The string information is a table field in the table data to be derived, for example, the string information of the student achievement table includes: table fields of "name", "grade", "gender" and "achievement".
In the embodiment of the invention, a hidden form is rendered in a front-end browser, all the requested form data are rendered in an auxiliary form, and the auxiliary form is used for performing auxiliary calculation, so that the problem that PDF format data are difficult to control when a pure background directly derives can be avoided.
And secondly, calculating the data height of the table data to be derived based on the auxiliary table.
Specifically, the calculating the data height of the table data to be derived based on the auxiliary table includes:
constructing a table document object model based on the labels and the attributes of the auxiliary table;
and traversing the data height of each row of data in the auxiliary table by using the table document object model.
In the embodiment of the invention, the form Document Object Model (DOM for short) is an API Document based on a tree, the form DOM provides an access Model for the whole form, the form is taken as a tree structure, each node of the tree represents a form HTML tag or a text item in the tag, the tree structure of the form DOM can accurately describe the correlation between tags in the HTML Document, and the form DOM not only describes the structure of the form, but also defines the attribute of the node Object, and the nodes and contents in the DOM can be conveniently accessed, modified, added and deleted by using the method and the attribute of the Object.
In an alternative embodiment of the present invention, the tags include < capture >, < th >, < then >, < tbody >, < tfoot >, etc., where < capture > represents the table title, < th > represents the name of the row or column of the table, < then > represents the table header, < tbody > represents the table body, and < tfoot > represents the footer; the attributes comprise a summary attribute, a boarder color attribute, a cellpacking attribute and the like, wherein the summary attribute is used for summarizing the content of the whole table, the boarder color attribute is used for setting the color of a frame of the table, and the cellpacking attribute is used for setting the space between cells of the table.
In another optional embodiment of the present invention, after the table document object model is constructed based on the tags and attributes of the auxiliary table, the method further includes: and receiving an adjusting instruction of a user in the table document object model.
In detail, the adjustment instruction may include an add row instruction, a column instruction, a style adjustment instruction, a cell content modification instruction, and the like.
According to the method and the device, the data height of each row of data of the form can be rapidly determined by traversing the form DOM of the auxiliary form, and meanwhile, the form data can be adjusted by adjusting the label or the attribute in the form DOM, so that the form style can be intuitively adjusted, and the feasibility of adjusting the form data is improved.
And step three, acquiring a preset page size, and performing paging processing on the table data to be exported by using the page size and the data height to obtain paging data.
Specifically, the performing paging processing on the table data to be exported by using the page size and the data height to obtain paged data includes:
judging whether the data height of the traversed single-row data exceeds the height of the page size;
if the data height of the single line of data exceeds the height of the page size, carrying out scaling processing on the single line of data;
and if the data height of the single-row data does not exceed the height of the page size, accumulating the data height of the single-row data, and performing paging processing on the table data to be exported according to the accumulated height to obtain paging data.
In an embodiment of the present invention, the preset page size may be a page size of a 4. When the table data to be exported is subjected to paging processing by traversing the data height of the single-line data, if the data height of the current single-line data is larger than the height of the page size to be exported, the current single-line data is subjected to scaling processing, so that the data height of the current single-line data does not exceed the height of the page size.
In detail, the accumulating the data height of the single line of data, and performing paging processing on the table data to be exported according to the accumulated height to obtain paged data includes:
constructing a two-dimensional array, and accumulating the data height of the traversed single-row data to obtain an accumulated height;
judging whether the accumulated height exceeds the height of the page size;
if the accumulated height does not exceed the height of the page size, continuing to execute the step of accumulating the data height of the traversed single-row data, and storing the table data corresponding to the accumulated height as paging data into a sub-array of the two-dimensional array;
and if the accumulated height exceeds the height of the page size, taking the last traversed single-row data as paging data of the next page, and executing the step of accumulating the data height of the traversed single-row data again until all the single-row data are stored in the sub-array of the two-dimensional array.
In the embodiment of the present invention, a two-dimensional array is constructed to store paging data of each paging, wherein each sub-array in the two-dimensional array stores different paging data and paging conditions, for example, the two-dimensional array stores: "page 1: page data 1 "," page 2: page data 2 "," page 3: paging data 3 ", and the like.
Furthermore, the table data to be exported is subjected to paging processing through the data height, so that the condition that the data is cut off when the data is exported can be avoided.
And step four, rendering the paging data in batches, performing image conversion on the rendered paging data, and performing format splicing on the image-converted paging data to obtain PDF format data.
Specifically, the rendering the paging data in batches, performing image transformation on the rendered paging data, and performing format splicing on the image-transformed paging data to obtain PDF format data includes:
constructing a page table according to the page size, and rendering the paging data of each sub-array in the two-dimensional array into the page table in sequence by using a preset rendering method;
and capturing the page form by using a preset capture plugin to obtain a form image, converting all the form images into PDF format pages, and splicing the PDF format pages according to the sequence of each sub-array in the two-dimensional array to obtain the PDF format data.
In the embodiment of the present invention, the preset rendering method may be a requestanamationframe method, where the requestanamationframe method centralizes all DOM operations in each frame, and completes the DOM operations in one redrawing or reflowing, and a time interval of the redrawing or reflowing closely follows a refresh frequency of a browser (which may be 60 frames per second), so as to optimize rendering performance of a front-end browser, and effectively solve a problem of deadlocking caused by a large data volume of the browser. Meanwhile, the preset and screenshot plug-in can be an html2canvas plug-in, the form image is converted into a PDF format page based on a jsspdf method, and all the obtained PDF pages are finally merged and exported to be a PDF file through the jsspdf method.
The invention calculates the data height occupied by each row of data in the table data to be exported through establishing an auxiliary table, and pages the data through the calculated data height, which is similar to the way of cutting one data table into a plurality of data tables. Meanwhile, because the batch rendering is carried out, only one page is rendered at each time, the stable operation of the browser is ensured, and the problems of dead jamming and collapse of the browser and data loss when the data volume is large are solved. Therefore, the PDF format data export device provided by the invention can solve the problem of inaccurate data when the PDF format data is exported.
Fig. 3 is a schematic structural diagram of an electronic device for implementing a method for exporting PDF format data according to an embodiment of the present invention.
The electronic device may comprise a processor 10, a memory 11, a communication interface 12 and a bus 13, and may further comprise a computer program, such as a PDF formatted data derivation program, stored in the memory 11 and executable on the processor 10.
The memory 11 includes at least one type of readable storage medium, which includes flash memory, removable hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, etc. The memory 11 may in some embodiments be an internal storage unit of the electronic device, for example a removable hard disk of the electronic device. The memory 11 may also be an external storage device of the electronic device in other embodiments, such as a plug-in mobile hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the electronic device. Further, the memory 11 may also include both an internal storage unit and an external storage device of the electronic device. The memory 11 may be used not only to store application software installed in the electronic device and various types of data, such as codes of a PDF format data derivation program, but also to temporarily store data that has been output or is to be output.
The processor 10 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or may be composed of a plurality of integrated circuits packaged with the same or different functions, including one or more Central Processing Units (CPUs), microprocessors, digital Processing chips, graphics processors, and combinations of various control chips. The processor 10 is a Control Unit (Control Unit) of the electronic device, connects various components of the electronic device by using various interfaces and lines, and executes various functions and processes data of the electronic device by running or executing programs or modules (e.g., PDF format data derivation program, etc.) stored in the memory 11 and calling data stored in the memory 11.
The communication interface 12 is used for communication between the electronic device and other devices, and includes a network interface and a user interface. Optionally, the network interface may include a wired interface and/or a wireless interface (e.g., WI-FI interface, bluetooth interface, etc.), which are typically used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a Display (Display), an input unit such as a Keyboard (Keyboard), and optionally a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable, among other things, for displaying information processed in the electronic device and for displaying a visualized user interface.
The bus 13 may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus 13 may be divided into an address bus, a data bus, a control bus, etc. The bus 13 is arranged to enable connection communication between the memory 11 and at least one processor 10 or the like.
Fig. 3 shows only an electronic device having components, and those skilled in the art will appreciate that the structure shown in fig. 3 does not constitute a limitation of the electronic device, and may include fewer or more components than those shown, or some components may be combined, or a different arrangement of components.
For example, although not shown, the electronic device may further include a power supply (such as a battery) for supplying power to each component, and preferably, the power supply may be logically connected to the at least one processor 10 through a power management device, so that functions of charge management, discharge management, power consumption management and the like are realized through the power management device. The power supply may also include any component of one or more dc or ac power sources, recharging devices, power failure detection circuitry, power converters or inverters, power status indicators, and the like. The electronic device may further include various sensors, a bluetooth module, a Wi-Fi module, and the like, which are not described herein again.
Further, the electronic device may further include a network interface, and optionally, the network interface may include a wired interface and/or a wireless interface (such as a WI-FI interface, a bluetooth interface, etc.), which are generally used to establish a communication connection between the electronic device and other electronic devices.
Optionally, the electronic device may further comprise a user interface, which may be a Display (Display), an input unit (such as a Keyboard), and optionally a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable, among other things, for displaying information processed in the electronic device and for displaying a visualized user interface.
It is to be understood that the described embodiments are for purposes of illustration only and that the scope of the appended claims is not limited to such structures.
The PDF formatted data derivation program stored in the memory 11 of the electronic device is a combination of instructions that, when executed in the processor 10, may implement:
the method comprises the steps of obtaining table data to be exported, and utilizing a preset rendering template to render the table data to be exported into a preset auxiliary table;
calculating the data height of the table data to be derived based on the auxiliary table;
acquiring a preset page size, and performing paging processing on the table data to be exported by using the page size and the data height to obtain paging data;
and rendering the paging data in batches, performing image conversion on the rendered paging data, and performing format splicing on the image-converted paging data to obtain PDF format data.
Specifically, the specific implementation method of the instruction by the processor 10 may refer to the description of the relevant steps in the embodiment corresponding to the drawings, which is not described herein again.
Further, the electronic device integrated module/unit, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in a computer readable storage medium. The computer readable storage medium may be volatile or non-volatile. For example, the computer-readable medium may include: any entity or device capable of carrying said computer program code, recording medium, U-disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM).
The present invention also provides a computer-readable storage medium, storing a computer program which, when executed by a processor of an electronic device, may implement:
the method comprises the steps of obtaining table data to be exported, and utilizing a preset rendering template to render the table data to be exported into a preset auxiliary table;
calculating the data height of the table data to be derived based on the auxiliary table;
acquiring a preset page size, and performing paging processing on the table data to be exported by using the page size and the data height to obtain paging data;
and rendering the paging data in batches, performing image conversion on the rendered paging data, and performing format splicing on the image-converted paging data to obtain PDF format data.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus, device and method can be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential attributes thereof.
The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
The embodiment of the application can acquire and process related data based on an artificial intelligence technology. Among them, Artificial Intelligence (AI) is a theory, method, technique and application system that simulates, extends and expands human Intelligence using a digital computer or a machine controlled by a digital computer, senses the environment, acquires knowledge and uses the knowledge to obtain the best result.
The artificial intelligence infrastructure generally includes technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation/interaction systems, mechatronics, and the like. The artificial intelligence software technology mainly comprises a computer vision technology, a robot technology, a biological recognition technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and the like.
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the system claims may also be implemented by one unit or means in software or hardware. The terms second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions may be made on the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.
Claims (10)
1. A method for deriving PDF format data, the method comprising:
the method comprises the steps of obtaining table data to be exported, and utilizing a preset rendering template to render the table data to be exported into a preset auxiliary table;
calculating the data height of the table data to be derived based on the auxiliary table;
acquiring a preset page size, and performing paging processing on the table data to be exported by using the page size and the data height to obtain paging data;
and rendering the paging data in batches, performing image conversion on the rendered paging data, and performing format splicing on the image-converted paging data to obtain PDF format data.
2. The method as claimed in claim 1, wherein the step of rendering the table data to be derived into a preset auxiliary table by using a preset rendering template comprises:
reading character string information in the table data to be exported by using the rendering template;
splicing the read character string information, and filling the spliced character string information into the auxiliary table based on the rendering template.
3. The method for deriving PDF formatted data according to claim 1, wherein said calculating the data height of the table data to be derived based on said auxiliary table comprises:
constructing a table document object model based on the labels and the attributes of the auxiliary table;
and traversing the data height of each row of data in the auxiliary table by using the table document object model.
4. The method for exporting PDF formatted data according to claim 1, wherein the paging of the table data to be exported according to the page size and the data height to obtain paged data comprises:
judging whether the data height of the traversed single-row data exceeds the height of the page size;
if the data height of the single line of data exceeds the height of the page size, carrying out scaling processing on the single line of data;
and if the data height of the single-row data does not exceed the height of the page size, accumulating the data height of the single-row data, and performing paging processing on the table data to be exported according to the accumulated height to obtain paging data.
5. The method for deriving PDF formatted data according to claim 4, wherein said accumulating the data height of the single line data and paging the table data to be derived according to the accumulated height to obtain paged data comprises:
constructing a two-dimensional array, and accumulating the data height of the traversed single-row data to obtain an accumulated height;
judging whether the accumulated height exceeds the height of the page size;
if the accumulated height does not exceed the height of the page size, continuing to execute the step of accumulating the data height of the traversed single-row data, and storing the table data corresponding to the accumulated height as paging data into a sub-array of the two-dimensional array;
and if the accumulated height exceeds the height of the page size, taking the last traversed single-row data as paging data of the next page, and executing the step of accumulating the data height of the traversed single-row data again until all the single-row data are stored in the sub-array of the two-dimensional array.
6. The method for deriving PDF formatted data according to claim 5, wherein the step of rendering the paginated data in batches, the step of converting the rendered paginated data into images, and the step of performing format splicing on the paginated data after image conversion to obtain PDF formatted data comprises:
constructing a page table according to the page size, and rendering the paging data of each sub-array in the two-dimensional array into the page table in sequence by using a preset rendering method;
and capturing the page form by using a preset capture plugin to obtain a form image, converting all the form images into PDF format pages, and splicing the PDF format pages according to the sequence of each sub-array in the two-dimensional array to obtain the PDF format data.
7. The method according to any one of claims 1 to 4, wherein the obtaining the table data to be exported includes:
receiving a request address input by a user on a front-end page, and analyzing a domain name of the request address;
and searching the IP address corresponding to the domain name, and receiving the table data to be derived returned by the IP address.
8. A PDF formatted data exporting apparatus, comprising:
the data rendering module is used for acquiring the table data to be exported and rendering the table data to be exported into a preset auxiliary table by using a preset rendering template;
the data height calculation module is used for calculating the data height of the table data to be derived based on the auxiliary table;
the data paging module is used for acquiring a preset page size, and paging the table data to be exported by using the page size and the data height to obtain paging data;
and the data splicing module is used for rendering the paging data in batches, converting the rendered paging data into images, and performing format splicing on the converted paging data to obtain PDF format data.
9. An electronic device, characterized in that the electronic device comprises:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores a computer program executable by the at least one processor, the computer program being executable by the at least one processor to enable the at least one processor to perform the PDF formatted data derivation method of any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, wherein the computer program is executed by a processor to implement the PDF formatted data exporting method according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111274232.2A CN114004209A (en) | 2021-10-29 | 2021-10-29 | PDF format data export method and device, electronic equipment and readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111274232.2A CN114004209A (en) | 2021-10-29 | 2021-10-29 | PDF format data export method and device, electronic equipment and readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114004209A true CN114004209A (en) | 2022-02-01 |
Family
ID=79925542
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111274232.2A Pending CN114004209A (en) | 2021-10-29 | 2021-10-29 | PDF format data export method and device, electronic equipment and readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114004209A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116821166A (en) * | 2023-08-31 | 2023-09-29 | 云筑信息科技(成都)有限公司 | Distributed data export method |
-
2021
- 2021-10-29 CN CN202111274232.2A patent/CN114004209A/en active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116821166A (en) * | 2023-08-31 | 2023-09-29 | 云筑信息科技(成都)有限公司 | Distributed data export method |
CN116821166B (en) * | 2023-08-31 | 2023-12-08 | 云筑信息科技(成都)有限公司 | Distributed data export method |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN113095995B (en) | Webpage watermark adding method and device, electronic equipment and storage medium | |
CN109190062B (en) | Crawling method and device for target corpus data and storage medium | |
CN107590288B (en) | Method and device for extracting webpage image-text blocks | |
CN115048111B (en) | Code generation method, device, equipment and medium based on metadata | |
CN114979120A (en) | Data uploading method, device, equipment and storage medium | |
CN114241499A (en) | Table picture identification method, device and equipment and readable storage medium | |
CN114637866A (en) | Information management method and device for digital new media | |
CN114004209A (en) | PDF format data export method and device, electronic equipment and readable storage medium | |
CN117873486A (en) | Front-end and back-end code automatic generation method, device, equipment and storage medium | |
CN113360139A (en) | Integration method and device of front-end frame, electronic equipment and storage medium | |
CN112906351A (en) | PDF document generation method and device | |
CN111444235A (en) | Django-based data serialization method and device, computer equipment and storage medium | |
CN116542221A (en) | PDF file analysis preview method, device, equipment and storage medium | |
CN115016754A (en) | Method and device for synchronously displaying pages among devices, electronic device and medium | |
CN112149391B (en) | Information processing method, information processing apparatus, terminal device, and storage medium | |
CN114490666A (en) | Chart generation method, device and equipment based on data requirements and storage medium | |
CN113312568A (en) | Web information extraction method and system based on HTML source code and webpage snapshot | |
CN116628128B (en) | Method, device and equipment for standardization of supply chain data and storage medium thereof | |
CN113487698B (en) | Form generation method and device based on two-channel neural network model | |
CN113657076B (en) | Page operation record table generation method and device, electronic equipment and storage medium | |
CN112559919B (en) | Method and device for checking online document uploading, electronic equipment and storage medium | |
CN114491007A (en) | Data exposure method, device, equipment and storage medium | |
CN116226563A (en) | Rich text editing method, rich text editing device, electronic equipment and computer readable storage medium | |
CN118278373A (en) | Custom examination certificate template generation method and device and electronic equipment | |
CN113486266A (en) | Page label adding method, device, equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |