GithubHelp home page GithubHelp logo

kendallb / printhtml Goto Github PK

View Code? Open in Web Editor NEW
45.0 9.0 18.0 39.43 MB

Open source command line program to print HTML pages using QtWebKit

License: MIT License

QMake 3.67% C 10.06% C++ 86.27%

printhtml's Introduction

PrintHtml

PrintHtml is a command line program to print HTML pages and more importantly allows you to send the output to a specific printer. I was searching for a long time to find a solution to this problem after we ran into more and more issues using the .net WebBrowser control. Most recently the WebBrowser control kept failing and silently not printing until we rebooted the computer and updating to Windows 10 made no difference. It worked flawlessly for probably 4 years, but now it seems it has problems. On top of that we needed the ability to print to different printers and the WebBrowser control always sends the output to whatever printer is configured as the default for Internet Explorer.

Many years ago we wrote a version of our printing code for packing slips using C++ and the QtWebKit library. But when we ported all our code to C# and .net, we moved to using the .net WebBrowser control and it served us faithfully for many years. So to solve the problems we had with the .net WebBrowser control I dug up the old C++ application that printed web pages files and turned it into this project to print via the command line, and enabled it to print to different printers.

The program is pretty simple and the command line usage is like this:

Usage: PrintHtml [-test] [-p printer] [-l left] [-t top] [-r right] [-b bottom] <url> [url2]

-test         - Don't print, just show what would have printed.
-p printer    - Printer to print to. Use 'Default' for default printer.
-a page       - Paper type [A4|A5|US letter]
-l left       - Optional left margin for page.
-t top        - Optional top margin for page.
-r right      - Optional right margin for page.
-b bottom     - Optional bottom margin for page.
url           - Defines the list of URLs to print, one after the other.

Since it has to spawn up an entire instance of the QtWebKit control in order to perform the printing the program is written to accept multiple URL's on the command line, one after the other. So if you have large batches of URL's to print, like we do simply pass them all on the command line. In our case we print our pick sheets using this tool by passing in batches of 20 URL's at a time and it works very fast without anything showing on the screen.

Build environment

To build this you need to use a version of Qt that includes the QtWebKit control. This control was deprecated and removed from the Qt 5.x releases, and although there is an external project that has ported the QtWebKit control to the latest Qt releases, I was unable to find any pre-compiled libraries I could use out of the box for this project. Hence for simplicity I decided to stick to using Qt 4.8 and as of today the code is written to compile and link with Qt 4.8.6 using the Qt Creator that came with the Qt 5.7.1 release by installing Qt 4.8.6 alongside it. The build in the deploy directory is built using MingW 5.3 as a 32-bit x86 application.

Theoretically the code is 100% portable so you could build it for Mac or Linux, but I have only done it on Windows since that is what I needed it for :)

Pre-built binaries

For those who just want the resulting app and do not want to compile the code yourselves, I have included a pre-built Windows x86 version of the program in the deploy directory.

Caveats

The biggest caveat at the moment is that the QtWebKit control has no support for renderin headers and footers on the page. For us this is not a big problem, but for some it could be a deal breaker. There have been quite a few discussion about this that I could find on the web, but no solutions that seemed to work. If anyone has ideas about how to fix this it would be great to add some options to control the headers and footers to this program.

Potential improvements

Something that would cool to add, but I am not familar enough with Qt and C++ these days to implement, would be to turn this application into a small REST server that would sit in the background and accept URL's and related options to print them over the wire so it would be easy to use from other apps without having to resort to executing it on the command line. If someone more familiar with Qt and REST services knows how to build a basic REST server into the app that would be a pretty slick improvement.

printhtml's People

Contributors

kendallb avatar khalidchawtany avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

printhtml's Issues

Orientation is not working

Hello,

We are thankful to you for this wonderful utility...

If I pass values for orientation it is not taking.

PrintHtml.exe -p "\192.168.120.156\HP LaserJet Professional M1136 MFP (Copy 1)" -l 0 -t 0 -r 0 -b 0 -a "A5" -o "Portrait" URL

I tried without quote also but somehow when a portrait is given it is showing "Failed to load HTML"

Cuts row in half when printing large tables

When printing tables that span over multiple pages, the rows and its content split into 2 parts each one on a separate page. This makes the text unreadable when printed.

Windows prebuilt files after Dec 2017 don't work

Both of the prebuilts after 2017 don't work properly, the 4.6 Static version is missing many of the necessary library files, the 4.7 version is missing libgcc library files.

On top of this if you combine the DLL files from both pre-builds (to cover for the missing Qt/LibGCC DLLs in each), neither of them appear to be able to load any webpage, providing the same command (below) to the Dec 2017 build will correctly print the page, but subsequent versions show "Failed to load HTML" error.

printhtml.exe -p "<printer_name>" "https://www.google.com" -t 0 -b 0

3 seconds execution delay

I am using it for a restaurant for printing on the thermal receipt printer.
However it has a delay around 4 to 5 seconds each time it gets executed.
Any ideas how to improve this ?
Maybe if we converted it to QT web service or QT windows service could be much faster?

A4 page

Hello, please can you build version with paper size set to A4?

scripting problem

Just found the program start but hang in memory if is started from CGI scripting environment. From console window it work normally. My guess is it cant create GUI box with green progress bar in true scripting enviroment and wait for it, or something like this. Any other reason for such behaviour?

command with bottom margin not working

Thanx for this repo.
I am using prebuilt from deploy x86_qt_4.7.4 to print on thermal printers.
Commands with argument -b is not taking effect as page is auto cut immediately after content.
Any work around?

using PrintHtml in windows servives .net

Hi
If it's posible to use PrintHtml in windows services, because all error msg are interactive like :

QMessageBox msgBox;
msgBox.setWindowTitle("Fatal Error");

mayby it could drop msg to txt file or sth like that.

Thx,

Margins not working?

Is there an issue with the margins?

Does anyone know a QT version that has no issues?
Flex box support (Not much needed)
No margin problems
No double Text sometimes (4.6 does not have this issue but margins are broken)

Exitcode

Does this prohgram provide any exitcode (errorlevel) if sending to printer (or printing itself) failed?

Found nothing in documentaion

Flex box, Euro sign (โ‚ฌ) and Non English characters not working

Hey flex box wont work right?
What about the special character and Other non English Language? They don't show up right

Edit: Seems like if I change everything into HTML Converted data is working.
So for Euro sign I have to use the HTML TAG &#128;.
And for any other non English word.

Only base64 png picture

Hello, is there any possible way print some other picture formats than base64 png? Javascript doesnt work too. ts there any way to get it work?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.