I'm creating Web App using Java,And one of the tasks is to print a report to the customer.The problem is that the paper design is already made and putted in the actual printer and I must only fill the blank fields.The questions are :
1) how can I print the values exactly in the fields ?
2) Is there a way to simulate this process without having physical printer, like using virtual printer and upload the default page to it ?
I attached part of the paper that will be in the printer and I should fill the blank fields with data comes from JSF page.
I solved the problem like yours in the past. My company has a pre-designed printed invoice. My task is to put the data into the blanks in place. In my experience, you should:
Scan the paper into an image with the same size as the physical version.
Measure the distance from a blank to another.
Specify the location of the blanks to output the data based on your measurement.
You can use the digitalized version as the background of the output page and test on it.
Try to put the first blank in place.
Test and adjust your code.
Hope it helps.
If the things that are there in the page only in the soft copy you can do one thing. Design a A4 exactly the same way you have on the printed page. Then write down variables in the places where you would like to fill up from your java program. That docx file will act as the template. After that, replace those texts with the actual values from the Java program in that template. All these can be done with docx4j api.
A code block like this will be useful :
if (textElement.getValue().contains(placeholder)) {
String temp = textElement.getValue();
temp = temp.replace(placeholder, name);
textElement.setValue(temp);
return;
}
This is how we do it our project. If you need more help, let me know.
Related
I don't know if "cutting" is the right term...
I've got to finish doing a large and complex report based on an Applet legacy system, a fellow and I decided trying reuse all the logic in the applet to avoid the complexity of doing a lot of sub-reports. What we did was copy all the logic in the applet that include a lot of condictionals/SQL and make a huge and properly formated String, so that in our Jasper file it would just have a method called "myVo.getBody()" besides the header and footer stuff.
Unfortunately we found out a problem that some part of text get lost between pages. I think that as the text get bigger and reach Jasper page limit for some reason it keeps being writed in a "no visible area" and when the next page content starts some part was lost.
For example, there is a list of 19 items and what happens is:
End of 2nd page
1 - item
2 - item
beggining of 3rd page
18th - item
19th - item
Items from 3 to 17 are not being showed.
Is there any Jasper configuration for this situation?
We tried:
Position type: Fix Relative to the Top and Float
Stretch Type: Relative to the Tallers Object and Relative to Band Height
Stretch With Overflot: true or false
I don't think showing Java code would be useful as it just use a StringBuffer to build the String, put it on body property in a PreparedDocumentVO so that Jasper model can consumes it. It seems to be some Jasper setting, or the idea of creating a huge String is not so good as we thought.
I would consider breaking the result up.
Jasper formats information based on a relative page size. This means that at some point in time, when dealing with information that is not likely to fit on a page, Jasper will probably make an assumption that doesn't hold (and your data will likely not be formatted into the page).
If you have an exceptionally long string, consider splitting it up. Besides, people scroll web pages down, not the side, so a heavy side-scrolling document is likely to cause user issues unless every record scrolls to the side just as heavily.
Sorry for the long winded question, I've spent a few days trying to figure this out and have so far found dozens of ways not to solve my problem.
I'm currently trying to use a Datamax O'Neill E Class Mark 3 printer to print some labels. The java application that generates the label data cannot be easily modified, and simply outputs plain text via a built in "print" function (output example below)
Unit name [LF]
Unit description [LF]
Quantity
When I print to a Ricoh printer it works (using CR+LF replacement in the Ricoh driver). However when I print to the label printer it does not. I've been advised that the label printer requires "control codes" and "encoded data" to be able to print.
I've been able to log the .prn files from the printer and when sending the exact same data from Notepad to he printer, the .prn file is much larger and appears to be "encoded" containing control codes.
This is entirely inside a windows environment using a networked printer (tried USB as well). I basically need something for my Java application to print to, that will add the necessary "encoding" to the data and then pass it along to the Datamax printer. Any ideas?
I'll try and post some samples tomorrow when I'm in the office as I'm currently typing this on mobile.
What I ended up doing was using the printers logging feature to log all jobs to C:\printlogs\ and have a batch file that loops every few seconds to run notepad /P on each file in the folder and then clean them all up.
I know it's a messy workaround, but it works.
When you print text from something like Notepad, that text gets sent to a print driver that converts it into the format the printer understands. You can't generally add control codes to the text in Notepad and have it work because it won't be seen as anything other than plain text to be printed.
The programmer's manual for that printer can be found here. That gives you everything you need to know to print labels on that printer. But in order to send those commands to the printer, you can't just paste them into Notepad. You have to write them directly to the printer, bypassing the print driver. For that you're going to need to use the WritePrinter function. The sequence of steps for printing goes like this:
To begin a print job, call StartDocPrinter.
To begin each page, call StartPagePrinter.
To write data to a page, call WritePrinter.
To end each page, call EndPagePrinter.
Repeat 2, 3, and 4 for as many pages as necessary.
To end the print job, call EndDocPrinter.
The MSDN entry for WritePrinter includes a link to example code (in C).
I am trying to recall a list of employees from an array in Java. I can either choose to do them individually via their ID number or bring all employee info up at once. I know how to code everything else but I cannot find a clear tutorial on how to recall the data and project it onto the text box I have programmed into my GUI. I have the array already created in a different class but I need to get the information from that one and display it in the GUI. Any help would be appreciated. Thanks.
If you want more info just let me know.
[The image is a screenshot of the simple GUI I made.]
There are many ways to do this, but one simple way that may help you to understand this process is as follows:
Implement a store method that simply writes all data to a file in a format of your choice. XML is common, as is TSV or CSV. Some of those are very easy to use, as predefined classes exist to handle them partially or completely.
You will have to read the data you want to store from whereever you have it in your application, possibly in the text boxes directly.
Accordingly implement a restore method that reads the file and fills it back into your data structure and/or the text boxes.
I'm creating a Web-based label printing system. For every label, there should be a unique s/n. So when a user decided to create 1000 labels (with the same data), all of it should have unique s/n, therefore the pdf will have 1000 pages, which increases the file size.
My problem is when the user decided to create more copies, the file size will get bigger.
Is there any way that I can reduce the file size of the pdf using Itext? Or is there any way that I can generated the pdf and output it in the browser without saving it neither to server/client's HDD?
Thanks for the help!
On approach is to compress the file. It should be highly compressible.
(I imagine that you should be able to generate the PDF on the server side without writing it to disc, though you could use a lot of memory / Java heap in the process. I don't think it is possible to deliver a PDF to the browser without the file going to the client PC's hard drive in some form.)
If everything except the s/n is the same for the thousands of labels, you only have to add the equal things one time as a template and put the s/n text on top of it.
Take a look at PDFTemplate in itext. If I recall correctly that creates and XObject for the recurring drawing/label/image.... and it is exactly the same object every time you use it.
Even with thousands of labels, the only thing that grows your document size is the s/n (and every page) but the graphics or text of the 'label' is only added once. That should reduce your file size.
I am working on a project here that ingests internal resumes from people at my company, strips out the skills and relevant content from them and stores it in a database. This was all done using docx4j and Grails. This required the resumes to first be submitted via a template that formatted everything just right so that the ingest tool knew what to look for to strip the data.
The 2nd portion of this, is what if we want to get out a "reduced" resume from the database. In other words, I want to search the uploaded content I now have, and only print out new resumes for people who have Java programming experience lets say. So I can go into my database, find the people who originally had java as a skill, and output a new set of resumes that are also still in a nice templated format, and only have the relevant info in them, instead of ALL the content.
I have been writing some software to do this in Java that will basically use a docx template, overwriting the items in customXML which are bound to the content controls in the doc, so the new data shows up and can eb saved as a new docx with that custom data.
This seems really cumbersome to me, and has some limitations. For one, lets say my template has a place for 3 Skills, and the particular person has 8 skills. There seems to be no good way to add those 5 additional skills to the docx other than painstakingly inserting the data with all of the formatting XML tags and such. This is a real pain, because if the template changes, I dont want to have to go back into my software and edit source code to change that additional data input XML tag to bold instead of italic.
I was doing some reading up on using Infopath to create a form that I could use to get the input, connecting to some sharepoint data source or something to store the stripped out data. However, I can't seem to find out if it is possible using sharepoint to get the data back out, in a nice formatted way. What would the general steps for this be? It seems like I couldnt find very much about this topic with any quick googling.
Thanks
You could set up the skills:
<skills>
<skill>..</skill>
<skill>..</skill>
and use a "repeat" content control pointing to the container. This would handle any number of <skill> entries.