executing a Linux command from PDF file in a PDF viewer - pdf

Is it possible to execute a Linux command from a PDF file shown in a PDF viewer?
More specific: I generate PDF files from LaTeX using pdflatex. What I would like to do is to include some symbol or text in the PDF file which starts a Linux command when the user clicks on it. Typically I'm using evince to show PDF files.
I'm not sure whether it is at all possible to execute commands from PDF files in a viewer, and if it is possible, which packages and LaTeX commands would be required to include the symbol or text and the associated command in the PDF file?
(Alternatively, is there at least a way to obtain the number of the current page shown in the PDF viewer? That would help to some extent.)
Thanks a lot!

Unfortunately and rather fortunately you cant do that.The pdf standard doesnt allow to run shell scripts. That would be a HUGE security oversight.

Related

Add link to PDF within a PDF file using relative addressing

I want to add a link to some text within a PDF that will bring up another PDF that is located in the same folder. I wish to use relative addressing so that the PDF suite is transportable to other users and computers. I wish this to work on Linux and Macs.
LibreOffice Draw, despite promises, writes out the link address as a full path. Thus if taken to another computer with another user the link fails to work.
I tried manually editing the PDF files using vi and altered the link syntax so;
<</Type/Annot/Subtype/Link/Border[0 0 0]/Rect[940.9 480.3 1200.7 507.9]/A<</Type/Action/S/URI/URI(Content/Information.pdf)>>
where the target file, "Information.pdf" is in a subdirectory "Contents".
On Linux using Document Viewer, it works! On an Apple, Preview (a PDF viewer) interprets the target file needs to be opened by some application. Adobe Reader doesn't like this syntax either. I tried prefixing the filename with the keyword "file:" which works for a full path but not with relative addressing.
Does anyone know what syntax might work for me
Editing a PDF you can select text and add a hyperlink using LibreOffice Draw. It is then possible to edit the PDF file with a text editor such as vi.
To find the line with the link search for the filename of the target. One problem is that LibreOffice insists in using a fully qualified domain name to locate the file and this won't work after the file is moved, say to another computer. The unedited line should be similar to;
<</Type/Annot/Subtype/Link/Border[0 0 0]/Rect[940.9 480.3 1200.7 507.9]/A<</Type/Action/S/URI/URI(File:<fullpathname>/Content/Information.pdf)>>
Where Content/Information.pdf is the link target in the same directory as the linking pdf. This line should be changed to
<</Type/Annot/Subtype/Link/Border[0 0 0]/Rect[940.9 480.3 1200.7 507.9]/A<</Type/Action/S /Launch/F(Content/Information.pdf)>>
This works on Unix and MacOs

inkscape: multiple page pdf to multiple png

when I convert pdf to image in linux command line, it seems inkscape gets the best result (better quality than gs with same dpi). Unfortunately, it only converts the first page to png. How to convert every pdf page to different png file? Do I have to extract one PDF page and store to a new pdf file , then do inkscape concert, and so on?
This isn't solely using Inkscape, but you could use e.g. pdftk to split up the pdf-file into separate pages and convert every page into a png with Inkscape. For example, like this:
pdftk file.pdf burst;
l=$(ls pg_*.pdf)
for i in $l; do inkscape "$i" -z --export-dpi=300 --export-area-page --export-png="$i.png"; done
Note that pdftk burst creates pdf-files called pg_0001.pdf, etc., so if you have any files named like that, they'll be overwritten. You can remove them afterwards easily using
rm pg_*.pdf
Lu Kas' answer threw warnings for me without doing the conversion. Probably because I'm running Inkscape 1.1
However, i got it running by replacing some deprecated commands:
inkscape pdfFile.pdf --export-dpi=300 --export-area-page --export-filename=imageFile.png;
For batch processing rather than slowly looping through file by file inkscape has a shell mode for command file scripting. See https://wiki.inkscape.org/wiki/index.php/Using_the_Command_Line#Shell_mode
However like all other #file.txt scripts you need to write a custom text file. and for Windows users run against higher ranking inkscape.com not .exe
Since version 1.0 (currently 1.2) a multipage pdf of contents can be addressed for multiple outputs. for some other examples see https://inkscape.org/doc/inkscape-man.html#EXAMPLES
Commands get replaced over time so currently to export png use --export-type="xxx" to batch export a list of input files to type xxx. Thus in this case --export-type="png"
Also for pdf related inputs and support see https://wiki.inkscape.org/wiki/index.php/Using_the_Command_Line#New_options
For windows users there is a handy batchfile converter here https://gist.github.com/JohannesDeml/779b29128cdd7f216ab5000466404f11

Convert "print to file" PRN file to PS

I spend almost day trying to understand how to convert "print to file" PRN file to PS or PDF file. The PRN file is in PCL format and while looking on google I found that GhostPCL should do conversion job using command line
gpcl6win64.exe -dNOPAUSE -sDEVICE=ps2write -sOutputFile="c:\output.ps" "c:\input.prn"
Unfortunately that I get is binary data from PRN file is moved to ps/pdf file without rendering anything useful only garbage symbols.
Any idea how to convert PRN PCL files to PS or PDF?
I am using the newest version of GhostPCL 9.23 for Win64.
I also attaching test files.
input.prn - the print to file PCL.
output.ps - the PostScript file created using command line above with ps2write. Bad result.
output.pdf - the PDF file created using command line above with pdfwrite. Bad result.
output-correct.pdf - The PDF file created using one of online converters. Produce correct output but looking at PDF metadata it seems it is using GPL Ghostscript 9.19.
The command line you specify will create a PostScript program from the PCL input. I don't understand what you mean by:
binary data from PRN file is moved to ps/pdf file without rendering
anything
The process won't render anything it will produce a PostScript file. Note you can create a PDF file instead by using the pdfwrite device.
Perhaps if you shared an example of the input and output files it might be possible to say more. It would also be helpful to see the entire transcript of the back channel output. If nothing else it would contain the version of GhostPCL being used, which would be helpful to know.
[Edit after files supplied]
I've no idea what led you to believe your file was a PCL file, but it isn't.
The 'PRN' file turns out not to be a PCL file at all. Its an XPS file.
Unsurprisingly, when you run this through the PCL interpreter it doesn't know what to make of it. PCL interpreters treat anything they don't understand as 'text' and try to print it as such. Which is why the content of your PDF begins with 'PK'. XPS files are zip archives, and PK is the signature for a zip archive.
If you use GhostXPS instead it will read the file properly. Or, since this is presumably on Windows 10, you could just save it direct to a PDF file if that's what you want.
Add a Microsoft PS Class Driver printer on a local port FILE:. Make sure that its Print Processor is set to winprint/RAW.

some markdown files into one pdf document

I have approximately 20 files in markdown type and I need to convert those into one pdf document. I try using online converter, but the images are not showing, it just like ![alt text](image.png)
Using Calibre app also not showing images.
Btw, I am using Gitbook to generate my markdown and html view, I read the documentation about how to convert into pdf using gitbook pdfin command line, but it returns TypeError
Does anyone know how to solve this? I am using Windows 10
Hi you can use the Pandoc tool (it runs on Windows/MacOS/Linux).
It is an command line tool which can easily convert your Markdown file into PDF (or other kind of format).
Take a look to Pandoc website
Maybe you will have to install a LaTeX environnement like Miktex in order to convet into PDF.
An example from Pandoc documentation :
From markdown to PDF:
pandoc myInput.md --latex-engine=xelatex -o myOutput.pdf
Furthermore, there is several interesting options if you want to generate a table of contents in your output for instance.

Using Texmaker, I want to lock the PDF file created so others cannot copy text or print the file

I'm creating PDFs using Texmaker. I would like to create some of the PDF files so that when I give the PDF to others, they are not able to print the file or to copy the text. I know I can do this with some PDF creator applications, but can I do that from some command like program I have with Latex, MikTex and TexMaker?
It wouldn't be effective anyway. There are bits in the pdf format that purport to forbid the user from doing this, but they are really just suggestions that the reader application may or may not act on. There is nothing to stop a user from removing the code that inspects the bits from a free/libre PDF reader, or just to run a tool over the file to remove the restrictions.