printing swt browser contents with Header and Footer - java

I am implementing SWT Browser in RCP application for displaying HTML pages.
For Printing we use JavaScript function - htmlBrowser.execute("javascript:print()");
This works fine but my problem is that I want a my own Header with Logo and Footer (some text)
on print pages. please help me with suitable example

The only possible solution I can think of.
Open a new Browser
Get the text (browser.getText()) from the parent Browser
Wrap it in your header and footer html
Set the text (browser.setText()) on newly opened Browser
Hide it - shell.setVisible(false) (Only if you don't want to show the popup)
And invoke browser.execute("javascript:print()");
I suspect printing the content after hiding the Shell. But, you can give it a try!!

Related

how to avoid blank page at the end of pdf report in BIRT?

I am using current BIRT version that is 4.5. I have two master pages in my report. I have huge data to display on a report so i have set some data to display on one master page and the remaining on another master page due to some reason. The problem is when there is no data to display on one of the master page it is rendering a blank page with header and footer of that master page which i want to avoid. In my pdf report how can i avoid this blank page?
Hi, all are pointing to hide tables or other components but my requirement here is, i need to hide the page itself. I dont think there is visibility option for page. even if it is there it is not so useful. Kindly understand that i dont want to display the page itself not only the components in it.so can i expect any help now?
I guess you added the tables directly on the masterpage?
That's not how it works. BIRT will render the (master)page and maybe hide the elements on them (for example a table that has no data. You can do this by setting the visibility property). The problem with this approach is that the Masterpage cannot be 'unrenderred'.
The proper way to fix this, is to add each element on the normal layout. In the properties for each table, grid, etc. you can set the pagebreak properties. Here you can select the Masterpage you want to use. If an element does not need to be rendered (by visibility settings), it wont trigger a 'blank' masterpage.
Hope that helps.

jquery: load/include html code into html file without delay?

I'm working on a mobile-app that uses cordova, so it's basically a html-website runing in an app. And I have a lot of elements and html-code that has to be present on all pages, e.g. navigation but also popups and so on and so on.
While working on larger webprojects I usually wrap these kind of code-segments in php-files and use "php include" to create my html file. Here however I can't work with php since there is no server. So since I would like to avoid having countless copies of the same code in every html-file, I'm looking for a way to include html code into an html file using jquery maybe?
I did try it with:
$("#includeContent1").load( "mod_navigation.html" );
and
$.get('mod_navigation.html', function(data) { $('body').append(data);});
Both worked, not as great as php, but did the trick. Problem is, the additional content (in this case the navigation) is being loaded "after" the parent html file is shown, making the navigation just pop up with a slight delay. This looks just horrible, because the navigation at the bottom of the screen just keeps flickering while using the app.
Is there a way to avoid these delays? Maybe by jumping to the new page AFTER everything in the html file has been loaded ... or any other way?
could you just try to create the whole DOM in a variable, and when all the HTML code is saved in the variable append it to the body? Say
$("body").empty(); // clear all
var content = "";
/* start to create content here */
$("body").append(content);
Althoug I have no idea how fast this is...
Cheers
You cannot use JavaScript that's on your page to preprocess that page's HTML as it is part of the document and therefore by definition executed after the document has been loaded.
You could however use a callback function to only display the new page after it has fully been loaded.

Anchor not working in IE7 via redirect (spring-mvc, jsp)

So for this project I am doing I have a page which generates content via clickable buttons. The button posts the form to my controller and the controller acts on the button that has been clicked. To show what was changed a redirect will occur (form in the session) with an anchor included. A little piece of javascript will then go to anchor which is in the link (eg. website/add/picture#123). This works fine in pretty much every browser except Internet Explorer 7.. I found out this has to do with an input field of file type.. Because if I remove the input field, then even IE7 will nicely scroll to the anchor..
Does anyone have any idea why this behaviour occurs?
If it's unclear please tell me and I'll provide more details..
Thanks a lot,
Davey
So.. I didn't manage to solve the input type=file bug.. I suppose it's just an IE7 bug. I made a work around to put the input field on a popup. A lot of overhead but it is working pretty well now

PDF-Form Text hidden unless clicked

In my application I have to fill a predefined PDF form with data from DB. We are using Java and Pdfbox. The filling itself is not a problem.
The problem is that in resulting PDF-file all texts in the form are invisible (or hidden, also grey rectangles) unless field clicked.
How can I solve this problem?
I had the same problem when I tried to programmatically fill PDF forms using pdfbox. I add this answer to a rather old question as all the other answers manipulate the original PDF, which is not always an option.
The problem with invisible form fields just appeared in Acrobat PDF, other PDF renderers showed it fine. If using pdfbox 1.8.x you have to set Need Appearances as explained here:
PDAcroForm form = docCatalog.getAcroForm();
form.getDictionary().setItem(COSName.getPDFName("NeedAppearances"), COSBoolean.TRUE);
If using pdfbox 2 this is simplified to:
PDAcroForm form = docCatalog.getAcroForm();
form.setNeedAppearances(true);
I read this on a forum and worked for me:
Using Adobe Acrobat Pro, I exported the form using "Export Data" to a XML and then imported it back from XML-file with "Import Data". Those commands are under Forms/Manage Forms Data
This is the link to the post: http://forums.adobe.com/thread/637421
I had this exact problem with a form I was filling with PDFBox in Java.
I fixed it by opening the original (blank) PDF form in Acrobat Pro and changing some options for each of the problem text fields. The options might vary for you, but here's what worked for me:
In the Acrobat Pro menu bar go to Forms > Add or edit fields.
Right click the text field in Acrobat Pro and select properties, then:
In the 'Options' tab:
Untick all options except 'scroll long text'
Add a few space characters in to the Default Value box
In the 'Appearance' tab:
Set the font size to 'auto'
Click 'close form editing' and save the file.
I just ran across this and tried a combination of things before one very simple thing worked. I have Adobe Acrobat 9.0 and I couldn't find some of the options written here.
What I ended up doing was a two-pronged process: I went to Forms > Manage Form Data > Export Data; I then saved that file on my desktop. Next, I went back to Forms > Manage Form Data but instead selected Import Data, and selected that file I'd just saved. Bingo! Everything filled in properly.
I don't quite know how you can stop it happening in the future but a resolution to getting the file working, similar to g-eorge is to open it in adobe acrobat pro, in tools on the right hand menu select "Interactive objects" and choose select object.
When you highlight the first field you want to fix, you should then be able to control-a to select all interactive objects. Once all are selected, right click on one field and select properties.
In the "general" tab the bottom option should have "common properties" which has the option "form field" change this to hidden and then back to visible. This will then restore all visibility to the form.
This has worked for me on all the rare instances when I receive this, and hasn't failed me once. Hope it does the same for you,
BoB
in the appearance tab of each erroneously hidden object you will see the "fill color" set to none. set it to none again (just click on it) and save the PDF and these fields will show up normally. I can't believe adobe has let this error persist for so long. It happens constantly when viewing/saving with multiple pdf readers.
Nothing I tried here worked - except to change software.
I was using PDFElement 6 Pro (trial) and couldn't make it work. Tried all sorts of things with PDFBox plus all suggestions above.
Ended up trying https://www.pdfescape.com/ and it all worked just fine.
In my case I solved it by changing the font to Arial (or one of the standard in windows set), in the 'Appearance' tab, in properties.
Before, it was set Helvetica which was not embedded in the file and that I think generated the problem.

Print Multi page JEditorPane html contents in Java

I have developed a code in Java where I have embedded HTML content into a JEditorPane by setting its content type to text / html.
However this content spills over to the second page and so on. I know that the JEditorPane has a print() method that prints the contents of the JEditorPane and I know that the print() method of the JEditorPane prints all the contents of the JEditorPane and even prints multiple pages.
What I want is that the top, left, right and bottom margins should be set to 0.
If I would simply leave the work of setting the margins to 0 at run-time by changing the print settings before printing, it would just not work.
Due to this I had to implement the Printable interface. But when I used the Printable interface it allows to print only the first page of the JEditorPane.
When I searched a lot for this solution I got this link on Google;
http://download.oracle.com/javase/tutorial/displayCode.html?code=http://download.oracle.com/javase/tutorial/2d/printing/examples/PaginationExample.java
But the problem here is that I am using html contents in the JEditorPane. I dont know how to integrate the above solution provided in the link with a JEditorPane that consists of HTML Code
If you need real WYSIWYG use articles about paginated printing from here
http://java-sl.com/articles.html
If you need just print JEditorPane's content paginated use this
http://java-sl.com/JEditorPanePrinter.html

Categories