Is there a way to run a file through a print driver without opening the application?
Ex: run a .docx file, without opening word, and save it to file?
Since it is a .docx-file Microsoft Word is probably the best program to do the task.
I would have a look at the [command line arguments] to Word:
Have a look at the following switches:
/q, /n, /mFilePrintDefault and /mFileExit
(/q and /n explained in the page above, and /mXxxx refers to macros. Have a look att google.)
Example:
WINWORD.EXE your_document.docx /mFilePrintDefault /mFileExit /q /n
The following page seems to explain how to convert it to PDF.
What you are looking for is called "headless start" of the program which needs to print.
I know for sure that OpenOffice can do this.
Basically, you need to start it and invoke a macro which will do the printing. Even more, you can print to a PDF, HTML, or anything else that Oo supports.
This negates the need for install of Microsoft Word and the cost of license, because OpenOffice is free.
If you are looking only for .docx silent printing then [aioobe] answer is the best. If you want a more generic silent print program that runs on Windows, use powershell or .NET and use the print verb. http://www.eggheadcafe.com/software/aspnet/30441939/how-to-suppress-printdialog-when-using-print-verb.aspx provides an example.
Hope this helps, if so +1 please :)
You might be interested in DocTo which will convert a word document to another file format, including pdf and XPS but does require Word on the machine.
For example
Docto -f "c:\docs\mydocument.docx" -o "c:\output" -t wdFormatPDF
Will output mydocument.docx to c:\output\mydocument.pdf as a pdf file.
Related
I have a lua REPL, and would like to run a lua script file stored as plain text at HTTPS://URL. I understand os.execute() can run OS commands so we can use curl etc. to grab the script then load(). Is that something possible to do in lua REPL with a single line?
Note: If you're going to run source code directly from the web, use https at least, to avoid easy MitM attacks.
To give this question an answer, since Egor will probably not post it as such:
(loadstring or load)(io.popen("wget -qO- https://i.imgur.com/91HtaFp.gif"):read"*a")()
For why this prints Hello world:
loadstring or load is to be compatible with different Lua versions, as the functions loadstring and load were merged at some point (5.2 I believe). io.popen executes its first argument in the shell and returns a file pointer to its stdout.
The "gif" from Egor is not really a GIF (open this in your browser: view-source:https://i.imgur.com/91HtaFp.gif) but a plain text file that contains this text:
GIF89a=GIF89a
print'Hello world'
Basically a GIF starts with GIF89a and the =GIF89a afterwards is just to produce valid Lua, meaning you don't have to use imgur or gifs, you can just as well use raw gists or github.
Now, it's rather unlikely that os.execute is available in a sandbox when io.popen is not, but if it is, you can achieve a one-liner (though drastically longer) using os.execute and temporary files
Lets first write this out because in a single line it will be a bit complex:
(function(u,f)
-- get a temp file name, Windows prefixes those with a \, so remove that
f=f or os.tmpname():gsub('^\\','')
-- run curl, make it output into our temp file
os.execute(('curl -s "%s" -o "%s"'):format(u,f))
-- load/run temp file
loadfile(f)()
os.remove(f)
end)("https://i.imgur.com/91HtaFp.gif");
And you can easily condense that into a single line by removing comments, tabs and newlines:
(function(u,f)f=f or os.tmpname():gsub('^\\','')os.execute(('curl -s "%s" -o "%s"'):format(u,f))loadfile(f)()os.remove(f)end)("https://i.imgur.com/91HtaFp.gif");
Something that I've had a good hard look for and I have not been able to find, is how to efficiently obtain a hard copy of Javadocs? Obviously, one solution is simply to navigate to each page and execute a browser print, but there's got to be a better way! Do you guys have any ideas?
You can use DocBook Doclet (dbdoclet) to create DocBook XML from your JavaDoc Comments. The DocBook XML can then be transformed to PDF or (Singlepage-)HTML.
You can call the tool from the commandline. Point it to your class files and it will generate the DocBook XML. This works similar to the javadoc command which will generate the JavaDoc HTML. Example:
./dbdoclet -sourcepath ~/my-java-program/src/main/java -subpackages org.example
The result is a DocBook XML file in a dbdoclet subdirectory which can be used to create a PDF or HTML file. This can also be done from the command line; I am using the docbkx-maven-plugin for this.
You can do mass conversions with it, but it would require some time to make it work the way you want.
We have developed an in-house printing solution that allows users to manage their prints (audit/merge/review/send to multiple printers) etc... but we are having issues with the very end of the process - the final print.
Currently our solution stores documents (original & after merging) in PDFs. We need to be able to send these documents to a particular printer and have it in some cases (when the user has selected the option) print page 1 to tray 8 and the rest to tray 1. We can't split the PDFs and print them separately as they also have to be stapled by the printer as a single job.
Our idea was to convert the PDF files to PostScript files using ghostscript then insert PJL commands into the PostScript and then print this modified PostScript file using gsprint.
Unfortunately the combination of ghostscript, postscript, PJL and gsprint doesn't seem to be working. The PJL commands we try, which we CAN get to work within text files sent to the printer via the windows copy command, don't seem to have the same affect when put into the PostScript files and printed using gsprint.
Can anyone spot any hideous flaws in what we are doing to the PostScript or have any idea why the PostScript->PJL amends->gsprint workflow we have might not be working?
It's been very difficult to find examples online so it's very possible our placement of PJL commands is incorrect.
(//comments not in final file)
<ESC>%-12345X#PJL JOB<ESC>&l8H //start job printing first page
#PJL ENTER LANGUAGE = Postscript //to tray 8 (letterhead)
#PJL COMMENT CANPJL SET STAPLE=ONEUPLEFT //indicate the document should be stapled
%!PS-Adobe-3.0 //start of PostScript file proper
---
%%PageTrailer //end of first page
<ESC>%-12345X#PJL EOJ<ESC>%-12345X //end the first job
%%Page: 2
<ESC>%-12345X#PJL JOB<ESC>&l7H //start 2nd job to print remaining
--- //pages to tray 1 (plain)
---
%%EOF
<ESC>%-12345X#PJL EOJ<ESC>%-12345X //end 2nd job
We then take this modified PostScript and use gsprint as follows:
gsprint -noquery -ghostscript gswin32c -printer "printer" "C:\postscriptfile.ps"
This all print out to the default tray and unstapled, i.e. none of this works as expected.
I hope it's clear what we are trying to achieve. Any help would be greatly appreciated.
Thanks in advance.
PS: All our printers are Canon printers.
Edit:
After KenS's answer below it seems the logical workflow should instead be PDF->PCL->add PJL->send to printer with "copy"
Unfortunately we are still having issues with this, certain PJL commands seem to be ignored by our printers (the printers are definitely PCL printers).
If we take a 2 page PDF produced by Microsoft Word, convert it to PCL using ghostscript then edit that PCL file with Notepad++ add add the following:
<ESC>%-12345X#PJL JOB NAME = "My Print Job Name"<CR><LF>
#PJL SET DUPLEX = ON
#PJL SET OUTBIN = LOWER
#PJL ENTER LANGUAGE = PCL
...original PCL data...
<ESC>%-12345X#PJL EOJ<CR><LF>
<ESC>%-12345X
the document comes out of the lower output tray but not duplexed. But what is extra odd is that the printer seems to take much longer to print when DUPLEX = ON than the exact same job with DUPLEX = OFF and it sounds like it's doing something different internally.
Any ideas?
I think you misunderstand how gsprint operates. It takes an input file, renders it to a bitmap, draws that bitmap on an appropriate canvas, and then uses the Windows printing system to print that canvas on a printer. It does not have any control of the printer at all, as a result embedding anything which is expected to control the printer (as opposed to the rendering) will not have any effect.
In addition, PJL is asociated with HP PCL printers, not with PostScript printers. Whil;e your PJL may work on a PCL printer, because it treats each page as a separate job, it won't work at all on a PostScript printer, and may well cause it to give you an error, depending on whether the interpreter ignores PJL commands or not.
In order to control the printer, you will need to determine what kind of input the printer supports (PostScript or PCL), you then need to convert your PDF to that form, then insert appropriate control sequences. In the case of a PCL printer you might reasonably use PJL, for PostScript printers you should control this using the setpagdevice operator. Assuming you have a Windows .WPD or .PPD file for your printer, the relevant control sequences can be found there, or by printing a few test files and examining their contents.
In passing; you say that the commands you are using work when sending text files to the printer. This means the printer at least understands PJL and is almost certainly a PCL printer. You can't send text to a PostScript printer, it will generate an error, because PostScript is a programming language and you will have syntax errors with any random piece of text. You can however send text to a PCL printer which assumes that anything not starting with a 0x1B (escape) is just text to be printed.
So using Ghostscript to produce PCL output, inserting your PJL as you have above, and then sending the result directly to the printer should probably work. Of course identifying the end of each page might be more difficult in a PCL file.
We had similar issue this is how we did using ghost script and PJL
http://reddymails.blogspot.com/2014/07/how-to-print-documents-using-java-how.html
Also bfo.com has some commercial jars which do the same thing without ghost script and in a Pure java way. But you have to pay for it :)
I'm going to a farm. I think there are no computers there, and my laptop is broken. I want to print out the code of some of my projects on A4 paper so I can review it while I'm there. It would be nice if it was printed with syntax highlighting.
Editors: Vim, Notepad++
Code: Html, CSS, Javascript
enscript
pygmentize
In emacs use ps-print-buffer-with-faces. There is also ps-print-region-with-faces for those occasions when you only want part of a file...
Use M-x <command> to invoke commands by name. Use C-h f <command> for help on a command and also to learn what (if any) keybinding it has.
a2ps tool produces nice PostScript files for program listing printing.
Vim has :TOhtml command which produces HTML with current open file highlighted according to Vim syntax coloring. GVim has Syntax -> Convert to HTML menu for this.
If you use LaTeX, look at listings package (pdf documentation at CTAN). It's a very good solution for including your code in documentation/presentation.
All these tools support syntax of many programming (and non-programming) languages.
Editplus prints with syntax highlighting intact
As suggested here, latexmk is a handy way to continually compile your document whenever the source changes. But often when you're working on a document you'll end up with errors and then latex will panic and wait for user input before continuing. That can get very annoying, especially recently when I hacked up something to compile latex directly from an etherpad document, which saves continuously as you type.
Is there a setting for latex or latexmk to make it just abort with an error message if it can't compile? Or, if necessary, how would I set up some kind of Expect script to auto-dismiss LaTeX's complaints?
(I had thought pdflatex's option -halt-on-error would do the trick but apparently not.)
Bonus question: Skim on Mac OSX is a nice pdf viewer that autorefreshes when the pdf changes (unlike Preview), except that whenever there's a latex error it makes you reconfirm that you want autorefreshing. Texniscope doesn't have this problem, but I had to ditch Texniscope for other reasons. Is there a way to make Skim always autorefresh, or is there another viewer that gets this right?
ADDED: Mini-tutorial on latexmk based on the answer to this question:
Get latexmk here: http://www.phys.psu.edu/~collins/software/latexmk-jcc/
Add the following to your ~/.latexmkrc file:
$pdflatex = 'pdflatex -interaction=nonstopmode';
(For OS X with Skim)
$pdf_previewer = "open -a /Applications/Skim.app";
While editing your source file, foo.tex, run the following in a terminal:
latexmk -pvc -pdf foo.tex
Use Skim or another realtime pdf viewer to view foo.pdf. For Skim, just look at the “Sync” tab in Skim’s preferences and set it up for your editor.
Voila! Hitting save on foo.tex will now cause foo.pdf to refresh without touching a thing.
With MikTeX, pdflatex has this command-line option:
-interaction=MODE Set the interaction mode; MODE must be one
of: batchmode, nonstopmode, scrollmode,
errorstopmode.
Edit suggested by #9999years:
Those values are equivalent to a set of LaTeX \commands that provide the same functionality.
From TeX usage tips:
The modes make TeX behave in the following way:
errorstopmode stops on all errors, whether they are about errors in the
source code or non-existent files.
scrollmode doesn't stop on errors in the source but requests input when a
more serious error like like a missing file occurs.
In the somewhat misnamed nonstopmode, TeX does not request input after
serious errors but stops altogether.
batchmode prevents all output in addition to that (intended for use in
automated scripts). In all cases, all errors are written to the log file
(yourtexfile.log).
You can also put \nonstopmode or \batchmode at the very beginning of your tex file; then it'll work with any TeX version, not just pdflatex. For more info on these and related commands see the very good reference on (raw) TeX commands by David Bausum. Especially the command from the debugging family could be of interest here.
Another possible hack is simply to use:
yes x | latexmk source.tex
You could always create an alias for 'yes x | latexmk' if you're going to use this option lots. The main advantage of this that I can see above the other suggestions is that it is very quick for when you occasionally want latexmk to behave like this.
Mehmet
There is also a \batchmode command may do the work.