Rectangle 27 3

I'm assuming you place a CSS page break at the end of each report and not manually at the end of each page. So your problem is to know when a page break will occur naturally within a long HTML document. The answer is - you can't. Even if you know how many lines of a table fit on a page (for example) you'll only know that for a given page size and print settings. If somebody decides to print your report on legal paper scaled 200% then your document will never know that. In my opinion, your options are 1) guess or 2) don't worry about it.

You are right about the printing variation. I am putting the CSS page break at the end of each report. This is on an intranet, so although the people could change the printing setup, they generally will not, and if they do, I can tolerate the solution "breaking" in those cases because my response can be "don't do that!" ;) But I am getting concerned that you may be right and this may not be possible...

If you all used the same hardware and same setup I would simply put each report in a separate DIV and then use theDiv.clientHeight to find out how long it is. If you know what size DIV will fit on a printed page you should know how many pages there are. You could then absolutely position en element with the page number where it belongs. It would take some work, but I think it would work with enough trial and error.

But then the element would change the div's size too... that should be fun to watch.

@ANeves not when it's absolutely positioned.

javascript - How can I count CSS page breaks for printed HTML? - Stack...

javascript html css printing
Rectangle 27 6

I know that this subject is quite old but I want to share my experience about that topic. Actually, I was searching a module that can help me with my daily reports. I'm writting some documentations and some reports in HTML + CSS (instead of Word, Latex, OO, ...). The objectif would be to print them on A4 paper to share it with friends, ... Instead of searching, I decided to have a small funny coding session to implement a simple lib that can handle "pages", page number, summary, header, footer, .... Finally, I did it in ~~2h and I know that's not the best tool ever but it's almost ok for my purpose. You can take a look at this project on my repo and don't hesitate to share your ideas. It's maybe not what you are searching for at 100% but I think that this module can help you.

Basically I create a page of body "width: 200mm;" and container of height: 290mm (smaller than A4). Then I used page-break-after: always; so the "print" option of the browser know when to split pages.

css - How to make a HTML Page in A4 paper size page(s)? - Stack Overfl...

html css printing
Rectangle 27 6

I know that this subject is quite old but I want to share my experience about that topic. Actually, I was searching a module that can help me with my daily reports. I'm writting some documentations and some reports in HTML + CSS (instead of Word, Latex, OO, ...). The objectif would be to print them on A4 paper to share it with friends, ... Instead of searching, I decided to have a small funny coding session to implement a simple lib that can handle "pages", page number, summary, header, footer, .... Finally, I did it in ~~2h and I know that's not the best tool ever but it's almost ok for my purpose. You can take a look at this project on my repo and don't hesitate to share your ideas. It's maybe not what you are searching for at 100% but I think that this module can help you.

Basically I create a page of body "width: 200mm;" and container of height: 290mm (smaller than A4). Then I used page-break-after: always; so the "print" option of the browser know when to split pages.

css - How to make a HTML Page in A4 paper size page(s)? - Stack Overfl...

html css printing
Rectangle 27 4

I don't know if you can do it with other PDF viewers in such a way that those viewers are plug-and-play replacements for Adobe Reader. You'll probably have to tailor it to each program you want to support. It's not so difficult to have Reader on one's system, really, if it's necessary to perform a job and most computers come with it preinstalled.

The first thing you have to know is that when you tell it to print via that verb, via either code or the Explorer context menu, you are doing something like this:

""C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe"" /p /h "%1"

Note the arguments: /p (tells it to print) and /h (start minimized).

AcroRd32.exe /t path "printername" "drivername" "portname"

The document specifies that this initiates Adobe Reader and prints a file, whose path must be fully specified, while suppressing the Print dialog box. (Copy-pasted from Developer FAQ.)

There is also an option /n which "launches a separate instance of Acrobat or Adobe Reader, even if one is currently open." (Developer FAQ again.) That could be used to run multiple print jobs in parallel, I imagine.

So basically, you could iterate your list of PDFs, and for each one start a new print process with a Process.Start call and wait for it to close via a Process.WaitForExit. This will make your program appear to hang and I hate when programs hang while they perform operations, so you should really do this in a cancellable BackgroundWorker that reports progress and still leaves your GUI somewhat interactive.

Thanks, @djdanlib. I have confirmed now that I can assume that Acrobat Reader is present, and so I can use your Acrobat Reader /t solution. It does print, but adding /h does not make it minimized.

c# - How does Windows bulk print PDF documents? - Stack Overflow

c# pdf printing
Rectangle 27 3

I can't talk about the technical details because I don't know them, but this doesn't surprise me: the terminal was not designed for printing lots of data like this. Indeed, you even provide a link to a load of GUI stuff that it has to do every time you want to print something! Notice that if you call the script with pythonw instead, it does not take 15 seconds; this is entirely a GUI issue. Redirect stdout to a file to avoid this:

import contextlib, io
@contextlib.contextmanager
def redirect_stdout(stream):
    import sys
    sys.stdout = stream
    yield
    sys.stdout = sys.__stdout__

output = io.StringIO
with redirect_stdout(output):
    ...

python - Why is printing to stdout so slow? Can it be sped up? - Stack...

python linux printing stdout tty
Rectangle 27 1

I tried to give a new approach to my problem, since I can't print single div per page and I don't know why, I must find another way. But it's not that I didn't know how it works... I created a JSFiddle and it worked. In my own project, I created a html page and it worked. But since I was in JSP, maybe it was messing with my code somewhere.. I have no idea.

function getStuffToPrint(data){
        var html = "", index, len;
        for (index = 0, len = data.length; index < len; ++index) {
            html += "<div class=\"custom-page-break\">" + data[index].innerHTML + "</div>";
        }
        var mywindow = window.open();
            mywindow.document.write('<html><head>');
            mywindow.document.write('<link href="my/path/to/styles/print.css" rel="stylesheet" type="text/css"/>');
            mywindow.document.write('</head><body >');
            mywindow.document.write(html);
            mywindow.document.write('</body></html>');

            mywindow.document.close();
            mywindow.focus();

            mywindow.print();
            mywindow.close();

            return true;
    }
data
objectHTMLCollection
document.getElementsByClassName("custom-page-break")

It's a bit ratchet, I had to write the div with the class name again...

display: block
page-break-inside
@media print {
    .custom-page-break  { 
        display: block !important;
        page-break-before: always !important;
        page-break-inside: avoid !important;
    }
}

html - Google Chrome (v.51) not applying print media css - Stack Overf...

html css google-chrome printing media-queries
Rectangle 27 2

Don't know (as for now) why, but this one helped:

@media print {
        html, body {
            border: 1px solid white;
            height: 99%;
            page-break-after: avoid;
            page-break-before: avoid;
        }
    }

Hope someone will save his hair while fighting with the problem... ;)

css - how to avoid extra blank page at end while printing? - Stack Ove...

css printing
Rectangle 27 3

In IE there are the nonstandard window.onBeforePrint() and window.onAfterPrint() event listeners. There isn't a non-IE way to do it that I know of, however.

What kinds of changes are you trying to make? It's possible that your problem could be solved by specifying different rules for your print stylesheet.

For printing it maybe nice to add aditional content to the DOM. This could all be done with print.css, hiding other elements by default, enabling them. I'd prefer the javascript approach though. Do you know a solution for other browsers?

Javascript Event Handler for Print - Stack Overflow

javascript events printing
Rectangle 27 3

In IE there are the nonstandard window.onBeforePrint() and window.onAfterPrint() event listeners. There isn't a non-IE way to do it that I know of, however.

What kinds of changes are you trying to make? It's possible that your problem could be solved by specifying different rules for your print stylesheet.

For printing it maybe nice to add aditional content to the DOM. This could all be done with print.css, hiding other elements by default, enabling them. I'd prefer the javascript approach though. Do you know a solution for other browsers?

Javascript Event Handler for Print - Stack Overflow

javascript events printing
Rectangle 27 3

Edit 2 After reading Arjan's answer, I realize that this solution does not address correctly sites using (or abusing) the @media print CSS. (See example below.) But I think this solution still holds valid as a "non-perfect-quick-and-dirty-trick", above all for code that you have written and that you know beforehand that it doesn't have this.

<style>
<link rel="stylesheet" type="text/css" media="screen">

and the browser will apply it. You'll also have to deactivate the screen-only ones.

Of course, this is only useful if you only want to quick-check a few pages with very few stylesheet links, but at least, you do not need to install any additional plugins.

// Save all stylesheet links
allStylesheets   = $('link[rel="stylesheet"], style');
// Save the print-stylesheet links
printStylesheets = $('link[media*="print"], link[media*="all"], style[media*="print"], style[media*="all"]');

// Set all stylesheet medias to something 'exotic'
if (null != allStylesheets) {
    allStylesheets.attr("media", "aural");
}
// Switch the print-stylesheet medias to 'screen'
if (null != printStylesheets) {
    printStylesheets.attr("media", "screen");
}

Note that the default media is "screen" (w3.org - media attribute). This could be used in a button to show a page preview. The only drawback is that you have to reload the page to restore the original view.

As pointed out above, this solution does not work with html code like this, because the styling inside the @media print won't be applied by the browser:

<html>
    <head>
        <title>Hello world</title>
        <style type="text/css" media="all">
            @media print { h1 { color: red; }}
        </style>
    </head>
    <body>
        <h1>Hello world</h1>
    </body>
</html>

printing - How to see the print media CSS in Firebug? - Stack Overflow

css printing firebug print-css
Rectangle 27 4

I know this question is very old, but another awk example:

awk '{print substr($0,index($0,$5))}' fileName

What it does: find the index where you want to start printing (index of $5 in $0) and print the substring of $0 starting at that index.

It may be late to the party, but it worked great for me. +1 =)

shell - AWK command to print until end of line - Stack Overflow

shell unix awk
Rectangle 27 2

Well, the obvious answer is that the sprintf is printing more characters than there is allocated space, so that some info on the end of the block (containing bookkeeping info for the memory manager) is being overwritten. Without examining the whole program, there are too many uncertainties here for us to diagnose it perfectly. For example, we don't know what param points to, and how you guarantee it's not too long. You could use snprintf to do this more safely.

c - Why does a perfectly fine free on a string cause "free(): invalid ...

c gcc free glibc
Rectangle 27 1

First if you are passing word to vowel I don't know why you use global. You are calling vowel inside a print so vowel should return a string instead of printing a string itself. Next by using a for loop you can check each character of the word and increment the score even if multiple occurances of a vowel appear.

word = str(input("Enter a word:"))

def vowel(word):
  score = 1
  for c in word:
    if "a" == c.lower():
        score += 5
    elif "e" == c.lower():
        score += 4
    elif "i" == c.lower():
        score += 3
    elif "o" == c.lower():
        score += 2
    elif "u" == c.lower():
        score += 1

  return "Your word scored "+str(score)+" in the vowel checker"

print(vowel(word))

python - Requires assistance with vowel checker program - Stack Overfl...

python
Rectangle 27 6

For what I know printing the complete stack trace in nodejs is not possible, you can just print a "partial" stack trace, you can not see from where you came from in the code, just where the Exception occur. That's what Ryan Dahl explains in this youtube video. http://youtu.be/jo_B4LTHi3I at min 56:30 for being precise. Hope this helps

true, but the module in @Timboudreau's answer "fixes" that

javascript - How to print a stack trace in Node.js? - Stack Overflow

javascript node.js stack-trace
Rectangle 27 1

I don't know why it didn't work at first... probably used on the wrong element. but just tried again and this fixes the problem CSS Printing: Avoiding cut-in-half DIVs between pages?

html - Text cut at page break when print - Stack Overflow

html css
Rectangle 27 1

I don't know why it didn't work at first... probably used on the wrong element. but just tried again and this fixes the problem CSS Printing: Avoiding cut-in-half DIVs between pages?

html - Text cut at page break when print - Stack Overflow

html css
Rectangle 27 1

The cleanest way that I know is to use sys.excepthook.

You implement a three argument function that accepts type, value, and traceback and does whatever you like (say, only prints the value) and assign that function to sys.excepthook.

import sys

def excepthook(type, value, traceback):
    print(value)

sys.excepthook = excepthook

raise ValueError('hello')

This is available in both python 2 and python 3.

excepthook
sys.excepthook = "excepthook"

The short answer is no. excepthook, at least in python 3 which I have now checked is a function pointer. This is what I get with a string: Error in sys.excepthook: TypeError: 'str' object is not callable

You must be running a different version than 3.2, correct?

python 3.5.3. But I find it hard to believe that they would change such a fundamental API in a non compatible way...

exception - In Python, how do I print an error message without printin...

python exception error-handling customization traceback
Rectangle 27 3

For what I know printing the complete stack trace in nodejs is not possible, you can just print a "partial" stack trace, you can not see from where you came from in the code, just where the Exception occur. That's what Ryan Dahl explains in this youtube video. http://youtu.be/jo_B4LTHi3I at min 56:30 for being precise. Hope this helps

true, but the module in @Timboudreau's answer "fixes" that

javascript - How to print a stack trace in Node.js? - Stack Overflow

javascript node.js stack-trace
Rectangle 27 1

Rafe mentioned this in a comment, but I don't know why he did not offer it as an answer. Using rgba() colors works to get faded text in Firefox to print. Example fiddle with this code:

<table>
    <tr><td>Test No Fade</td></tr>
    <tr><td>Test Fade 70%</td></tr>
    <tr><td>Test Fade 50%</td></tr>
    <tr><td>Test Fade 30%</td></tr>
</table>
tr + tr td {
    color: rgba(0,0,0,.7);
}
tr + tr + tr td {
    color: rgba(0,0,0,.5);
}
tr + tr + tr + tr td {
    color: rgba(0,0,0,.3);
}

Since you are not printing background colors and images, then I suggest all your .fade classes switch to rgba() for the color of the text for print media.

google chrome - Opacity on table cells in Firefox print CSS - Stack Ov...

css google-chrome firefox opacity printing-web-page
Rectangle 27 0

Much of the confusion is due to the placement of parentheses around the arguments to print. As you know, parentheses are optional with language constructs; what you probably didn't know is that they're removed during parsing.

Let's remove the parentheses first:

echo print '3' . '2' . print '4';

And illustrate the actual order of evaluation:

echo (print ('3' . '2' . (print '4')))
^     ^      ^                     ^
3     2      1--------->>----------1

In the heart of this you will find a concatenation of strings or string representations; this is evaluated first:

'3' . '2' . (print '4')

The first two elements are concatenated:

'32' . (print '4')

Then, the value of (print '4') is evaluated; after printing its argument '4', the return value of print itself is always int(1); this is cast into a string '1' and concatenated with the other elements:

'321'

This concludes the first step. The second step passes the temporary results to another print statement:

print '321'

As before, '321' is printed and now int(1) is returned for the last step:

echo 1

You can confirm this behaviour when you look at the opcodes that are generated (output column is added for clarity):

line     # *  op          return  operands        output
------------------------------------------------+-------
   1     0  >   CONCAT      ~0      '3', '2'    |
         1      PRINT       ~1      '4'         | 4
         2      CONCAT      ~2      ~0, ~1      | 4
         3      PRINT       ~3      ~2          | 4321
         4      ECHO        ~3                  | 43211
  • "3" and "2" are concatenated - "32" - and stored into ~0.
  • "4" is printed and the return value int(1) is stored into ~1.
  • ~0 and ~1 are concatenated - "321" - and stored into ~2.
  • "321" is printed and the return value is stored into ~3.
  • int(1) is printed as "1" due to string casting.

printing - Strange echo, print behaviour in PHP? - Stack Overflow

php printing echo