Cannot print off-screen HTML content from AIR application - actionscript

I am a newbie in Adobe AIR, and am trying to print a HTML from my air app, however, this HTML should never be seen on screen. I am using HTMLLoader for this, as per some sample I saw on the web.
What happens, is that there is a print dialog, but it prints out a blank page.
If this is a window application, and I click some button to print (just the HTMLLoader) it gets printed.
Following is my code.
var mySprite:Sprite = new mySprite()
var loader:HTMLLoader = new HTMLLoader()
loader.loadString("ADDRESSThu Aug 20 21:37:20 GMT+0530 2009")
var html:HTML = new HTML()
html.htmlLoader = loader
mySprite.addChild(html);
//After this its pretty standard
var pJob:PrintJob = new PrintJob();
html.width = pJob.pageWidth
html.height = pJob.pageHeight
loader.height = pJob.pageHeight
loader.width = pJob.pageWidth
if(!pJob.start())
{
throw new PrintingCanceled(" User Canceled Printing");
}
pJob.addPage(loader, null);
pJob.send();
Please let me know what I'm missing. Any help, or suggestions are welcome.

are you sure the page is being loaded ?
the frame doesn't have to be visible BUT it needs the content. meaning that you htmlLoader data must be loaded and "shown" in a canvas. Then you can put the canvas invisible if you don't want the users to see what will be printed.
you'll have to set the clipping on false. This however means that it will take some seconds before the printer dialog will get on the screen.
1. // Event Handler - called when the print button is clicked
2. private function onPrintClick ():Void
3. {
4. // Remove the clipping so all of the content is printed
5. clipForPrinting( true );
6.
7. // Start the delay to allow clipping to update before
8. // printing anything.
9. doLater( this, "doActualPrinting" );
10. }
11.
12. // Adjust the clipping to prepare for or recover from print.
13. private function clipForPrinting( printing:Boolean ):Void
14. {
15. // Assume printing is true if not passed in
16. if ( printing == undefined ) {
17. printing = true;
18. }
19.
20. // Modify the root clipContent so the application's width/height
21. // doesn't interfere with bounds of the print content
22. Application.application.clipContent = !printing;
23.
24. // Modify the container holding the content to be printed to remove
25. // the scroll masking
26. printArea.clipContent = !printing;
27.
28. }
29.
30. // Handles the actual printing of the content in the popup
31. private function doActualPrinting():Void
32. {
33. var printJob:PrintJob = new PrintJob();
34. // Keep track of # of pages - only print if there are pages to print
35. var pageCount:Number = 0;
36.
37. // Show the print dialog
38. if ( printJob.start() ) {
39. // The user has opted to print - add the pages that
40. // need to be printed
41. pageCount += PrintUtil.pagenate( printArea, printJob );
42.
43. // Send the content to the printer
44. if ( pageCount > 0 ) {
45. printJob.send();
46. }
47. }
48.
49. // Explicitly delete the printJob
50. delete printJob;
51.
52. // Fix clipping now that print is done
53. clipForPrinting( false );
54. }
credits to the original: Link to source

Related

TCPDF create move-able "box" with text without using ln settings

I am trying to create a bit of a unique table in TCPDF as shown below:
Getting the captions, headers and rows setup is easy. The hard part is the "bar".
The bar needs a few things:
Editable X-position
Text
Originally I was trying to use MultiCell; however, I got some weird behavior as shown below:
Multi-Cell:
I believe this is because of the ln settings. If we look at my code you can see that I am trying to create a Cell and then a MultiCell inside of it. Both of these use the have the ln setting to put the next cell below.
I tried setting the MultiCell's ln to 0 (to the right) but it had no visible change.
//multi cell
// extend TCPF with custom functions
class MYPDF extends TCPDF {
// SCC table
public function SCCTable($headers,$rows) {
// Colors, line width and bold font
$this->SetFillColor(0,128,128);
$this->SetTextColor(0);
$this->SetDrawColor(0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');
// Header
$num_headers = count($headers);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell(
$headers[$i]->width,
$headers[$i]->height,
$headers[$i]->text,
1,
0,
'C',
1
);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
$num_rows = count($rows);
for($i = 0; $i < $num_rows; ++$i){
$this->Cell(//Row
$headers[$i]->width * $num_headers, //Row width should be the sum of all header width.
$rows[$i]->height,
//Row's Text
$this->MultiCell(
$rows[$i]->width,
$rows[$i]->height,
$rows[$i]->text,
0, //Border
"C", //Text Align
false, //fill, determines if the background is painted or transparent (false).
2, //ln, 1 = Next cell starts at beginning of new line.
$rows[$i]->x,
$rows[$i]->y
),
1, //Border
2, //ln, 1 = Next cell starts at beginning of new line.
"L" //text align
);
}
}
}
After this I found out about TextField. When I tried this I got just as weird behavior...
//text field
// extend TCPF with custom functions
class MYPDF extends TCPDF {
// SCC table
public function SCCTable($headers,$rows) {
// Colors, line width and bold font
$this->SetFillColor(0,128,128);
$this->SetTextColor(0);
$this->SetDrawColor(0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');
// Header
$num_headers = count($headers);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell(
$headers[$i]->width,
$headers[$i]->height,
$headers[$i]->text,
1,
0,
'C',
1
);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
$num_rows = count($rows);
for($i = 0; $i < $num_rows; ++$i){
$this->Cell(//Row
$headers[$i]->width * $num_headers, //Row width should be the sum of all header width.
$rows[$i]->height,
//Row's Text
$this->TextField(
$rows[$i]->text,
$rows[$i]->width,
$rows[$i]->height,
[],
[],
$rows[$i]->x,
$rows[$i]->y
),
1, //Border
2, //ln, 1 = Next cell starts at beginning of new line.
"L" //text align
);
}
}
}
Finally I thought of using the Rect function to create a rectangle and Text to the draw the text. Using variables I could "glue" the Text to the Rectangle; however, the textfield uses the ln setting as well; furthermore, looking at the actual code there is this line:
$this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
Seeing as it creates a cell, then it should run into the same problem as MultiCell, as the only difference between Cell and MultiCell in my case is the ability to change the x-position from the left border.
So I'm stuck with this question: How can I draw a "box" that has text and can be pushed along horizontally?
How this is done is not that important except that images aren't an option.
I realized I didn't actually need to have the original row. I could just make due with the "bar".
$this->MultiCell(
$rows[$i]->width,
$rows[$i]->height,
$rows[$i]->text,
1, //Border
"C", //Text Align
true, //fill, determines if the background is painted (true) or transparent (false).
2, //ln, 1 = Next cell starts at beginning of new line.
$rows[$i]->x,
$rows[$i]->y
);
Though with that said it would still be nice to know how to do with rows...

Looping through subviews swift / ios

var replycount = replies.count
var startingTag = 10
for subview in self.personView.subviews {
if replycount > 0 {
subview.viewWithTag(startingTag)?.backgroundColor = .green
replycount = replycount - 1
startingTag = startingTag + 1
}
}
}
I'm pulling a number from a server (replycount) and trying to represent the number by coloring some views on the screen. I've got 10 bubbles across the bottom, and if replycount was 4, starting from the left I'd want 4 of the bubbles to have a green background color, and the rest to remain their default black.
What I'm trying to do with the above code is to grab the reply count which I"m doing successfully, my first bubble starts at a tag of 10 and goes up to 19, and if the reply count is more than 0, meaning there is a reply, I'm wanting to take the first tag of 10, make it green, then move on to the next tag of 11, minus from the reply count, and keep going until there are no more replies.
The only time the code below works is if I comment out
replycount = replycount - 1
and change viewWithTag(startingTag) to viewWithTag(10) and hardcode in the number. If either of those two things aren't done the view's color is not changed.
Is there a better way to do this, or any ideas why I'm running into this issue?
Skip looping through subviews and just do self.view.viewWithTag? Although I'm just assuming all of the bubbles are in the same view, and not each in a different subview.
Although I would probably have written it something like this for clarity:
var replycount = replies.count
for tag in 10 ..< (10 + replycount) {
self.view.viewWithTag(tag)?.backgroundColor = .green
}

How can I obtain 2 blocks of 3 columns on the same page with TFPDF

I want to create a layout of 2 blocks on a page, each with 3 columns. I am currently using example 10 of the documentation and the setEqualColumns() method.
How can I fix a maximum height?
The result I want to achieve:
you must use SetAutoPageBreak() and resetColumns() functions (more details here). Be careful, if your text is longer than the allowed space, the rest of the text will be written on the next page.
For example :
//Set the distance from the bottom the first block must stop : 130
$pdf->SetAutoPageBreak(true, 130);
//Write the first block : 3 columns, width 50
$pdf->setEqualColumns(3, 50);
$pdf->writeHTML($content_1);
//reset columns
$pdf->resetColumns();
//reset the X position and the page break
$margins = $pdf->getMargins();
$pdf->setX($margins['left']);
$pdf->SetAutoPageBreak(true, $margins['bottom']);
//write the chapter title (like in the TCPDF example 10)
$pdf->SetFillColor(200, 220, 255);
$pdf->Cell(180, 6, 'Chapter 2', 0, 1, '', 1);
//write the second block
$pdf->setEqualColumns(3, 50);
$pdf->writeHTML($content_2);

How do I remove bottom padding that appears below a TextBox in Windows Phone when tapped?

I am attempting to implement a chat view in Windows Phone 8. When a user taps my TextBox at the bottom of my View, the view shifts vertically as the keyboard appears, but an additional amount of padding appears at the bottom of the view. I have seen this happen in other apps as well.
Here is my app:
Here is an equivalent app (Whatsapp) that has clearly solved the problem.
Anyone have any ideas on how to correct this issue in a way that won't break my view? My attempts to manually modify padding when Focused/Unfocused have not been successful.
Good news! I have managed to figure out a fix for this. The below code stops the page from being moved up at all and then adds a margin to the bottom of the text box to place it above the keyboard. The value below of 417 seems to work well for me but you can change this to whatever you like. Using this method also stops other content being pushed off screen like the conversation as it will be fully scrollable while the keyboard is active.
private void TextBox_GotFocus_1(object sender, RoutedEventArgs e)
{
var rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
rootFrame.RenderTransform = new CompositeTransform() { TranslateY = +0 };
TextInput2.Margin = new Thickness(12, 0, 12, 417);
}
private void TextBox_LostFocus_1(object sender, RoutedEventArgs e)
{
var rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
rootFrame.RenderTransform = new CompositeTransform() { TranslateY = +0 };
TextInput2.Margin = new Thickness(12, 0, 12, 12);
}
You can always try to give bottom margin with negative value. example give -40px and see.
If you're using Grid, set Height to "Auto" where the TextBox is.
Set InputScope="Default".

How do I adjust where the calendar appears for the datePicker in the Grails UI plugin without the position changing when the page is resized?

I wanted to change where the calendar appeared for the datePicker portion of the Grails UI plugin. After a bit of digging, I found it in the InputTagLib.groovy file:
out << """
YAHOO.util.Event.on("${showButtonId}", "click", function() {
var buttonRegion = YAHOO.util.Dom.getRegion('${showButtonId}');
var buttonHeight = buttonRegion.bottom - buttonRegion.top;
var buttonWidth = buttonRegion.right - buttonRegion.left;
var xy = YAHOO.util.Dom.getXY('${showButtonId}');
var newXY = [xy[0] + buttonWidth, xy[1] + buttonHeight];
YAHOO.util.Dom.setXY('${id}_calContainer_c', newXY);
GRAILSUI.${jsid}Panel.show();
if (YAHOO.env.ua.opera && document.documentElement) {
// Opera needs to force a repaint
document.documentElement.className += "";
}
});"""
The position is set on this line:
YAHOO.util.Dom.setXY('${id}_calContainer_c', newXY);
The YAHOO.util.Dom.setXY() method takes two arguments.
The first argument of the setXY method is either the ID of an HTMLElement, or an actual HTMLElement object. The second argument is an array containing two values: [x, y] where x is the distance from the left edge of the document, and y is the distance from the top edge of the document.
Source: http://developer.yahoo.com/yui/examples/dom/setxy.html
So I can easily adjust where the calendar appears by changing the values in the newXY variable that is passed to the setXY method and it works fine.
However, if I resize the page, the calendar positions its top left corner directly under the showButton's bottom left corner. What is it that makes the repositioning happen when the page is resized and how can I resolve it?
EDIT : A little more info:
This happens in the most recent versions of IE, Firefox, and Chrome
If I resize the page and then click the button to show the calendar, the calendar shows in the expected place but it will reposition if I resize the page again once the calendar is open

Resources