Does CUPS have properties for "margins"? - cups

I cannot find what properties of CUPS must be used, for printer margins, left/top/etc. Maybe CUPS dont support margins at all? I wanted to add margins support to Lazarus CUPS code.

Not sure if I understand your question correctly...
Note, that the support of controlling margins on the printed paper is dependent on the file type you submit for printing. This may not be supported for the one you want to print!
Assuming you print a TEXT document, here are the controls offered by CUPS lp command to submit the document as a print job to a CUPS printer with a custom page appearance:
lp \
-h cupsserver \
-d printername \
-o cpi=11 \
-o lpi=4 \
-o page-bottom=36 \
-o page-top=72 \
-o page-left=100 \
-o page-right=6 \
textfile.txt
The '-h cupsserver' part is optional and can be skipped if the queue is defined on your localhost. The 'cpi' parameter (characters per inch) determines the width of each character on a line. 'lpi' (lines per inch) works similar. 'page-top/bottom/right/left' is the margin in PostScript points. (72 points are one inch.)
If you submit a PDF file instead of text (which is a format that already internally has cast its page properties, including margins, into its code), the following should work, but I haven't tested it:
lp \
-h cupsserver \
-d printername \
-o fitplot=true \
-o page-bottom=36 \
-o page-top=72 \
-o page-left=100 \
-o page-right=6 \
pdffile.pdf
This should attempt to scale the page contents, but will probably scale more than you expect since it cannot do a "fluid" scaling to respect all the wanted borders (only a "preserve original page ratio" scaling).

Related

I need to pass json-data to api with special characters

I am trying to push some data to my Tiddlywiki via api so I can create a new tiddler.
I can pass almost all the data, but if the value "text" has spaces inside it breaks the curl command trying to pass multiple urls.
This is the actual command:
curl -X PUT -i "http://192.168.1.166:8080/recipes/default/tiddlers/$title" -H "X-Requested-With: TiddlyWiki" --data $(jq -nc --arg tags "$tag" --arg text "'${content}'" '{ $tags, $text }')
I tried at first using $variables, inside brackets, even inside multiple "'"$var"'" following others questions here. But most of them quickly recommended using jq so I gave it a try.
I learned how to create some keys with the bash¡s variables contents, and If I pipe all of this I can get it to work only if I replace spaces with other characters...I tried %20 or scaping the space \ with sed whitout success. (%20 is replaced literally so not helpful)
Any recommendations at all, I will follow any other path you could bring to it.
Thanks.
EDIT:
I tried using --data-urlencode "text=${var}" but it wasnt filled, only variable expanded was the title. The others didnt show at all.
API'S INFO:
https://tiddlywiki.com/static/WebServer%2520API%253A%2520Put%2520Tiddler.html
I forgot to mention that I am using zsh shell...
You need to quote the output of the command substitution: --data "$(jq ...)". Without this, curl thinks the words after the first one are individual URLs to connect to. You should also remove the single quotes from --arg text "'${content}'", otherwise they'll be added to the text itself.

tmux send-keys swallows spaces

Synopsis: "tmux send-keys" strips the spaces from a bash command and I don't understand why (or how, really.)
test ()
{
tmux new -s testsession -d
tmux send-keys -t testsession "time tar -I \"zstd -19 -T0\" -cvf ${1}.tar.zst "${#:2}""
tmux attach -t testsession
}
with an input of
input1 input2 input3 i\ n\ p\ u\ t\ 4
Expected (and desired) output is
time tar -I "zstd -19 -T0" -cvf input1.tar.zst "input2" "input3" "i n
p u t 4"
Instead I get
time tar -I "zstd -19 -T0" -cvf input1.tar.zst "input2input3input4"
Note I have omitted the ; C-m or ; ENTER at the end of the send-keys. (And I've also simplified the original function since other parts are more straightforward and work.) I've done that to get a more precise understanding of what is outputted on the terminal during several hours spent last night trying to brute-force the 'correct' syntax (, to no avail.)
I stumbled over the same problem and I found the not-so-nice solution of adding the keyword, "Space", for the spaces.
So, in your case, I would expect following command to work:
tmux send-keys -t testsession "time Space tar Space -I Space \"zstd Space -19 Space -T0\" Space -cvf Space ${1}.tar.zst Space "${#:2}""
I got this idea from this page's send-keys description "list of Keys" section.

How to use make file functions with $# to generate prerequisites?

I want to extract the name of a prerequisite from the target.
TARS= zabc zbcd zcde zdef
# and I want abc.o to be a prerequisite for zabc
$(TARS): $(patsubst z%,%.o,$#) z.c
gcc -c -o $# $^
However, this is not working.
Consider the following:
TARS= zabc zbcd zcde zdef
# and I want abc.o to be a prerequisite for zabc
$(TARS): $(patsubst z%,%.o,zabc) z.c
gcc -c -o $# $^
Ignore the TARS in above code but this works for make zabc.
So I want to know how to use $# as an argument in the function for getting the prerequisite name.
The short answer is, you can't. Automatic variables, as made clear in the documentation, are only set inside the recipe of a rule, not when expanding the prerequisites. There are advanced features you can take advantage of to work around this, but they are intended only to be used in very complicated situations which this isn't, really.
What you want to do is exactly what pattern rules were created to support:
all: $(TARS)
z%: z%.o z.c
gcc -c -o $# $^
That's all you need.
ETA
GNU make doesn't provide any completion capabilities, so you'll need to figure out where that completion is done and how it works, to know what you need to have in your makefile to have it work. If it only completes on explicit targets, you can either just make them like this:
all: $(TARS)
$(TARS):
z%: z%.o z.c
gcc -c -o $# $^
Or you can use static pattern rules instead:
all: $(TARS)
$(TARS): z%: z%.o z.c
gcc -c -o $# $^
I didn't understand the last sentence in your comment below.

GhostScript: Cropping multiple area of pdf in single reading?

I need to crop certain [multiple time with different area] area of pdf and save it as image. For that i am using the below commands in my windows system for ghostscript[9.5]:
"C:\Program Files\gs\gs9.50\bin\gswin64c.exe" ^
-dSAFER -dBATCH -dNOPAUSE ^
-dTextAlphaBits=4 -dGraphicsAlphaBits=4 ^
-dDEVICEWIDTHPOINTS=238 -dDEVICEHEIGHTPOINTS=149.5 ^
-dFIXEDMEDIA -r600 -dDownScaleFactor=2 -sDEVICE=jpeg -o out1.jpeg ^
-c "<</PageOffset [ -64.2 40 ]>> setpagedevice" ^
-sPDFPassword=01011977 ^
-f "E:\PDFs\ECC\PDF_AESTRO.pdf"
"C:\Program Files\gs\gs9.50\bin\gswin64c.exe" ^
-dSAFER -dBATCH -dNOPAUSE ^
-dTextAlphaBits=4 -dGraphicsAlphaBits=4 ^
-dDEVICEWIDTHPOINTS=238 -dDEVICEHEIGHTPOINTS=149.5 ^
-dFIXEDMEDIA -r600 -dDownScaleFactor=2 -sDEVICE=jpeg -o out2.jpeg ^
-c "<</PageOffset [ -308.5 40 ]>> setpagedevice" ^
-sPDFPassword=01011977 ^
-f "E:\PDFs\ECC\PDF_AESTRO.pdf"
the above command does their job and crops both part from that pdf.
But this is rendering the same pdf twice for that work and consuming the time and i want to save that time for faster processing as this will be used in firebase funciton for myweb app.
How can i crop both area to image in single reading of pdf?
To be blunt about it; you can't do what you are asking. To get the same file rendered differently you need to render it each different way you want it rendered.
In passing; you no longer need to specify -dSAFER (since the 9,50 release) because that's the default. If you specify -o (instead of -sOutputFile) as you have done, then you don't need -dBATCH or -dNOPAUSE, -o includes both of those.
Personally I wouldn't bother with the GraphicsAlphaBits or TextAlphaBits given that you are rendering to JPEG, but that's a matter of personal preference.

topojson makefile has no country data

I've been doing the d3 let's make a map tutorial and I'M SO CLOSE but something happened in merging the two json files because the final uk.json doesn't have the three letter country codes -- rendering my map useless because I can't assign a class to the subunits.
I read this from Mike Bostock that said topojson changed and to do this instead when creating the file:
topojson \
--id-property su_a3 \
-p name=NAME \
-p name \
-o topo/uk.json \
topo/subunits.json \
topo/places.json
which I ran in the Terminal but same output on the uk.json file. Any ideas? Do I need to make a subfolder within my directory called "topo"?
1. Working code: Quickly, I find in your code some diferences with mine. Try out this :
topojson \
--id-property su_a3 \
-p name=name \
-p name=NAME \
-o topo/uk.json \
-- topo/subunits.json \
topo/places.json
I'haven't test it however. The topo/... path is also a difference with my code.
2. Missing: A possibility is that you lost this property upper in your workflow. The GIS file's data attribute name may have changed, etc.
3. Case sensitive: Check that the keys you call in your TOPOJSON match the keys within your GIS / Geojson file. This is case sensitive. To check within the shp file : QuantumGIS* > load the .shp file > Right click on layer > Open attribute table > There, look at the column's title.
*: or other GIS software
I had the same issue, although after a while I realized that the doc says
-p, --properties feature properties to preserve; no name preserves all properties
So if you use -p without anything else, something like
topojson --id-property SU_A3 -p -o yourjson.json -- subunits.json places.json
you will get all the features and you will be able to retrieve whatever field you want. I don't know how is that if you only want to map some attributes (I was having the same issue)
Anyway, hope this help