I create png graphs using xmgrace via the bash script working from the terminal w/o gui:
gracebat *.xvg -hdevice PNG -fixed 400 260 -printfile *.png -hardcopy
could you suggest me commands (or alternatively a script for the batch mode) which will customize the output graphs? In particular, I would like to increase the size and the font along the XY axes and customize the legend.
If xmgrace is not a good editor, could you suggest me another command-line utility for linux with better options for the graphs visualization?
Thank you!
In addition to grace batch files, you have a few more (non mutually exclusive) options:
You can use a custom Default.agr (see here for an example) to improve the visual appearance of your plots out-of-the-box
You can use parameter files: create a plot (with legend and all) and use the "Load -> Save parameters..." menu option to save a parameter file. From bash, use the -param switch to use that parameter file with other sets of data (e.g. gracebat *.xvg -param myparams.par -hdevice PNG -fixed 400 260 -printfile *.png -hardcopy).
You can use (or write) a utility program to automatically edit .agr files (which are plain text files). A really nice one is pygrace. With pygrace you can easily write python scripts that generate or edit agr files in a very straightforward way.
Related
I'm downloading some newspapers as pdf (for posterity). One title is a pain, it includes URI links in the pdf itself, if you accidentally click these it opens a browser tab to a page that 500s. It's not so bad on a desktop computer, but a pain in the butt if someone is reading it with a tablet. Each issues has approximately 200 of these links.
For a different title, it was as simple as using QPDF, like so:
qpdf --qdf --object-streams=disable file temp-file
This puts the temp version into postscript mode or something, and I was able to nuke the links with something like this:
s/obj\n<<\n( \/A <<\n \/S \/URI.+?)>>\nendobj/"obj\n<<\n" . " " x length($1). ">>\nendobj"/sge
This still works. However, a 15 meg original pdf is now becoming a 108meg "fixed" pdf. I can accept some bloat, but 720% is a bit absurd (I think it was more like 10% on the other title). Whenever I google for how to do this, I get results for Acrobat Reader and how you can click around in 20 menus to do such... does no one that uses Adobe products ever want to automate this stuff? There are between 180 and 300 links in a typical issue, spread across 45-150 pages (Sunday editions).
Are there any tools that can do this? Are there any clever arguments to qpdf that will make this more reasonable?
PS Yes I know it's hacky as hell to just overwrite the URIs with spaces, but I've never managed to figure out how to remove the objects entirely since their references also have to be removed.
You can do this with the community edition of cpdf: https://community.coherentpdf.com/
To remove all links in a PDF (well, to replace them with an empty link):
cpdf -replace-dict-entry /URI cpdfmanual.pdf -replace-dict-entry-value '""' -o out.pdf
This does not remove the annotations - it just makes sure that clicking on them won't go anywhere. It leaves the annotation in place, but with an empty link. You could replace with a working URL too, of course:
cpdf -replace-dict-entry /URI cpdfmanual.pdf -replace-dict-entry-value '"https://www.google.com/"' -o out.pdf
(You can also use -replace-dict-entry-search to replace only certain URLs - see the manual.)
Or, if you just want rid of all the annotations (link and non-link):
cpdf -remove-annotations in.pdf -o out.pdf
You can use HexaPDF (you need to have Ruby installed and then use gem install hexapdf to install HexaPDF) and the following small script to remove the links:
require 'hexapdf'
HexaPDF::Document.open(ARGV[0]) do |doc|
doc.pages.each do |page|
page.each_annotation.select {|annot| annot[:Subtype] == :Link}.each do |annot|
page[:Annots].delete(annot)
end
end
doc.write(ARGV[0] + '_processed.pdf', optimize: true)
end
Then batch execute the script for all the files you want the links removed.
Note that this will remove all links.
Just to round off the options I would suggest the best is potentially a PDF dedicated command line tool such as cpdf answer by johnwhitington or a dedicated library like iText.
There are several alternative methods touted for batch text editing your using qpdf
"temp version into postscript mode or something,"
That is a converted pdf into plain old decompressed text/pdf hybrid qdf so you can run sed or similar string editor. Here the primary difference is the upper out.pdf file shows as an editable QDF-1.0 version after editing so needs conversion to a conventional PDF as seen in the lower part where the stream is binary thus recompressed.
1) qpdf
At end of a bloating edit exercise the idea is to reverse back to application/pdf using
fix-qdf file-temp.pdf>out.pdf
to tidy up redirects and then
qpdf --compress-streams=y out.pdf outfixed.pdf
back to fixed.pdf
Other cross platform means are using
2) pdftk
$ pdftk infile.pdf output outfile.pdf uncompress
edit with vim or whatever sed scripting method then
$ pdftk outfile.pdf output fixedfile.pdf compress
3) mutool
mutool clean -d [options] input.pdf [output.pdf] [pages]
-d Decompress streams. This will make the output file larger, but provides easy access for reading and editing the contents with a text editor.
-i Toggle decompression of image streams. Use in conjunction with -d to leave images compressed.
-f Toggle decompression of font streams. Use in conjunction with -d to leave fonts compressed.
-a ASCII Hex encode binary streams. Use in conjunction with -d and -i or -f to ensure that although the images and/or fonts are compressed, the resulting file can still be viewed and edited with a text editor.
Whichever options you use, need to be reversed when recompressing
NOTE
Using text editors will potentially corrupt binary fonts and binary images, thus they need monitoring for any corruption in an editor that changes encoding or line feeds. This pdftk sample shows the image stream has been decompressed well into simple text but beware any change of End Of Line by editor would break up that stream
Additionally when making text edits that are not simple byte wise "find and replace", the xref table can be corrupted too much to be reindexed by recompression, try to overwrite with same number of characters when using a text edit method.
SIDE NOTE
EVEN if you remove actions and external hyperlinks actions but the text is present the reader will still provide that exploitable action. Same as here https://google.com but html will highlight usually in blue underline.
Hence ensure security is on
I'm trying to convert my existing asciidoc documentation into pdf. Asciidoctor-pdf seems quite easy and I'm able to convert single files into pdf.
asciidoctor-pdf -a pdf-theme='./theme/styles.yml' -a pdf-fontsdir='GEM_FONTS_DIR, theme/fonts/' 01-intro.adoc
But my docs are spread across many files. I want do create a single pdf from all those files. Does anyone know how to do this?
Secondly I don't want the generated pdf to be located next du the adoc file. I want to specify a target path.
I'd appreciate every hint. Thanks and best regards. Sebastian
(Dec 26, 2021)
The easiest and most convenient way is to use the VSCode editor with the AsciiDoc extension installed. This extension is developed by the same team that develops the AsciiDoctor text processor. This is a GUI-based approach to solve all your problems so I'm pretty sure u're gonna love it.
(Step 1) After the extension is installed, use the keyboard shortcut Cmd + , to go to the settings and then enter asciidoc.use_asciidoctorpdf in the search bar and tick the check box (see the demonstration below)
(Step 2) To create a single pdf file from multiple .adoc files, just simply put all of them in a single .adoc file with include::directory-to-the-adoc-file.adoc[] (see the illustration below)
(Step 3) Press F1, then type in as pdf and hit Enter to export this single .adoc file as a single PDF file, this will allow u to specify the target export directory for the PDF. Please be patient and wait for a few seconds for the export to complete, the editor will immediately inform u as soon as the export is complete (see the image at the bottom)
Have you considered to work with includes?
Just add to your document "01-intro.adoc" an any position this line:
include::02-next-file.adoc[]
When you build the 01-intro.adoc with your regular command, the contents of 02-next-file.adoc will be put to the position of the include line. Using this method we create a file with many includes and just build that file. We're very happy with that.
I am using xmgrace to plot several graphs on a shared axed, from a two-column data file like so:
# title "RMSD"
# xaxis label "Time (ns)"
# yaxis label "RMSD (nm)"
#TYPE xy
# subtitle "C-alpha after lsq fit to C-alpha"
1.7125001 0.0005074
1.7225001 0.0635904
1.7325001 0.0747008
1.7425001 0.0707590
1.7525001 0.0821623
1.7625000 0.0842335
1.7725000 0.0929994
1.7825000 0.0938834
1.7925001 0.1014052
1.8025001 0.1107717
1.8125001 0.1106072
1.8225001 0.1032858
1.8325001 0.0967231
1.8425001 0.1072746
So, I call the command to show me all graphs on the GUI
xmgrace 1.xvg rmsd_amber_2.xvg rmsd_3.xvg
Is it possible to automatically use the filenames as the labels for the legend, using an option found within the GUI of xmgrace? So far xmgrace automatically uses different line colors for each data series, but does not show the filename as the data label.
If this is not possible, please suggest me another GUI software for Linux which is able to open xvg files from the terminal for its visualization "on the fly".
Thanks !
Xmgrace does not do what you want
The xmgrace help (shown by calling xmgrace --help at the terminal) shows that there is no command line flag to specify data set legend titles. If that were the case you could probably come up with some bash commands to parse the title from your data files.
But there is another way
As an alternative, you can load a parameters file containing the correct titles. If you save any parameters file from within the xmgrace GUI and load it in a text editor, you will see that almost every aspect of Plot, Graph and Set appearance properties can be controlled.
However, it is not all needed; we can delete almost all of that information and just keep the lines related to our data set legend titles (everything else will just take the default values).
Solution
A minimal parameter file "template.par" might contain just the following four lines:
with g0
s0 legend "title0"
s1 legend "title1"
s2 legend "title2"
where in your case "title1" would be "RMSD".
You can then use xmgrace -param template.par 1.xvg rmsd_amber_2.xvg rmsd_3.xvg to create the plot.
Automating it
So far so good, but you want to create template.par automatically by parsing your chosen bunch of .xvg files. You could probably achieve this in any number of different ways using a bash script or even a bash one-liner.
how can I export an image of the area of the plot by code?
I'm using Netlogo 5.0.5.
I'm tring to reproduce the comand "copy image" of menu right-button of the mouse in the area-plot in tag "Interface".
There is no primitive to export a plot as an image in NetLogo, which is admittedly a hole in the language. It would be fairly simple to write an extension to do that, but as far as I know, none exists.
That leaves you with two alternatives:
Use export-plot, which will give you a CSV file, and recreate your plot using some other tool (e.g., Gnuplot). This is more work, but it has the advantage of giving you better quality output in the end, NetLogo plots being kind of bitmappy anyway...
Use export-interface to export the whole NetLogo interface tab as an image, and then crop the resulting picture to keep only your plot. If you use a command-line tool like ImageMagick, this can be fully automated.
In both cases, you could try calling the external program that you choose directly from NetLogo by using the Shell extension.
Does anyone knows how to extract the characters image from a font(ttf) file?
TTF is a vector format, so there are no characters shapes, really. Load the font, select it into a device context (a memory one), render a character, grab a bitmap.
Relevant APIs: AddFontResource, CreateFont, CreateDC, CreateBitmap, SelectObject, TextOut (or DrawText).
You can use GetGlyphOutline with GGO_BEZIER to get the shape of a single character.
For the sake of completeness I'd like to add a GUI and Python way to this pretty old thread.
If the goal is to extract images (as e.g. png) from a .ttf file I found two pretty straight forward ways which both involve the open-source program fontforge (Link to their website):
GUI Way (Suitable for extracting a handful of characters): Open the .ttf file in fontforge click on the character you want to export. Then: file -> export -> format:png
CLI / Python Way (Suitable for automation): FontForge has a cli api for python 2.7 which allows to automate the extraction of the images. Refer to this superuser thread for a complete script.
Link 1: https://fontforge.org/en-US/
Link 2: https://superuser.com/questions/1337567/how-do-i-convert-a-ttf-into-individual-png-character-images