How can I select papertray - pdf-generation

How do I programatically select the papertray to use when I send a document to the printer? There is different papers in the trays (A5, A4, A4 with one tear off part or two tear off parts, Papers with logo and without logo).
Today we use the setpapertray command directly in the postscript-file, but this is not very convenient especially since we plan to move to producing pdf-files instead.
Any suggestions?
EDIT: Today we send the ps-documents directly to the printer with commands like
cat file.ps > /dev/usb/lp0
or in programs just by opening the device and writing to it.
So since we use postscript templates its easy to select the tray to use directly by putting a section like this in the template:
statusdict begin
/manualfeed false def
$paper_tray setpapertray
end
Now we want to get rid of the ps-templates since they are hard to work with, and its not always safe to assume the printer is directly connected but could be at a external printerserver.
Questions:
Is it possible to embed the tray selection in a pdf-file in the same way?
Is there another more convenient way to select tray for each document when printing multiple documents?

You can print PDF and PostScript files from the command line using cups, ie:
lp filename.pdf
You can pass options on the command line using the -o option, ie
lp -o media=A4 filename.pdf
If your printer supports trays then you can probably use something like this:
lp -o InputSlot=Tray2
You can list all the options for the -o switch:
lpoptions -l
See http://www.cups.org/documentation.php/options.html#OPTIONS for more details.

Related

Windows 10: Simple way to print a PDF-file without the save-dialog

I'm trying to print the PDf-file(s) in a certain folder (or alternatively just print the files one-by-one) using for example Micorosft Print to PDF in order to create flattened versions. However when using Microsoft Print to PDF i need to specify the ouput-file's name and path. Is there any way to circumvent this or an alternative virtual printer specialized on such a job?
What I've already tried:
Windows 10 Print to PDF from command-line and Printing PDFs from Windows Command Line
These approches try to use the command prompt (personally favoured by me aswell, as it allows to create a batch-file and automate the process completely), but unfortunately the programs/printers listed in those posts are either not free or show a save-file-dialog aswell. Furthermore they are quite slow (even though this is not my main focus). So far, PDFtoPrinter has been the best solution, though it shows the save-file-dialog aswell...
Another idea I got from this post is to create a (VBA-/PowerShell-)script, but I'm not very experienced at that.
Any way to print just one PDF via the console and then making a loop or maybe even hard-coding the names would suffice aswell. I can easily rename the files for example to 1.pdf, 2.pdf, 3.pdf, ...
At this point I've tried so much but there has to be a way to get this running. Any help would be greatly appreciated!
Microsoft Print to PDF on Windows is not "Free", simply "Leased", however that said you can change the owners designed behavior to a different "port" than "prompt" or use the drivers to print to your desired named file.
To use ONE fixed output filename like %TEMP%OUT.PDF you are best served by cloning/duplicate the "Microsoft Print to PDF" to a printer name of your choice so I call mine "My Print to PDF" as its shorter to type and the Auto printed file goes to MyData folder. For a visual guide see https://stackoverflow.com/a/69169728/10802527 and up vote there if that helps.
The alternative is to use a structure like
CliPdfApp /PrintTo file.pdf "Microsoft Print to PDF" "Microsoft Print to PDF" "C:\MyFavourite Places\FileName.pdf
However few apps follow the required convention, so WordPad will convert Docx or RTF via command line but can not handle a PDF and Edge AFAIK was not designed to make the PDF format CLI print friendly :-). But those links you have in the question will suggest acrord32 /p or /t filename printer printdriver filename and that is probably the best method for flattening acroforms
Disclaimer I support SumatraPDF so can suggest to "Print As Image ONLY" its perfect as one single 32 or 64 bit portable.exe https://www.sumatrapdfreader.org/prerelease so all you need is:-
SumatraPDF -print-to "My Print to PDF" filename.pdf (or other types supported)
There are other print methods/options but BE-AWARE that is NOT flattening forms since "Flattening" means convert the form to plain readable text and SumatraPDF ONLY prints PDF as Imagery.
So combining SumatraPDF with a promptless port will provide a single command to build a known output then you need to monitor that output and rename to one of your choice, that can be tricky if you are submerged and "running silent and deep" without GDI feedback (that the print is spooling/erroring) and time is as variable as the input PDFs complexity.
You use the word "Slow" but that is the innate feature of PDF "Slow and Steady" output are its designed aims.
As an alternative to SumatraPDF two other viewers are more geared towards PDF Command Line printing. One is Acrobat Reader as per above "/Terminate and Stay Resident" and it does that exceptionally well so should be preferred. A good alternative lightweight but powerful PDF handler is Tracker PDF X-change which has both command line printing and its own programmable printer drivers.
Win2PDF has a command line to create image only (flattened) PDF files.

Building a very simple wrapper for ANSI escape sequences

Maybe a mission impossible. Once upon a time I wrote a Ruby module SimpleDialog for text coloring in DOS windows. It does so by talking to the Windows APIs. Now I want to make it suitable for Mac OS as well, or even for the entire unix universe. Okay, just Terminal and xterm would satisfy my needs for the moment. ANSI escape sequences seem to be the appropriate weapons for the job. But using them I cannot always handle things as I would like to. Here is the functionality I try to realize:
def clear_screen
print "\e[H\e[2J\ec"
color( ... old colors stored in an instance variable ... )
end
The "\e[H\e[2J" part is the same as the clear command (that's how I've found this sequence [edit next day after some experiments: "\e[2J" does not erase any text sent before the "\e[H" sequence, even when it's visible on the screen]). Terminal and xterm only clear the visible part of the screen [issue 1]. The "\ec" part doesn't make sense for Terminal anymore, but this time xterm does succeed to clear the entire screen buffer. At doing so, it rings the bell [issue 2], while Terminal keeps silent. Since the "\ec" sequence resets the colors, the last settings have to be restored again. Not very elegant, altogether. The clear command submitted from the command line normally clears the entire screen buffer of xterm. However, it cannot wipe out the part that's left by my attempt to clear the screen by just sending "\e[H\e[2J" from Ruby.
def color( ... )
... too big to show here ...
end
The color method works almost fine, there's only one disappointment. In Windows, I can change the color of a rectangle without modifying the text that is already placed within it. I see no way how to do this by ANSI escape sequences [issue 3]. As a workaround I could memorize the text involved and restore it afterwards, of course. And this one is really puzzling me: the respons to "\e[6n" (report cursor position) is printed to the screen, with the last few
characters repeated after the command prompt. Can it be intercepted by Ruby [issue 4]?
The other methods are a piece of cake:
def shrink_window # to its original size
print "\e[9;0t"
end
def stretch_window # to the maximum size that fits on the screen
print "\e[9;1t"
end
def title(title = nil)
print "\e]2;#{title}\a"
end
def write(... text containing human-friendly color codes ...)
... trivial ...
end
MS-Windows allows me to get the current window title too, but I don't see real use for that (xterm doesn't listen at all when the title argument is an empty string, btw). The write method makes use of the color method. No problems here. So, in the end, four obstacles to overcome. Or to live with?
If you want help with all of these Mac OS and Unix terminal UI issues, try using the curses/ncurses libraries, through the Curses gem.
Since you already have a working Windows solution for this, you can create two classes that drive your dialog boxes. I suggest this because the presence of a curses library on Windows isn't always reliable or easy to install (see this question and its answers for examples of that problem in action). Keep your DOS implementation, then make an alternate that uses curses/ncurses. Then your code can chose which implementation to go with based on operating system or based on whether a working curses/ncurses library exists. Naturally, this path also simplifies adding even more methods of user interface later, too.

automatic copy paste from Browser to Microsoft Word

I want to copy some specific texts from internet browser(chrome) and want to paste them in proper fields of Microsoft word.. Let me explain what I want exactly... I have this kind of page structure in chrome-
Name-Deepak,Raju,Jhon,Robert.......
Salary-200,254,673,953...
Phone-987535747,856889479,64688539,357954228....
Etc..
I have a table in MS word as-
Sl. Phone. Name. Salary.
Can I make a auto copy paste program to make my table-
Sl. Phone. Name. Salary
1. 987535747. Deepak. 200
2. .......
Like this? Suggest me the best suitable platform to compile this.. Its best for me, if a bat file can do the job.. I know bit odd question.. And I should not ask the entire program,rather a section of it..Bt still....... actually I don't know from where to start..
Rather than use a wget which will only retrieve the document, what you want is a way of parsing the results of the web content and writing into an output file.
After searching the web, I could only come across
lynx which
is a text based browser and you can parse the -dump parameter to
output the text into file which you can then write a script to do
the final bit.
Also take a look at this
link
for more info on switches you can use most especially if the desired
text has links in it (-nolist)
elinks which is an advanced text based browser

How do I plot some data (using xmgrace in the terminal) using dots, not lines, without explicitly changing it in the GUI?

i'm using xmgrace in the terminal, and want the data to be displayed directly as dots instead of lines. Achieving this in the GUI is simple, but I have to read in multiple files, and do not want to change it every time i start xmgrace. Can I add a command to the files that are read in? Or can I use an option in the terminal when I start xmgrace?
The correct way to set the appearance of a plot from the commandline is to use an existing parameter file, specified using the flag
-param settings.par
The parameter file can be stored beforehand, using the GUI to modify the appearance of an existing, similar plot. Modify the plot as you like, then save the appearance settings in a parameter file (convention is to use the extension .par) using Plot > Save Parameters.
A typical example command would then be
xmgrace -block data2.dat -bxy 1:4 -block data2.dat -bxy 1:6 -param settings.par
In my experience, calling the
-param
flag last thing in your command works best.
There really is no need to be manually text-editing your grace plot files (.agr) to achieve this.
xmgrace has a full and complex language for expressing the configuration of the look and feel for the graph. There are two ways to go about what you described. The simple way is to load the dataset into xmgrace, change everything to make it look the way you want, then save the dataset. You will see the dataset now has tons of lines describing the configuration "#g0 on" "# s0 linestyle 1" etc with your dataset at the end, terminated by a &.
To replicate that graph, spit out the saved header, insert your data, and the insert the trailing &. Feed the result into xmgrace and everything will be all set up. Once you get comfortable you can start doing dynamic substitutions to rename the graph or change the symbol or whatever. See /usr/share/grace/examples for examples of what grace can do (and the config files which generate that).
The more complex method is to load the dataset, save it immediately, change it to look the way you want, and then save it again under a different name. Run diff on the two files and you will get a set of changes. You might need at most a handful of other lines from the non-changing portion, but that is somewhat rare. This produces the minimal set of fixed headers you need to prepend to the dataset. It usually isn't worth the effort to reduce the prefix size.

General Purpose Filter As You Type (aka typeahead, Incremental find, autocomplete) is it out there?

Background
Lately I've become a fanatic that everything I type while working on a computer should be compatible with "DRY". If there's anything I have to type more than once in any context, I want some kind of user-aware auto-complete option to do some of the work for me -- always -- no exceptions.
Having to work under Windows, I've looked at GUI solutions to make this insane goal a reality.
The (almost) optimal solution
If you have a moment, open up Firefox 3.0 and type a few keystrokes into the address bar. You will notice that it performs a kind of Incremental Autocomplete based on space-separated sub-strings of whatever you type. Another place in Firefox that does something similar is the about:config URL.
This is sub-optimal, because I don't want this in Firefox only. I want to use this everywhere.
The Question
Does anyone out there know of a widget or app that does nothing but insanely good incremental auto-complete that can be used as a general purpose "run everywhere" tool? Something that allows the user to: 1) maintain one or more "completion candidate files"; 2) pick one of those files as the source for Firefox 3.0 style completion; 3) return the result (or blank if the user canceled), and do those three things only?
Details
Here's how it should work:
STEP1: user saves or more csv file(s) (or other easy-edit format) somewhere in his hard-drive
STEP2: user creates a Windows Script Host script or a batch file (or whatever) instantiates the FilterAsYouType GUI
STEP3: user runs the script file, and the script file instantiates the GUI, telling it which CSV file to use as the source of all potential completions
STEP4: the user either chooses one of the completions, supplies his own text that is not in the list, or cancels out without supplying anything
STEP5: when the user is done the script saves the result to a variable and does something with it
Here is some pseudo-code for the script:
include "GenericTypeaheadWidget";
var gengui = new GenericTypaheadWidget('c:\docs\favorite_foods.csv');
var fave_food = gengui.get_user_input();
if(fave_food != ''){
alert('you chose '+fave_food+'!');
}
The rationale
The goal is to just have a way to always be able to do auto-completions from a list of arbitrary items, even if the list is a couple thousand items, and not have to rely on it being built into some IDE or standalone application that only accepts certain kinds of input or has an overly-complicated API relative to the simplicity of this task.
CSV (or text or sqlite database) would provide a way for me to self-generate "candidate lists" or "history logs" and then just use those logs as the source of the possible completions.
The disclaimer
I've tried several GUI "launcher" programs, command-line engines like power-shell and scripting shells, the regular plain old command-line history with varying degrees of satisfaction. The problem with these is they all do extra superfluous stuff like searching directories or built-in commands. I just want nothing but whatever is in the CSV file I happen to be pointing at.
I'm wondering if there is any simple tool that does nothing but what I'm describing above.
UPDATE: It looks like this question is very closely related to Graphical Command Shell, which captures the essential idea presented here.
You should really try Launchy - it's exactly what you're looking for, a "run anything" with intelligent autocompletion. It completely changes the way you interact with a Windows PC.
And it has open source-code, so you can borrow its autocompletion code if you want to roll your own interface.

Resources