How to take snapshot of PDF file in linux? - linux

How I can take snapshot of first page of PDF file in Linux? I wanna do this on VPS server automaticaly. My distribution is Debian.

ImageMagick can convert PDF pages if you have Ghostscript installed.

You can do this with PDFTK. It's available in the Ubuntu repos, so check there first.
The syntax you'll want to grab the first page is:
$ pdftk input.pdf cat 1 output out.pdf

Press & Hold SHIFT + Print_screen KEYS and with mouse select the rectangle of pdf page you want to take screenshot ...

Related

How to cut last page from PDF on linux server

I've more than 500 PDF files stored on linux server with 5 pages each. I want only first 4 pages in each file. Is there any way to cut last page from all 500 PDF pages on linux ?
You can us the tool pdftk (need to be installed)
To only have page 1-4 from the in.pdf in your out.pdf file you have to type
pdftk in.pdf cat 1-4 output out.pdf
pdftk is a very powerfull tool, which can do a number of pdf manipulations. Have a look at the man page. At the end of the man pages are some examples of the most common tasks.

How do you print a multipage tiff file using CUPS (lp command)?

On Linux system (Ubuntu) I have a multipage TIFF file (file.tiff).
When I send it to a printer using "lp file.tiff" command, only the first page prints.
How do I print all the pages?
I have the following known options:
Split the file to single-page TIFFs
Convert TIFF to PDF
I'd like to keep the multi-page TIFF and avoid creating other formats. Is there a way to make CUPS print all the pages from the multipage TIFF file?
(Please do not offer "convert the file" as an answer as I know those, I'm looking for a CUPS method, lpprintmultipagetiff --please?).
Use tiff2ps. The link is below. You could also setup a dirty loop to print each page manually with cups.
for((i=1;i<=884;i++)); do <your lpr print command>; done
Note: 884 is the last page number... I'm just guessing. Use $i in your lpr print command when printing the desired page.
http://linux.about.com/library/cmd/blcmdl1_tiff2ps.htm

Ghoscript /cropbox not printing correctly in linux

I'm using the Domestic shipping label api in usps to generate domestic shipping labels in pdf format. I managed to crop the top section of the pdf file which is the label needed by the usps and Ignored the bottom section which is the receipt which is not needed in shipping.
I use Ghostscript /Cropbox to crop the section that I only want which is successful but when I try to print the cropped pdf file in linux cups I get the whole uncropped pdf printed instead of the cropped pdf file. Why is it still printing the whole file instead of just printing the cropped section?.
Here's the script I'm using to crop the usps Shipping label.
gs -o cropped.pdf -sDEVICE=pdfwrite -c "[/CropBox [50.4 460.5 484.4 750.5] /PAGES pdfmark" -f uncropped.pdf
Then to change its orientation to portrait i use pdftk
pdftk cropped.pdf cat 1L output cropped_portrait.pdf
To print it in linux cups I'm using the command.
lp cropped_portrait.pdf
But when i print it it is printing the uncropped.pdf file instead of cropped_portrait.pdf.
Why is it doing that? I even deleted uncropped.pdf and tried printing again but it still prints uncropped.pdf.
Here's the two files the uncropped and cropped usps shipping labels.
Uncropped PDF file
Cropped PDF file
Hope you can help me on this one,
Thank you
Presumably the reduced PDF file displays correctly, so there is no problem with Ghostscript producing the PDF file.
As to why the printing process doesn't respect the CropBox, there is no reason really why it should. There are many Boxes in PDF and no real way for a print application to know which one you want to use. As a result printing applications often default to the MediaBox, which you haven't altered (Note that altering the CropBox doesn't change the content of the PDF file, just what is displayed).
Now, if your CUPS chain is using Ghostscript to render the PDF file, or convert it to PostScript, then this can be solved, you need to add -dUseCropBox to the command line. However I'm not a CUPS expert so I can't tell you how to do that. If CUPS isn't using Ghostscript then its probably still possible to instruct whatever is doing the conversion to use the CropBox, but you're going to have to find out what application is involved and alter the command appropriately for that application.

Add margin to PDF file when merging using PDFTK or similar

I have a large collection of half-page sized PDF cut-sheets that are held in a folder on my Linux server. A user to the site will want to create a booklet from a subset of these. The booklet will be bound therefore the even pages of the collection will want more margin on the right side and the odd pages will want more margin on the left side. There can be up to 200 pages in a collection out of a universe of 500 pages so I don't want to regenerate each page to set the margin of it. It would take too much of the servers time to run the content through the DOMPDF. Just building the document using PDFTK is fast.
I'd like to merge the document with PDFTK from a centered PDF file and add the appropriate margin for the odd or even page.
If not PDFTK then is there another tool that might do the job?
If you use ubuntu, you can install pdfcrop:
sudo apt-get install -y pdfcrop
Despite its name, pdfcrop has the option to add margins:
pdfcrop --margin '29 0 29 0' input.pdf output.pdf
(Note: the unit is bp. 72 bp = 1 inch. 29 bp is approximately 1 cm.)
Then, use pdfjam to do the offset trick for the right and left pages.
pdfjam --twoside --offset '1cm 0cm' file.pdf
Note: pdfcrop does have problems with some pdf files. (!!! Error: Ghostscript exited with error code 139!).
If you are still interested in this, you should have a look at pdfjam which allows you to offset and clip pdfs. With respect to your particular question you might do something like
pdfjam --twoside --offset '2cm 0cm' file.pdf
This shifts the even pages 2cm to the right and the odd one to the left.
pdfjam is a front end to the pdfpages package of pdflatex.
Even if it is a bit late, but it might help someone. In response to #ElkeSpaak comment, it's the package texlive-extra-utils:
dpkg-query -S /usr/bin/pdfcrop
texlive-extra-utils: /usr/bin/pdfcrop

generate image (e.g. jpg) of a web page?

I want to create an image what a web page looks like,
e.g. create a small thumbnail of the html + images.
it does not have to be perfect (e.g. flash /javascript rendering).
I will call use the code on linux, ideally would be some java library, but a command line tool would be cool as well.
any ideas?
Try CutyCapt, a command-line utility. It uses Webkit for rendering and outputs in various formats (SVG, PNG, etc.).
you can get it nearly perfect, and cross platform too, by using a browser plugin.
FireShot or ScreenGrab for Firefox.
6 Google Chrome Screenshot Webpage Capture Extensions
BrowserShots is an open source project that may have some code you can use.
also see:
Command line program to create website screenshots (on Linux)
Convert web page to image
How to take screenshot of whole web page, rather than what shows on the screen
What is the best way to create a web page thumbnail?
Convert HTML to an image
To take a screenshot in the terminal with ImageMagick, type the following line into a terminal and then click-and-drag the mouse over a section of the screen:
import MyScreenshot.png
To capture the entire screen and after some delay and resize it, use the following command:
import -window root -resize 400×300 -delay 200 screenshot.png
You may use a mixture of xwininfo and import to retrieve the window id of the browser and make a screenshot of that window. A bash script to automate this process would be something like this:
#!/bin/bash
window_id=`xwininfo -tree -root | grep Mozilla | awk '{print $1}'`
import -window $window_id -resize 100x100 tumb.png
This script will create a 100x100 screenshot of Firefox on the current directory under the name tumb.png
Several sources show how to run a bash script from inside a Java application, google can help you on that. If you are in a hurry, check this and this.
After reading this page, I was thinking, let me fire up midori browser: http://midori-browser.org/ and when I tried the -h option, I have seen:
-s, --snapshot Take a snapshot of the specified URI
QutyCapt is difficult to compile, and has many dependencies. Midori has it less. It outputs the PNG of the website into TMP folder. One can get the file with:
midori -s http://www.rcdwealth.com new.png 2>/dev/null | awk '{ print $4}'
After that, the file can be converted to thumbnail size by using ImageMagick's convert program.
If you're interested in Java, maybe you could look at browser automation using Selenium-RC http://seleniumhq.com
It's a little java server that you can install on the box and the program itself will execute remote commands in a web browser.
Steps like (this is pseudo code by the way, I code my Selenium in php and I can't recall 100% of the specifics off the top of my head)
selenium.location("http://foo.com")
selenium.open("/folder/sub/bar.html")
selenium.captureScreenshot("/tmp/" + this.getClass().getName() + "."
+ testMethodName + ".png");
Actually, I just did a quick websearch for the exact syntax on that last one ... and this guy has a blog with what might actually be working code in java :)
https://dev.youdevise.com/YDBlog/index.php?title=capture_screenshots_of_selenium_browser_&more=1&c=1&tb=1&pb=1
There's also a number of websites that provide this service "cross browser and OS" I just can't recall what they are. Basically they've got a cloud of every single operating system and browser combination, and they log on with each machine, take a screen and store it on their site for you to come back to in a few hours when they're done.
Ahh... another websearch and it's yours :) http://browsershots.org/

Resources