Web Page Printing Method, Device, Equipment and Medium
By cropping and re-typed web page content and dividing it into multiple image objects suitable for printing, the problem of inability to print web pages in the prior art is solved, and precise paging printing of large web pages is achieved.
Patent Information
- Application Number
- CN202210776214.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-30
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2042-06-30
AI Technical Summary
In the prior art, when printing a web page, if the page cannot be fully displayed in the current window, only the part of the page can be printed out, and the complete content cannot be printed.
By obtaining the size of the target page and the printing paper, we judge whether it can be printed in one page, and crop the page into multiple image objects when it cannot be printed. Each object is suitable for printing in one page, retype and render these objects to form a sequence of images to be printed, and finally call window.print() for printing.
It realizes that the web page is printed in full, and even if the page cannot be fully displayed within one page, the complete content can be output through paging printing.
Smart Images

Figure CN114969611B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of Internet technologies, and can be applied to the financial field or other fields. More specifically, it relates to a web page printing method, apparatus, device, medium, and program product. Background Art
[0002] In actual projects, there are often requirements to print web pages, such as printing report pages displayed on the front end, etc. In related technologies, when printing a front-end page, it can be achieved by calling the window.print() printing method provided by the browser. Among them, calling the window.print() printing method is essentially a program call to the browser's printing function menu. Similar to clicking the printing function menu, it can often only print the page part displayed in the current window. If the web page cannot be fully displayed within the current window, only a partial page can be printed. Summary of the Invention
[0003] In view of the above problems, the present disclosure provides a web page printing method, apparatus, device, medium, and program product that can accurately divide a web page into multiple images and print the multiple images one by one.
[0004] According to a first aspect of an embodiment of the present disclosure, a web page printing method is provided. The method includes: obtaining the size of a target page and the size of a printing paper; when the target page after being scaled at a specified minimum scaling ratio cannot be printed on one sheet of the printing paper, cropping the target page to obtain N picture objects, where each picture object is suitable for being printed on one sheet of the printing paper, and the N picture objects can be spliced to form the picture of the target page, where N is an integer greater than 1; re-typesetting and rendering the N picture objects to form a sequence of images to be printed; and printing the sequence of images to be printed.
[0005] According to an embodiment of the present disclosure, cropping the target page to obtain N picture objects includes: using canvas to crop the target page to obtain the N picture objects; and obtaining the Uniform Resource Locator (URL) of the N picture objects.
[0006] According to an embodiment of the present disclosure, re-typesetting and rendering the N picture objects to form a sequence of images to be printed includes: arranging N image tags determined based on the URLs of the N picture objects in a DIV container; and rendering the N image tags in the DIV container to obtain the sequence of images to be printed.
[0007] According to an embodiment of the present disclosure, the use of canvas to crop the target page includes: determining the number N of cropped image objects based on the size of the target page, the size of the printing paper and a preset printing zoom ratio; calculating the starting point coordinates for each capture from the target page based on the size of each screenshot and the number N of cropped image objects; and traversing N times, each time taking the starting point coordinates as the starting point from the target page, capturing the screen according to the size of each screenshot, and drawing it onto the canvas after scaling it according to the printing zoom ratio.
[0008] According to an embodiment of the present disclosure, determining the number N of cropped image objects based on the size of the target page, the size of the printing paper and a preset printing scale ratio includes: multiplying the horizontal size of the target page by the printing scale ratio, and then rounding up the horizontal size of the printing paper to obtain a horizontal cropping number m; multiplying the vertical size of the target page by the printing scale ratio, and then rounding up the vertical size of the printing paper to obtain a vertical cropping number n; and obtaining the value of N based on the product of the horizontal cropping number m and the vertical cropping number n.
[0009] According to an embodiment of the present disclosure, the method also includes: based on the ratio of the size of the target page and the size of the printing paper, obtaining a global scaling ratio when the target page can be printed within one page of printing paper; and if the global scaling ratio is less than the minimum scaling ratio, determining that the target page scaled according to the minimum scaling ratio cannot be printed within one page of the printing paper.
[0010] According to an embodiment of the present disclosure, printing the sequence of images to be printed includes: calling window.print() to print the sequence of images to be printed.
[0011] According to a second aspect of the embodiments of the present disclosure, a web page printing device is provided. The device includes an acquisition module, a cropping module, a rearrangement module, and a paging printing module. The acquisition module is used to acquire the size of the target page and the size of the printing paper. The cropping module is used to crop the target page to obtain N picture objects when the target page cannot be printed on one page of the printing paper after being scaled according to a specified minimum scaling ratio, wherein each picture object is suitable for printing on one page of the printing paper, and the N picture objects can be spliced to form a picture of the target page, wherein N is an integer greater than 1. The rearrangement module is used to rearrange and render the N picture objects to form a sequence of images to be printed. The paging printing module is used to print the sequence of images to be printed.
[0012] According to an embodiment of the present disclosure, the cropping module is specifically configured to: use canvas to crop the target page to obtain the N picture objects; and obtain the uniform resource locator (URL) of the N picture objects.
[0013] According to an embodiment of the present disclosure, the apparatus further includes a judgment module. The judgment module is configured to: obtain a global scaling ratio when the target page can be printed on one page of printing paper based on the ratio of the size of the target page to the size of the printing paper; and determine that the target page scaled according to the minimum scaling ratio cannot be printed on one page of the printing paper if the global scaling ratio is less than the minimum scaling ratio.
[0014] In a third aspect of the embodiments of the present disclosure, an electronic device is provided. The electronic device includes one or more processors and a memory. The memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors are caused to execute the above method.
[0015] In a fourth aspect of the embodiments of the present disclosure, a computer-readable storage medium is further provided, on which executable instructions are stored, and when the instructions are executed by a processor, the processor is caused to execute the above method.
[0016] In a fifth aspect of the embodiments of the present disclosure, a computer program product is further provided, including a computer program, and when the computer program is executed by a processor, the above method is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, the above content and other objects, features, and advantages of the present disclosure will become clearer. In the drawings:
[0018] Figure 1 Schematically shows an application scenario diagram of a web page printing method, apparatus, device, medium, and program product according to an embodiment of the present disclosure;
[0019] Figure 2 Schematically shows a flowchart of a web page printing method according to an embodiment of the present disclosure;
[0020] Figure 3 Schematically shows a flowchart of using canvas to crop a target page in a method according to an embodiment of the present disclosure;
[0021] Figure 4 Schematically shows a flowchart of re-typesetting and cropping the N picture objects in a method according to an embodiment of the present disclosure;
[0022] Figure 5 Schematically shows a schematic diagram of a page that can be printed on one page of printing paper;
[0023] Figure 6 A schematic diagram showing a page that cannot be fully displayed horizontally;
[0024] Figure 7 A schematic diagram showing a page that cannot be fully displayed vertically;
[0025] Figure 8 A schematic diagram showing a page that cannot be fully displayed both horizontally and vertically;
[0026] Figure 9 A schematic diagram showing a target page to be cropped according to an embodiment of the present disclosure;
[0027] Figure 10 A schematic diagram showing a picture object that is re - typeset and cropped according to an embodiment of the present disclosure;
[0028] Figure 11 A schematic block diagram showing the structure of a web page printing device according to an embodiment of the present disclosure; and
[0029] Figure 12 A block diagram showing an electronic device suitable for implementing a web page printing method according to an embodiment of the present disclosure. Detailed implementation manners
[0030] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are merely exemplary and are not intended to limit the scope of the present disclosure. In the following detailed description, for the sake of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, obviously, one or more embodiments can also be implemented without these specific details. In addition, in the following description, descriptions of well - known structures and technologies are omitted to avoid unnecessarily obscuring the concepts of the present disclosure.
[0031] The terms used herein are merely for describing specific embodiments and are not intended to limit the present disclosure. The terms "including", "comprising", etc. used herein indicate the presence of the described features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.
[0032] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.
[0033] In the case of using expressions such as "at least one of A, B, and C", generally, it should be interpreted according to the meaning that a person skilled in the art usually understands this expression (for example, "a system having at least one of A, B, and C" should include, but not be limited to, a system having only A, only B, only C, having A and B, having A and C, having B and C, and / or having A, B, and C, etc.). The terms "first" and "second" are only used for descriptive purposes and should not be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more features.
[0034] In their daily work, inventors often encounter the need to print front-end pages. Through inquiries and practices, the inventors found that for a certain page, if one wants to print the content therein completely, there are certain requirements for the size of the page. If the page width and height are within the requirements for complete printing, the window.print() printing method can be called to print the page content completely. If the page width and height are outside the requirements for complete printing, the drawbacks of calling window.print() will be revealed. Specifically, it often only prints the visible part of the page and directly discards the invisible part (which can be viewed after scrolling the mouse), which does not meet the actual requirements.
[0035] In view of this, the embodiments of the present disclosure provide a web page printing method, device, equipment, medium, and program product. To handle the situation where the page size is outside the requirements for complete printing, the page to be printed can be split into multiple images, and then the multiple images can be printed separately at one time, so that the content of the page to be printed can be printed completely.
[0036] Figure 1 An application scenario diagram of the web page printing method, device, equipment, medium, and program product according to the embodiments of the present disclosure is schematically shown. It should be noted that Figure 1 What is shown is only an example of the system architecture to which the embodiments of the present disclosure can be applied, to help a person skilled in the art understand the technical content of the present disclosure, but it does not mean that the embodiments of the present disclosure cannot be used in other devices, systems, environments, or scenarios.
[0037] As Figure 1 shown, the application scenario 100 according to this embodiment may include a terminal device 101, a network 102, and a server 103. Among them, the network 102 is used to provide a communication link between the terminal device 101 and the server 103. The network 102 may be, for example, the Internet, a local area network, etc.
[0038] The application scenario 100 may further include a network 104 and a printer 105. Among them, the network 104 is used to provide a communication link between the terminal device 101 and the printer 105. The network 104 may be, for example, a local area network (e.g., an intranet).
[0039] The network 102 or the network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.
[0040] The user can use the terminal device 101 to interact with the server 103 through the network 102 to receive or send messages, etc. Various communication client applications may be installed on the terminal device 101, such as financial applications, government affairs applications, shopping applications, web browser applications, etc. The terminal device 101 may be various electronic devices with a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, and desktop computers, etc.
[0041] The server 103 may be a server providing various services, such as a background management server (only for example) that supports the websites browsed by the user using the terminal device 101. The server 103 may analyze and process data such as received user requests, and feedback information such as web pages obtained or generated according to the user requests to the terminal device 101.
[0042] The user can also use the terminal device 101 to interact with the printer 105 through the network 104 to send a print task to the printer. For example, when the user needs to print the web page displayed on the terminal device 101, the terminal device 101 can be triggered to generate a print task, and then the print task is sent to the printer 105, and the printer 105 performs the printing operation. Of course, it can be understood that the printer 105 can also be replaced by a virtual printer built into the terminal device 101. For example, the user can print the web page to be printed into a picture or a PDF file, etc. through the virtual printer in the terminal device 101.
[0043] The web page printing method provided by the embodiments of the present disclosure may be executed by the terminal device 101. Correspondingly, the web page printing device provided by the embodiments of the present disclosure may be disposed in the terminal device 101.
[0044] Further, the web page printing method according to the embodiments of the present disclosure can be executed by a browser installed in the terminal device 101. Correspondingly, the web page printing apparatus provided by the embodiments of the present disclosure can be integrated into the browser installed in the terminal device 101, and implement corresponding functions by means of various controls and tools in the browser. Of course, it can be understood that the web page printing method according to the embodiments of the present disclosure can also be executed by an application program different from the browser installed in the terminal device 101 (for example, a specially developed printing tool). Correspondingly, the web page printing apparatus provided by the embodiments of the present disclosure can be installed in the terminal device 101 in a manner independent of the browser, and perform web page printing through interaction with the browser.
[0045] It should be understood that Figure 1 the numbers of the terminal devices, networks, servers, and printers in
[0046] are merely illustrative. According to the implementation requirements, there can be any number of terminal devices, network servers, and printers. Figure 1 The following will be based on Figures 2 - 10 the scenarios described below, and will describe the web page printing method according to the embodiments of the present disclosure in detail through
[0047] Figure 2 FIG. schematically shows a flowchart of the web page printing method according to the embodiments of the present disclosure.
[0048] As Figure 2 shown, the web page printing method according to this embodiment may include operation S210, operation S220, and operations S230 to S250 or operation S260.
[0049] First, in operation S210, obtain the size of the target page and the size of the printing paper. For example, when the user needs to print the target page, the target page can be displayed in the browser window of the terminal device 101, and then a preset operation is performed in the terminal device (such as right-clicking on the browser to select printing the current page, or clicking on the printing control in the browser, or starting a custom printing program, etc.) to trigger a printing instruction for the target page, and then in response to the printing instruction, obtain the size of the target page and the size of the printing paper.
[0050] Generally, the printing paper and the target page are rectangular pages, and the sizes of the printing paper and the target page mainly refer to the sizes in two dimensions of width and height from the user's perspective when the user browses the web page. For irregular web pages, they can also be processed as rectangular web pages. Of course, with the development of technology, the sizes of the printing paper and the target page may not be limited to rectangular sizes, and the present disclosure does not make any limitations in this regard.
[0051] Then, in operation S220, it is determined whether the target page can be printed on one sheet of printing paper after being scaled according to the specified minimum scaling ratio. If not, then pagination printing is performed through operations S230 to S250; if it can be printed on one sheet of printing paper, the target page is directly printed through operation S260. Among them, in operation S260, the printing function window.print() of the browser can be called for printing.
[0052] According to an embodiment of the present disclosure, when the target page cannot be fully displayed in the browser window of the terminal device 101, it can be combined with the specified minimum scaling ratio to determine whether it can be printed on one sheet of printing paper. Among them, the purpose of specifying this minimum scaling ratio is to ensure that after the web page is scaled and printed, the content of the printed web page can still be clearly seen. Therefore, if the size of the target page is larger than the size of the printing paper, the degree of scaling of the target page is limited. At this time, it is necessary to judge whether the target page can be appropriately scaled and printed on one sheet of printing paper based on the minimum printing ratio scaling.
[0053] Specifically, there are various ways to determine whether the target page can be printed on one sheet of printing paper after being scaled according to the specified minimum scaling ratio.
[0054] For example, according to the minimum scaling ratio and the size of the printing paper, the size range of the target page that can be printed on one sheet of printing paper can be reversely determined. Among them, when the size of the target page is within this size range, it is determined that the target page can be printed on one sheet of printing paper after being scaled.
[0055] For another example, based on the ratio of the size of the target page to the size of the printing paper, the global scaling ratio when the target page can just be printed on one sheet of printing paper can be obtained. If this global scaling ratio is less than the minimum scaling ratio, it is determined that the target page scaled according to the minimum scaling ratio cannot be printed on one sheet of printing paper.
[0056] Specifically, in one embodiment, the process of obtaining this global scaling ratio can be to calculate the ratios of the width and height sizes of the target page and the width and height sizes of the printing paper respectively, and then take the reciprocal of the larger value obtained. Or, in another embodiment, the process of obtaining this global scaling ratio can also be that when only one dimension (horizontal or vertical) of the target page exceeds the corresponding dimension of the printing paper, the ratio of the dimension is calculated, and then the reciprocal of the ratio is taken.
[0057] Next, in operation S230, when the target page scaled according to the specified minimum scaling ratio cannot be printed on one sheet of printing paper, the target page is cropped to obtain N picture objects. Among them, each picture object is suitable for printing on one sheet of printing paper, and the N picture objects can be spliced to form the picture of the target page. Among them, N is an integer greater than 1.
[0058] That each picture object is suitable for being printed on one sheet of printing paper may be, for example, that the size of each picture object is less than or equal to the size of the printing paper, or the ratios of the width and height of each picture object to the width and height of the printing paper are all within the ratio range determined based on the minimum scaling ratio.
[0059] In some embodiments, canvas can be used to crop the target page. In other embodiments, the target page can also be cropped by a custom web page cropping tool or script.
[0060] Figure 3 Schematically shown is a flowchart of using canvas to crop the target page in operation S230 of a method according to an embodiment of the present disclosure. As Figure 3 shown, according to this embodiment, operation S230 may include operation S301 to operation S302.
[0061] In operation S301, use canvas to crop the target page to obtain N picture objects.
[0062] In operation S302, obtain the Uniform Resource Locator (URL) of the N picture objects.
[0063] Specifically, the picture objects cropped by canvas can be cached in the browser, and the URL of each picture object is returned to facilitate subsequent processing of the N picture objects. When using canvas to crop the target page, relevant application programming interfaces (APIs) of canvas can be called for cropping, and the specific cropping process can refer to the detailed introduction in Figure 9 and Figure 10 below.
[0064] Return to Figure 2 . Next, in operation S240, re-layout and render the N picture objects to form a sequence of images to be printed.
[0065] In some embodiments, the N picture objects can be respectively converted into N pages, the N pages are arranged into a page sequence, and the page sequence is rendered to obtain a sequence of images to be printed. In certain embodiments, the page sequence can be processed as a printing task, facilitating printing of the N pages one by one through a single printing operation by the user.
[0066] In some other embodiments, when the URL addresses of N picture objects are fed back in operation S230, the DIV container in HyperText Markup Language (HTML) can be used to arrange the N picture objects obtained by cropping into the same DIV container in the form of tags, and then the browser is utilized to render the image elements in the DIV container to form a sequence of images to be printed. Specifically, reference can be made to the illustration in Figure 4 .
[0067] Figure 4 FIG. schematically shows a flowchart of re-typesetting the N cropped picture objects in operation S240 according to an embodiment of the present disclosure. As shown in Figure 4 , according to this embodiment, operation S240 may include operations S401 to operation 402.
[0068] First, in operation S401, N image tags determined based on the URLs of the N picture objects are arranged in the DIV container. The DIV container is an element used to provide structure and background for large chunks of content within an HTML document. Among them, all the content between the start tag and the end tag of the DIV is used to form this block. In this way, the N picture objects can be arranged in the form of tags in the front-to-back adjacent order in the target web page.
[0069] Then, in operation S402, the N image tags in the DIV container are rendered to obtain a sequence of images to be printed.
[0070] Continue to refer to Figure 2 . Next, in operation S250, the sequence of images to be printed is printed.
[0071] When printing is implemented by means of a browser, window.print() can be called to print the sequence of images to be printed. Specifically, the sequence of images to be printed (for example, the printing sequence in the DIV container) can be passed as a printing task to window.print(), and the N picture objects in the sequence of images to be printed are printed one by one through window.print().
[0072] Of course, in addition to relying on the printing tool of the browser itself, printing can also be performed through a custom script or tool independent of the browser. For example, this custom script or tool can be used to receive the sequence of images to be printed, take the sequence of images to be printed as a printing task, generate a printing instruction, and send it to the printer 105 to execute the printing operation.
[0073] It can be seen that according to the embodiments of the present disclosure, the target page can be cropped and screenshot, sliced into multiple picture objects, and then printed one by one to solve the problem that the target page is too wide or too high to be directly printed in full by window.print(). Among them, by disassembling the target page into multiple picture objects and then re-typesetting these picture objects, the requirement of precise paging printing can be met. These multiple picture objects can be spliced to form the picture of the target page, thereby ensuring the integrity of the content of the printed target page.
[0074] Moreover, the operations such as cropping and re-typesetting the target page in the embodiments of the present disclosure can be set as hidden operations of the program and are invisible to the user. In this way, when the user needs to print a page, the user can only trigger the print instruction according to the predetermined operation requirements. After the program runs automatically, multiple printed pages are output to the user. This not only ensures the integrity of the content of the printed target page but also does not bring an additional learning and usage burden to the user.
[0075] The embodiments of the present disclosure can solve the problems of incomplete printing caused by the page being too wide or too high and difficult precise paging printing. According to the embodiments of the present disclosure, calculations can be made based on the size of the target page to determine whether the page needs to be cropped and paged for printing, achieving precise paging printing and facilitating the user to print out the complete page content.
[0076] The following combines the situations that are often encountered when browsing or printing a page, as follows Figures 5 - 10 The following shows the specific implementation of the web page printing method according to the embodiments of the present disclosure in various situations for exemplary illustration.
[0077] Figure 5 A schematic diagram of a page that can be printed within one page of printing paper is schematically shown.
[0078] As Figure 5 shown, the current page 501 can be fully displayed in the visible area of the browser without the need to scroll the mouse left and right or up and down. In some cases, the printing paper of the corresponding size can be automatically matched according to the window size of the browser. In this way, in Figure 5 this case, when the page 501 can be fully displayed in the browser window, it means that the page 501 can be fully printed on one page of printing paper. Therefore, for this case, it can be directly printed through the above operation S260 without the need for operations such as cropping.
[0079] Figure 6 A schematic diagram of a page that cannot be fully displayed horizontally is schematically shown.
[0080] As Figure 6As shown, on the current page 601 in the browser window (or the visual interface of the print preview), the user needs to scroll the mouse left and right to view the entire page content. For printing such a page, if it can be fully displayed after scaling at the minimum scaling ratio in the width direction, or if the width dimension is less than the maximum width value allowed to be printed on one page after scaling at the minimum scaling ratio, the content printed on one page of the print paper after scaling this page 601 can also be clearly visible. For this situation, it can also be directly printed through the above operation S260 without performing operations such as web page cropping. However, if the width of page 601 has exceeded the above maximum width value, then after scaling this page 601 at the minimum scaling ratio, it still cannot be printed on one page of the print paper. In this case, it is necessary to Figure 9 crop this page 601 in the manner shown (operation S230), and then Figure 10 re-typeset the cropped picture object in the manner shown and then print it (operation S240 and operation S250).
[0081] Figure 7 Schematically shows a schematic diagram of a page that cannot be fully displayed vertically.
[0082] As Figure 7 shown, on the current page 701 in the browser window (or the visual interface of the print preview), the user needs to scroll the mouse up and down to view the entire page content. For printing such a page, if it can be fully displayed after scaling at the minimum scaling ratio in the height direction, or if the height dimension of this page 701 is less than or equal to the maximum height value allowed to be printed on one page of the print paper, then it can also be directly printed through the above operation S260 without performing operations such as web page cropping. If the height has exceeded the above maximum height value, even after scaling this page 701 at the minimum scaling ratio, it still cannot be fully displayed in the browser window (or on one page of the print paper). Then it is necessary to Figure 9 crop this page 701 in the manner shown (operation S230), and then Figure 10 re-typeset the cropped picture object in the manner shown and then print it (operation S240 and operation S250).
[0083] Figure 8 Schematically shows a schematic diagram of a page that cannot be fully displayed both horizontally and vertically.
[0084] As shown in FIG. 8, on the current page 801 in the browser window (or the visual interface of the print preview), the user needs to scroll the mouse up, down, left, and right to view the entire page content. For printing such a page, if the page 801 can be completely displayed after being scaled as a whole at the minimum zoom ratio, it can be directly printed through the above operation S260 without performing operations such as web page cropping. If the width or height of the page 801 exceeds the maximum width value or the maximum height value allowed to be printed on one page, then after being scaled at the specified minimum zoom ratio, the page still cannot be completely displayed within the browser window or the printing paper, and it is necessary to Figure 9 crop the page 801 in the manner shown (operation S230), and then Figure 10 re - typeset the cropped picture object in the manner shown and then print it (operation S240 and operation S250).
[0085] Figure 9 Schematically shows a schematic diagram of cropping a target page according to an embodiment of the present disclosure.
[0086] As Figure 9 shown, crop and capture the target page according to the print paper type (for example, A4 paper) and the preset print zoom ratio (for example, the print zoom ratio selected by the user, or the default print zoom ratio 1). The number N of the obtained picture objects is calculated based on the width and height of the target page, the width and height of the print paper, and the above - mentioned preset print zoom ratio.
[0087] Figure 10 Schematically shows a schematic diagram of re - typesetting the cropped picture objects according to an embodiment of the present disclosure.
[0088] As Figure 10 shown, re - typeset the Figure 9 picture objects cropped in Figure 9 above. When re - typesetting, it can be typeset according to the cropping order or the coordinate order. For example, the picture objects in the same row in Figure 9 can be arranged in the order from left to right, and then after the picture object at the end of a certain row, start arranging from the picture object at the leftmost end of another row. Cycle in turn until all the images are arranged completely to form the Figure 10 picture object sequence in Figure 10 . After the image object sequence typeset in this way is printed, it is convenient for the user to connect the content of adjacent two pages and convenient for the user to read.
[0089] Figure 9 And Figure 10 the processes of web page cropping and image re - typesetting in Figure 10 can be set to be invisible to the user, belonging to a hidden operation, and does not affect the user's printing experience.
[0090] Next, in combination withFigure 9 and Figure 10 , taking the example of using canvas to crop the target page, the specific implementation process of using canvas to crop will be described in detail.
[0091] According to an embodiment of the present disclosure, in operation S230, the API related to canvas can be used to implement the cropping of the target page, and the URL of the cropped image object can be obtained (operation S301 - operation S302). The method for cropping the target page can be as shown in the example of Table 1:
[0092] Table 1
[0093]
[0094] By calling the method in Table 1, drawing can be performed in the canvas object ctx. First, taking (sx, sy) in the target page as the starting point, a page screenshot with a width and height of (sWidth, sHeight) is cropped in the target page. Then, this screenshot is drawn as an image with a width and height of (dWidth, dHeight) in the canvas at the coordinate values of (dx, dy). Next, this canvas object can be stored in the browser, and the URL of the stored canvas object is returned. Among them, the size (dWidth, dHeight) of the drawn image is determined according to the width and height of the screenshot (sWidth, sHeight) and the preset printing scaling ratio, and the preset printing scaling ratio is greater than or equal to the specified minimum scaling ratio. The preset printing scaling ratio can be, for example, the scaling ratio selected by the user when performing printing settings, or the default printing scaling ratio. The default printing scaling ratio can be, for example, the scaling ratio of the previous print, or 1.
[0095] According to the embodiment of the present disclosure, in the process of calling the method in Table 1 for screenshot cropping to implement cropping N image objects from the target object, it generally includes the following three steps:
[0096] In the first step, based on the size of the target page, the size of the printing paper, and the preset printing scaling ratio, the number N of the cropped image objects can be determined.
[0097] Specifically, the horizontal size of the target page can be multiplied by the printing scaling ratio, and then the horizontal size of the printing paper is rounded up to obtain the horizontal cropping quantity m; the vertical size of the target page is multiplied by the printing scaling ratio, and then the vertical size of the printing paper is rounded up to obtain the vertical cropping quantity n; and based on the product of the horizontal cropping quantity m and the vertical cropping quantity n, the value of N is obtained.
[0098] Specifically, for example, first obtain the width and height dimensions of the target page as follows:
[0099] {
[0100] Height: H,
[0101] Width:W
[0102] }
[0103] Then, based on the width and height dimensions of the printing paper and the preset printing scaling ratio, calculate the number of cropped picture objects (where an irregular page can be treated as a rectangle). For example, for the convenience of subsequent printing, the width and height of the canvas can be set to be the same as those of the printing paper, that is, the width and height of the printing paper are (dWidth, dHeight) in Table 1. Let the preset printing scaling ratio be r, where r = dWidth / sWidth. Then the number of cropped images can be calculated in the following way:
[0104] Horizontal quantity:
[0105] Vertical quantity:
[0106] Among them, represents rounding up.
[0107] Then the number N of the cropped picture objects is: N = m * n;
[0108] For the convenience of processing and algorithm calculation, it can be regarded as a two-dimensional array type as a whole: [m, n].
[0109] The second step is to calculate the starting coordinates (sx, sy) for each interception from the target page based on the size (sWidth, sHeight) of each screenshot and the number N of the cropped picture objects.
[0110] After obtaining the two-dimensional array [m, n], combined with the size (W, H) of the target page and the size (sWidth, sHeight) of each cropped image, the starting coordinates of each picture object to be cropped can be determined one by one.
[0111] The third step is to traverse N times. Each time, call the method shown in Table 1, start from the target page with the screenshot starting coordinates (sx, sy) at the current traversal, intercept the screen according to the size (sWidth, sHeight) of each screenshot, and draw it to the canvas according to the scaled size (dWidth, dHeight) of the printing scaling ratio, and then return the URL of the picture object drawn to the canvas as follows:
[0112] [{
[0113] name: ‘img1’,
[0114] url: “http: / / localhost / image / img1.png”
[0115] },
[0116] {
[0117] name: ‘img2’,
[0118] url: “http: / / localhost / image / img2.png”
[0119] }, .......
[0121] {
[0122] name: ‘img mn’,
[0123] url: “http: / / localhost / image / imgmn.png”
[0124] }]
[0125] Among them, the image objects drawn on the canvas can exist on the browser side, and this URL is the address information for storing each image object in the browser.
[0126] After obtaining the URLs of each image object, these URLs can be used to re-layout and render the image objects in operation S240. For example, in operations S401 to S402, the tags are used to re-layout these image objects in the DIV container, and then these image objects are rendered by the browser to obtain the sequence of images to be printed. Then, in operation S250, the sequence of images to be printed is printed, and thus paged printing of the target page can be achieved.
[0127] It can be seen that the web page printing method of the present disclosure embodiment can be integrated into the browser, and the corresponding printing method steps are executed by leveraging the functions of the browser. It is convenient to reference, does not require installing other printing controls, etc., and can be directly introduced into the front-end engineering file. What can be used is the native Javascript language implementation. Moreover, the method of the present disclosure embodiment is simple and convenient to use. When developing and implementing, only the page ID of the target page dom node needs to be passed into this printing method in the project, without redundant code.
[0128] Based on the web page printing methods of the above embodiments, the embodiments of the present disclosure also provide a web page printing device. The following will be combined with Figure 11 to describe this device in detail.
[0129] Figure 11 A schematic structural diagram of a web page printing device 1100 according to an embodiment of the present disclosure is shown.
[0130] As Figure 11 shown, the web page printing device 1100 includes an acquisition module 1110, a clipping module 1120, a re-layout module 1130, and a pagination printing module 1140. According to some other embodiments of the present disclosure, the web page printing device 1100 may further include a judgment module 1150. The web page printing device 1100 can be used to execute the web page printing method described with reference to Figures 2 - 10 the reference.
[0131] The acquisition module 1110 is used to acquire the size of the target page and the size of the printing paper. In one embodiment, the acquisition module 1110 may, for example, execute the operation S210 described above.
[0132] The clipping module 1120 is used to clip the target page to obtain N picture objects when the target page scaled according to the specified minimum scaling ratio cannot be printed on one page of printing paper, where each picture object is suitable for printing on one page of printing paper, and the N picture objects can be spliced to form the picture of the target page, where N is an integer greater than 1. In one embodiment, the clipping module 1120 may execute the operation S230 described above.
[0133] According to an embodiment of the present disclosure, the clipping module 1120 may specifically be used to: use canvas to clip the target page to obtain N picture objects; and obtain the uniform resource locator URL of the N picture objects.
[0134] The judgment module 1150 is used to, before the clipping module 1120 performs clipping, based on the ratio of the size of the target page to the size of the printing paper, obtain the global scaling ratio when the target page can be printed on one page of printing paper, and if the global scaling ratio is less than the minimum scaling ratio, determine that the target page scaled according to the minimum scaling ratio cannot be printed on one page of printing paper. In one embodiment, the judgment module 1150 may execute the operation S220 described above.
[0135] The re-layout module 1130 is used to re-layout and render the N picture objects to form a sequence of images to be printed. In one embodiment, the re-layout module 1130 may execute the operation S240 described above.
[0136] The paging and printing module 1140 is used to print the sequence of images to be printed. In one embodiment, the paging and printing module 1140 may perform the operation S250 described above.
[0137] According to an embodiment of the present disclosure, any multiple modules among the acquisition module 1110, the clipping module 1120, the reformatting module 1130, the paging and printing module 1140, and the judgment module 1150 may be combined and implemented in one module, or any one of them may be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules may be combined with at least part of the functions of other modules and implemented in one module. According to an embodiment of the present disclosure, at least one of the acquisition module 1110, the clipping module 1120, the reformatting module 1130, the paging and printing module 1140, and the judgment module 1150 may be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on chip, a system on substrate, a system on package, an application specific integrated circuit (ASIC), or any other reasonable manner of integrating or packaging circuits, etc., implemented by hardware or firmware, or implemented in any one of the three implementation manners of software, hardware, and firmware, or in an appropriate combination of any several of them. Alternatively, at least one of the acquisition module 1110, the clipping module 1120, the reformatting module 1130, the paging and printing module 1140, and the judgment module 1150 may be at least partially implemented as a computer program module, which can perform corresponding functions when the computer program module is run.
[0138] Figure 12 A block diagram of an electronic device suitable for implementing the web page printing method according to an embodiment of the present disclosure is schematically shown.
[0139] As Figure 12 shown, the electronic device 1200 according to an embodiment of the present disclosure includes a processor 1201, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1202 or the program loaded from the storage section 1208 into the random access memory (RAM) 1203. The processor 1201 may include, for example, a general microprocessor (such as a CPU), an instruction set processor, and / or a related chipset, and / or a dedicated microprocessor (such as an application specific integrated circuit (ASIC)), etc. The processor 1201 may also include on-board memory for caching purposes. The processor 1201 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present disclosure.
[0140] In the RAM 1203, various programs and data required for the operation of the electronic device 1200 are stored. The processor 1201, the ROM 1202, and the RAM 1203 are connected to each other via a bus 1204. The processor 1201 performs various operations of the method flow according to the embodiments of the present disclosure by executing the programs in the ROM 1202 and / or the RAM 1203. It should be noted that the programs may also be stored in one or more memories other than the ROM 1202 and the RAM 1203. The processor 1201 may also perform various operations of the method flow according to the embodiments of the present disclosure by executing the programs stored in the one or more memories.
[0141] According to an embodiment of the present disclosure, the electronic device 1200 may further include an input / output (I / O) interface 1205, and the input / output (I / O) interface 1205 is also connected to the bus 1204. The electronic device 1200 may further include one or more of the following components connected to the I / O interface 1205: an input portion 1206 including a keyboard, a mouse, etc.; an output portion 1207 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage portion 1208 including a hard disk, etc.; and a communication portion 1209 including a network interface card such as a LAN card, a modem, etc. The communication portion 1209 performs communication processing via a network such as the Internet. A drive 1210 is also connected to the I / O interface 1205 as needed. A removable medium 1211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is mounted on the drive 1210 as needed so that a computer program read therefrom is installed into the storage portion 1208 as needed.
[0142] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist separately without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the one or more programs are executed, the method according to the embodiments of the present disclosure is implemented.
[0143] According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example, but is not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In the present disclosure, the computer-readable storage medium may be any tangible medium that contains or stores a program, and this program may be used by or in combination with an instruction execution system, apparatus, or device. For example, according to an embodiment of the present disclosure, the computer-readable storage medium may include one or more memories other than the ROM 1202 and / or RAM 1203 and / or ROM 1202 and RAM 1203 described above.
[0144] An embodiment of the present disclosure further includes a computer program product, which includes a computer program that contains program code for executing the method shown in the flowchart. When the computer program product runs in a computer system, the program code is used to enable the computer system to implement the method provided by the embodiment of the present disclosure.
[0145] When the computer program is executed by the processor 1201, it executes the above functions defined in the system / apparatus of the embodiment of the present disclosure. According to an embodiment of the present disclosure, the above-described system, apparatus, module, unit, etc. may be implemented by computer program modules.
[0146] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices and magnetic storage devices. In another embodiment, the computer program may also be transmitted and distributed in the form of a signal on a network medium, and downloaded and installed through the communication part 1209, and / or installed from the removable medium 1211. The program code included in the computer program may be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0147] In such an embodiment, the computer program may be downloaded and installed from the network through the communication part 1209, and / or installed from the removable medium 1211. When the computer program is executed by the processor 1201, it executes the above functions defined in the system of the embodiment of the present disclosure. According to an embodiment of the present disclosure, the above-described system, device, apparatus, module, unit, etc. may be implemented by computer program modules.
[0148] According to embodiments of the present disclosure, program code for executing the computer programs provided by the embodiments of the present disclosure can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. The programming languages include, but are not limited to, programming languages such as Java, C++, Python, the "C" language, or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device can be connected to the user's computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., by connecting through the Internet using an Internet service provider).
[0149] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks can occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and combinations of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0150] Those skilled in the art can understand that the features recited in the various embodiments and / or claims of the present disclosure can be combined or / and combined in various ways, even if such combinations or combinations are not explicitly recited in the present disclosure. In particular, without departing from the spirit and teachings of the present disclosure, the features recited in the various embodiments and / or claims of the present disclosure can be combined and / or combined in various ways. All such combinations and / or combinations fall within the scope of the present disclosure.
[0151] The embodiments of the present disclosure have been described above. However, these embodiments are merely for illustrative purposes and are not intended to limit the scope of the present disclosure. Although the embodiments have been described separately above, this does not mean that the measures in each embodiment cannot be used advantageously in combination. The scope of the present disclosure is defined by the appended claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art can make various substitutions and modifications, and all such substitutions and modifications should fall within the scope of the present disclosure.
Claims
1. A web page printing method, comprising: Obtaining the size of the target page and the size of the printing paper; When the target page after being scaled according to the specified minimum scaling ratio cannot be printed on one sheet of the printing paper, cropping the target page to obtain N picture objects, where each picture object is suitable for being printed on one sheet of the printing paper, and the N picture objects can splice out the picture of the target page, where N is an integer greater than 1; the N is determined based on the size of the target page, the size of the printing paper, and a preset printing scaling ratio; Rearranging and rendering the N picture objects to form a sequence of images to be printed; and Printing the sequence of images to be printed.
2. The method according to claim 1, wherein The cropping the target page to obtain N picture objects includes: Using canvas to crop the target page to obtain the N picture objects; and Obtaining the uniform resource locator URL of the N picture objects.
3. The method according to claim 2, wherein, The rearranging and rendering the N picture objects to form a sequence of images to be printed includes: Arranging N image tags determined based on the URLs of the N picture objects in a DIV container; and Rendering the N image tags in the DIV container to obtain the sequence of images to be printed.
4. The method according to claim 2, wherein, The using canvas to crop the target page includes: Based on the size of the target page, the size of the printing paper, and a preset printing scaling ratio, determining the number N of cropped image objects; Based on the size of each screenshot and the number N of cropped image objects, calculating the starting coordinates for each interception from the target page; and Traversing N times, each time intercepting the picture from the target page starting from the starting coordinates, scaling according to the size of each screenshot, and then drawing it onto the canvas.
5. The method according to claim 4, the determining the number N of cropped image objects based on the size of the target page, the size of the printing paper, and a preset printing scaling ratio includes: Multiplying the horizontal size of the target page by the printing scaling ratio, and then rounding up the horizontal size of the printing paper to obtain the horizontal cropping quantity m; Multiplying the vertical size of the target page by the printing scaling ratio, and then rounding up the vertical size of the printing paper to obtain the vertical cropping quantity n; And Based on the product of the horizontal cropping quantity m and the vertical cropping quantity n, obtaining the value of N.
6. The method according to claim 1, wherein, The method further includes: Based on the ratio of the size of the target page to the size of the printing paper, obtaining the global scaling ratio when the target page can be printed on one sheet of the printing paper; and If the global scaling ratio is less than the minimum scaling ratio, determining that the target page after being scaled according to the minimum scaling ratio cannot be printed on one sheet of the printing paper.
7. The method according to claim 1, wherein The printing the sequence of images to be printed includes: Invoking window.print() to print the sequence of images to be printed.
8. A web page printing apparatus, comprising: An obtaining module, configured to obtain the size of the target page and the size of the printing paper; A cropping module, configured to crop the target page to obtain N picture objects when the target page after being scaled at a specified minimum scaling ratio cannot be printed on one sheet of the printing paper, where each picture object is suitable for being printed on one sheet of the printing paper, and the N picture objects can be spliced to form the picture of the target page, where N is an integer greater than 1; the N is determined based on the size of the target page, the size of the printing paper, and a preset printing scaling ratio; A re-layout module, configured to re-layout and render the N picture objects to form a sequence of images to be printed; and A pagination printing module, configured to print the sequence of images to be printed.
9. An electronic device, comprising: One or more processors; A storage device, configured to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors are caused to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, having stored thereon executable instructions, which when executed by a processor cause the processor to execute the method according to any one of claims 1 to 7.
11. A computer program product, comprising a computer program, which when executed by a processor implements the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method and device for converting PDF document, terminal and medium
CN111859865A