Can't rotate in pdftk - shell

I am following the online instructions and trying to rotate all pages of a PDFs 90 degrees clockwise like so
pdftk in.pdf cat 1E output out.pdf
But then I get the following error
Error: Unexpected text in page range end, here:
1
Exiting.
Acceptable keywords, for example: "even" or "odd".
To rotate pages, use: "north" "south" "east"
"west" "left" "right" or "down"
Errors encountered. No output created.
Done. Input errors, so no output created.
I can't imagine what I'm doing wrong

The compass direction should be given in full (EAST rather than E).
To rotate the first page:
pdftk t/helloworld.pdf cat 1EAST output out.pdf
To rotate all pages (page range 1-end):
pdftk t/helloworld.pdf cat 1-endEAST output out.pdf

Related

xmgrace: changing color of the XY graph in batch execution

I am using gracebat integrated into my bash script to make simple XY graph from 2D numerical data
gracebat input.xvg -hdevice PNG -fixed 800 600 -world 0 0.02 610 0.5 -printfile output.png -hardcopy
This simple execution without GUI produces the XY graph totally in black color!
would it be possible to quickly change to color of the line (I guess should be s0 color in the batch file) without using batch file for gracebat: e.g. via some option of gracebat or alternatively via editing of the input.xvg (via sed or any shell utility) specifying color or the line:
# s0 line color 2
Alternatively, if the grace has not good possibilities for graph customization, I would be grateful for simple example of the gnuplot batch execution.
What does xmgrace -help say? Please check the corresponding manuals and homepages and do a search on SO and the web before asking such questions. I don't now xmgrace and its documentation.
But a gnuplot command line would be using the command line option -e: (check help command line options).
gnuplot -e "set term pngcairo size 800,600; set output 'myFile.png'; plot 'myFile.dat' u 1:2 w l lc 'red' "

Insert image in RMarkdown bash code using RStudio 1.4

I am trying to create a bash script that loops trough a folder and prints all images.
However the line that should print the image actually doesn't print the image it self, it just prints the text.
```{bash echo=FALSE, comment=""}
echo "![$name]($dir/$file)";
```
Example output:
[dog][images/dog.jpg]
What i want is the actual image of the dog:
Add results="asis" to your document.
```{bash echo=FALSE, comment="", results="asis"}
echo "![$name]($dir/$file)";
```
See more at https://bookdown.org/yihui/rmarkdown-cookbook/results-asis.html
(BTW, on my rendering, without results="asis", I see
![](./1RfMf.jpg)
In your output the bang ! is missing.)

Is there a way to position new text within an existing pdf keeping such that it's editable after?

I want to create a pdf with pictures and text formatted a certain way — they all have to be arbitrarily positioned. I want to create such pdf on the server with terminal commands.
As I searched for the solution, I didn't find one. So I compiled some ideas to solve the problem; however, I still looking for a more direct one. I used the postscript compiler ENSCRIPT as a filter and then created a pdf by using the PS2PDF tool. Then I used the PDFJAM tool to position text in arbitrary position within the existing pdf. The following is the code I use to produce such a document. Although even this solution would help people who have the same problem, I welcome your suggestions of more efficient ways to handle this.
#!/bin/bash
# the following creates PDF with text
# options:
# -B — no header
# -f — font family and size
# --columns — make text grouped in columns
# -o - — to pass output
echo "Quick brown fox jumps over the lazy dog" | \
enscript -B -f "Times-Roman12" --columns=5 -o - | \
ps2pdf - pdf_with_text.pdf
# the following tool creates pdf_with_text-pdfjam.pdf from the pdf_with_text.pdf moving it in the exact position of the page
# options:
# -q — quiet mode
# --scale — scaling pdf_with_text.pdf if you need that
# --paper — resulting paper type
# --landscape — resulting paper orientation
# --offset — the most important part, set the offset of the top left corner of the source document in the resulting document. 0,0 point is in the middle (weird!)
pdfjam -q --scale 0.20 pdf_with_text.pdf --paper letter \
--landscape --offset "2cm -3cm"
# then we combine a new document and the existing one:
pdftk ./existing.pdf stamp pdf_with_text-pdfjam.pdf output new_combined.pdf
=========================
I got the combined pdf:
new_combined.pdf
with the text, I echoed in the first string, with the applied offset from the middle of the page.

Ghostscript: How can I move/scale eps content on target image?

I want to create a png file from an eps file with ghostscript. But I want to put it on a bigger image and control exactly where and how big (this means, I want to scale and move it).
I assume, that one should add some postscript commands in a "-c" argument to ghostscript.
I tried arguments like -c " 0.8 0.8 scale " and -c " 1 1 moveto ".
But in this case no png file was created, without other error message.
My question: what is the proper way to do this?
Example command used by me:
gswin32c.exe -dPARANOIDSAFER -r288 -dDEVICEHEIGHTPOINTS=195 -dDEVICEWIDTHPOINTS=256 -c " 1 1 moveto " -sDEVICE=png16m -o "testout.png" "input.EPS"
You need to read the Adobe EPSF specification
especially Section 2.6 "Graphics state". You will need to use scale as you suggest, and moveto. Note that 1 1 moveto moves the current point by 1/72 of an inch, so likely you won't be able to see any difference. Although you have used a -c switch to introduce PostScript, you haven't followed it with a -f to revert back to command line processing.
Try:
gswin32c.exe -sDEVICE=png16m -r288 -dDEVICEHEIGHTPOINTS=195 -dDEVICEWIDTHPOINTS=256 -sOutputFile="testout.png" -c "72 72 moveto" -f "input.EPS"
That should move the rendered image up and right by one inch each which you should be able to see. Using -sOutputFile rather than -o is in case you get something back on stdout. -o implies -dBATCH and -dNOPAUSE.

Gnuplot: One plot per file

I'm trying to plot the 1st and 3rd columns of multiple files, where each file is supposed to be plotted to an own output.png.
My files have the following names:
VIB2--135--398.6241
VIB2--136--408.3192
VIB2--137--411.3725
...
The first number in the file name is an integer, which ranges from 135-162. The second number is just a decimal number and there is no regular spacing between the values.
Basically I want to do something like this
plot for [a=135:162] 'VIB2--'.a.'--*' u 1:3 w l
although this doesn't work, of course, since the ' * ' is just the placeholder I know from bash and I don't know, if there is something similar in gnuplot.
Furthermore, each of the files should be, as already said above, plotted to its own output.png, where the two numbers should be in the output name, e.g. VIB2--135--398.6241.png.
I tried to come up with a bash script for this, like (edited):
#!/bin/bash
for file in *
do
gnuplot < $file
set xtics 1
set xtics rotate
set terminal png size 1920,1080 enhanced
set output $file.png
plot "$file" u 1:3 w l
done
but I still get
gnuplot> 1 14 -0.05
^
line 0: invalid command
gnuplot> 2 14 0.01
^
line 0: invalid command
...
which are actually the numbers from my input file. So gnuplot thinks, that the numbers I want to plot are commands... ?? Also, when the end of the file is reached, I get the following error message
#PLOT 1
plot: an unrecognized command `0x20' was encountered in the input
plot: the input file `VIB2--162--496.0271' could not be parsed
I've seen a few questions similar to mine, but the solutions didn't really work for me and I cannot add a comment, since I do not have the reputation.
Please help me with this.
gnuplot < $file starts gnuplot and feeds it the content of $file as input. That means gnuplot will now try to execute the commands in the data file which doesn't work.
What you want is a "here document":
gnuplot <<EOF
set xtics 1
set xtics rotate
set terminal png size 1920,1080 enhanced
set output $file.png
plot "$file" u 1:3 w l
EOF
What this does is: The shell reads the text up to the line with solemn EOF, replaces all variables, puts that into a temporary file and then starts gnuplot feeding it the temporary file as input.
Be careful that the file names don't contain spaces, or set output $file.png will not work. To be safe, you should probably use set output "$file.png" but my gnuplot is a bit rusty.

Resources