Hello my name is alex and I'm from France so sorry for possible mistakes.
I developed a programm in c++ for a gite de france in order to create contracts everything fine but I can't fine how to print html files in c++ ?
So please anyone have a solution ?
I tried system("print test.html") or system("print COM1 test.html") bit it doesn't work...
When you say "print", do you mean
(a) send plaintext HTML to a printer,
(b) send rendered HTML to a printer,
(c) display the text of the html file to the console, or
(d) display HTML rendered as a web browser would?
(c) is by far the simplest of these three options.
but in fact the contract are made in html but I think they can be converted in pdf so if it is easier to print a pdf in c++ it would be ok too ;-)
Alex
the dos print command is really just for text. You can use it, but your printer needs a com port to be set (printer properties, ports) (these used to be physical plugs on computers, they are virtual now) before it will go. Slightly easier, notepad /p file will use the default printer for a text file. Other programs may support this as well, you can see if one of the browsers has a similar option.
To do it in code (vs letting some other program do it for you) rendered html is going to require you to write some GUI specific code to talk to the installed printer from the common interface -- not strict C++ code, but library calls.
I was looking into that print program. It seems really old and possibly defunct. I couldn't get it to work; I doubt it knows how to handle rendering HTML.
The main problem is that you need some sort of middleman to tell you how to render the HTML to a printer. For example, you can force an internet explorer pop-up and then print from there. In WinForms this can be accessed with a WebBrowser control.
There's a project on GitHub that apparently uses the QtWebKit to assist in printing: https://github.com/kendallb/PrintHtml
But that requires Qt, which is a pretty heavy dependency.
(Not sure if this is the same "print html" as jonnin's link. I think it's different)
The easiest way to print a rendered HTML document is load the file into a browser and use the "print page" option. If the web page(s) are in PDF format use a PDF viewer and print the PDF.
i tried wkhtmltopdf to first convert my html files to pdf files; it works fine but in the new created pdf files the pictures and the objects called frome other txt files are empty the convertor didn't convert them...
i tried to add :
wkhtmltopdf L:\\private\\Contratformauto.html c:\\LC\\contrat.pdf [ --allow <L:\\private>]"
to autorize the software to acces to image and text situated in .txt but it says acces denied ?
does anybody have an idea ? i tried work as administrator too but nothing..
did you use the administrator version of the console (cmd)? (batch file, or just typing direct)
Or are these system calls in your c++? (in which case, try running the c++ program in admin console).
In fact I changed the version of wkhtmltopdf because the old versions didn't have the problem ...
It's strange because I was in admin mode and clear all restrictions to access the files doesn't matter I will use the old version 😉
The answer in the above link says to load the html into the qWebEngineView, wait for an event that says that the loading is completed, then convert it to a PDF, finally print the PDF. The good news is that it's all controlled withing Qt, so no more system() calls.
I think the better question here is how OP's employer feels about using Qt, as there are some very hairy sticking points to using that in a business environment.