Page breaks in JEditorPane - html

For the love of everything holy, can someone please help me do this?
I have literally been searching for two hours on how to put a page break in a JEditorPane for when it prints to no avail. I've tried everything from HTML styles to even trying sketchy APIs I've found on random websites.
The code I wrote uses a textPaneEditor to print the data, and I use the HTML styling to format it in the way that I need it to look. So, I need a way to add a page break after I push in all of the data for the next line possibly with the HTML styling. Unfortunately, " " doesn't seem to work.
Here's what my code essentially looks like:
String report = "<font size=\"3\">";
report += "<b> TEST! </b><br>";
report += "PAGE BREAK WOULD GO HERE<br>";
report += "</font>";
JEditorPane textArea = new JEditorPane("text/html", report);
try{
textArea.print(new MessageFormat(""), new MessageFormat(""), true, null, null, true);
}catch(PrinterException e){
e.printStackTrace();
}
TLDR; how do I page break a JTextEditorPane with HTML styling during printing to a printer?

I'm working on solving the same problem myself right now. One thought I've had is to issue two print commands, one for each page to print. Not sure if this is or will be the most elegant or efficient solution but it's something to look into.

Related

How to see if Chrome manipulates HTML by itself?

If you forget to close a HTML-Tag, Chrome will validate your code and try to fix problems like this.
I had a major problem because I forgot a closing Form-Tag, and instead of closing it correctly, Chrome deleted a following form, not the inputs, simply the Form-Tags.
When I looked at the Source Code itself, the Form-Tag was there, but not in the Elements-Tab in the console.
So at first, I thought it must have something to do with some JS deleting this DOM-Node and set a DOM-Breakpoint to find the script.
To cut a long story short, it took me hours to find out, that no JS deleted my form, but Chrome itself thought: There is a missing so I delete some other to fix that...
Is there any possibilty to see if Chrome automatically changes your DOM?
Thank You!
The browser Engine does indeed. They use string replace methods, although it happens internally.
<div>
</div>> // mistake
<div> //missing end tag
<div></div>
---------------------------------------------------
Methods
file=file.stringreplace('>>', '>')
an uneven count will add the missing div just after the next beginning div and conditionally if the missing is not found by the end of the file:
file=file.stringreplace('
<div>', '</div>
<div>')
The Parsing Engine after the missing and broken tags are repaired then parses the file and can then with a positive count set the screens GUI widgets by opening and closing tags as GUI Frames. It does this by adding tokens delimiters to the actual div tags making them easily distinguished from each other.
<div1s>
</div1e>
<div1s>//section columns
<div2s></div2e>
<div2s></div2e>
<div2s></div2e>
</div1e>
<div1s>Footer</div1e>
-----------------------------------------------------
The GUI Frame Tokens
for each "<dive1>"{
FrameCreate(CSS--ATTRIBUTES FROM ASSOCIATIVE ARRAYS--)
//the GUI Frame Widgets VERTICAL SECTIONS
}
//Next it finds the nested divs2 and embeds these into the thir parents above but with embedded Text Widgets also.
FrameTextBoxCreate(--CSS MATED ATTRIBUTES RULES--)
div3 etc------and so on.
In fact it is in the WebView GUI Widget Sets in its customized Mosaic Canvas Widget Sets in Chrome would be where they are repaired.

Printing Government paper form from website

We have to recreate a Government form from our website. The form is full of vertical and horizontal lines and different width and height cells. Some cells contain pre-printed text and have two or three lines of data.
We have created the Web page to capture and validate the dynamic data and now need a method of rendering the form (A4) to the printer. The client does not want a classic PDF print preview so our normal reporting tool will not work. Can anyone guide me on how to create a print output using css, html with vertical and horizontal lines and positioned data.
Sorry if I affended this board, I was actually trying to get some guidance from the experts
Our current code is below. We use Jaspersoft Ireports to design the form layout and the PHPJasperXML library to render a PDF and write a copy on the server.
I have to rewrite this using CSS & HTML and render in an Iframe with an immediate (kiosk) print. I'm just looking for the right approach before I go down the wrong route.
include "config.php";
$version="0.9d";$pgport=5432;
$pchartfolder="./class/pchart2";
$ecsd_id = $_REQUEST['ecsd_id'];
include_once('class/tcpdf/tcpdf.php');
include_once("class/PHPJasperXML.inc.php");
ob_clean();
$PHPJasperXML = new PHPJasperXML();
//$PHPJasperXML->debugsql=true;
$PHPJasperXML->arrayParameter=array('ecsd_id'=>$ecsd_id);
$PHPJasperXML->load_xml_file("ecsd_pdp.jrxml");
//$PHPJasperXML->transferDBtoArray($server,$user,$pass,$db);
$PHPJasperXML->transferDBtoArray($dbhost,$dbuser,$dbpass,$dbname);
//$PHPJasperXML->load_xml_file("ecsd_pdp_copy.jrxml");
$PHPJasperXML->outpage("I");
$PHPJasperXML->outpage("F", "ecsd_prints/" . $ecsd_id . ".pdf");
//page output method I:standard output F =save as filename and submit and parameter as destinate file name D:Download file

Want `­` to be always visible

I'm working on a web app and users sometimes paste in things they've copy/pasted from other places and that input may come with the ­ character (0xAD). I don't want to filter it out, I simply need the user to see that there is an invisible character there, so they have no surprises later.
Does anyone know a way to make the ­ always be visible? To show a hyphen, rather than remain hidden? I suspect a custom web font might be needed, if so, does anyone know of a pre-existing one?
You would need to either use JavaScript or a custom typeface that has a visible glyph for the soft-hyphen character. Given the impracticalities of working with typefaces for the web (and burdening the user with an additional hundred-kilobyte download) I think the JavaScript approach is best, like so:
document.addEventListener("DOMContentLoaded", function(domReadyEvent) {
var textBoxes = document.querySelectorAll("input[type=text]");
for(var i=0;i<textBoxes.length;i++) {
textBoxes[i].addEventListener("paste", function(pasteEvent) {
var textBox = pasteEvent.target;
textBox.value = textBox.value.replace( "\xAD", "-" );
} );
}
} );

Dynamically re-bind html.ValidationMessageFor html helper?

Some background information, I am using ASP.NET with the MVC framework and html helpers.
I currently have a dynamic table where each row has a series of input boxes. Each of these input boxes has a validation message. This works completely fine for the first row. However, when other rows are dynamically added (with the IDs' being changed along with other attributes to match the row number) the validation message no longer works.
Both the row and validation message span are being replicated properly.
In JQuery, this is usually just a problem with the binding, so for each row I would simply re-bind the IDs'. However I am not really to sure how to approach them in ASP.NET.
Any assistance would be appreciated.
Thanks
Alright, I have finally figured this out.
In MVC, in order to handle the validation, it import a JQuery file known as jquery.validate.unobtrusive.js.
However, similar to JQuery, this only occurs at the very beginning when the page is loaded. So, when you add a new dynamic element, you need to remove the bindings and the re-bind them again.
Basically, in your function for adding a new element, put the following lines of code AFTER you have added the new element:
$("#form").removeData("validator");
$("#form").removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse("#form");
For example:
function addInfoDynamic()
{
document.getElementById("#myDiv").innerHTML += "New Content";
$("#form").removeData("validator");
$("#form").removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse("#form");
}

Adding html to a ui web view at runtime in code, based on a switch

Is it possible for me to add text to a uiwebview and change the text and colours in this view without having separate html files? So I define whats in the html file in a switch statement? I do this at the moment using labels, but I can't have more than one colour in a label so I need to use html, as core text looks quite complicated.
switch (counter)
{
case 0:
titleLabel.text = #"needs to be more than one colour";
break;
case 1:
titleLabel.text = #"needs to be more than one colour";
break;
and so on...
Can I in some way define whats in a html file in tags in the code in these switches rather than having seperate html files? If so how would I do this?
Cheers,
Lewis
Assuming your HTML contains a CSS class called myCssClass where you specify your colors, and a label:
<label id="myTextElement">A Label</label>
You can programmatically execute javascript to set a different CSS class using code like this:
UIWebView *webView;
.
.
.
[webView stringByEvaluatingJavaScriptFromString:#"document.getElementById(\"myTextElement\").className = \"myCssClass\";"];
though honestly if you watch the WWDC 2012 videos on CoreText you might be less intimidated...