JSP implementation (invoice printing)

Source: Internet
Author: User

JSP normal printing is very simple, there are many ways, you can use window. Print () This built-in method, you can also use the component webbrowser, you can also use a third-party component such as scriptx to achieve. The default A4 format is printed. How can I print the invoice?
First of all, we need to understand whether to implement web page nesting using our existing methods.
Secondly, we need to know that the paper used for the invoice is different. First, it uses a copy paper. to print the copy paper, we must use a dot matrix printer, in this way, the content can be written in two or three records. At the same time, the size of the invoice paper is not the A4 paper we usually use, then we must customize the paper according to the size of the invoice paper.
Because invoice printing is a blank area of an invoice to print what we want, we need to use CSS to control the printing distance. We can use table or Div to locate the printed content. There may be problems in the middle, because the printer has the default page margin. If the default page margin is too large, we may not be able to generate an invoice for how to tune the page, when necessary, adjust the margin. After positioning, we need to consider the issue of continuous invoice printing. The invoice is generally smaller than A4. Therefore, if the content of multiple invoices is placed on the page and is not controlled, only the first correct invoice can be printed. We use a CSS to control the pages to be printed:. Pagenext {page-break-after: Always ;}.

Generally, the content and format are used for invoice printing.JSPut it together and put it inIFRAMEAnd then print.


Function printactive (newstr ){
VaR headstr = '<HTML> VaR footstr = '</body> Newstr = headstr + newstr + footstr;
VaR IFR = Document. createelement_x_x ("iframe ");// New IFRAME
Document. Body. appendchild (IFR );// Add IFRAME
VaR ifrdoc = ifr.content?#doc ument;
// Name
IFR. Name = 'I _ framework ';
IFR. ID = 'I _ framework ';
Ifrdoc. designMode = "on ";// Enter editable document mode
Ifrdoc. open ();// Open stream
Ifrdoc. Write (newstr );// Write content
Ifrdoc. Close ();// Close stream
Ifrdoc. designMode = "off ";// The document enters the non-editable mode.
SetTimeout ("printiframe ()", "1 ");// Latency 1 Execution in milliseconds
}

The aboveJSYou can createIFRAME, And then write the content to be printed in the print, because this printing is generally usedAjaxTo retrieve data from the background, soJSAt last, the execution will be delayed by one millisecond to ensure that the printed content can be written in.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.