If a pdf file is very old, using acroread, convert(print)  it to a ps file that can be opened with the emacs. For example, it is called "output.ps"

gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite --dCompatibilityLevel=1.3 sOutputFile=out.pdf  -c "[/CropBox [60 70 550 738] /PAGES pdfmark " -f output.ps

The letter size is   Pts (H 792 W 612) and  I want to crop left 60, right 62, top 54, bottom 70 pts.  So the CropBox option is

/CropBox [a b c d]

a = 60
b = 70
c = 612-62 = 550
d = 792-54 = 738


* References
http://www.prepressure.com/library/paper-sizes
http://stackoverflow.com/questions/6183479/cropping-a-pdf-using-ghostscript-9-01

* Note that unfortunately,  the Amazon kindle opens this modified pdf extremely slow.
저작자 표시 비영리 변경 금지
신고

'Computer > linux' 카테고리의 다른 글

create a thumbnail by command line  (0) 2011.09.27
Crop a pdf file to reduce a page margin in Linux  (0) 2011.06.23
email forward by using .forward  (0) 2011.06.05
Convert DOS to unix in emacs  (0) 2011.05.03
posted by citadel
When I learn more linux, I feel as if I am drinking icy cold Bohemian style beer on a roof. If you know a lot of "The Shawshank Redemption", you probably know what I mean.



The  corresponding video might be found on http://www.youtube.com/watch?v=w4oPFXWXaDE

The true Bohemian style beer is http://en.wikipedia.org/wiki/Pilsner_Urquell.

Extract each page from an electronic pdf or ps file in oder to edit or modifiy them. The ps file format has much better output result than pdf file.

gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=epswrite  -sOutputFile=result-%02d.eps test.ps

The related posts are
2007/08/15 - [computer/linux] - How to save each page of a pdf file to eps file
2006/12/06 - [computer/linux] - ghostscript를 사용해서 여러개 화일을 하나의 화일로 만들기 (pdf,eps, .....)



신고
posted by citadel
To fix  the wrong bounding box information in the eps files, I use the following method
2007/05/13 - [computer/linux] - How to create a stand alone eps file by using pstricks

However, whenever I fix problems, I have to do the same procedure. It was very cumbersome procedures. I decide to make a lazy program, which do the same thing automatically. Here my second python script :

more..fixBBox.py



The  http://akaihola.blogspot.com/2007/09/goodie-for-your-pdf-toolbox-automatic.html post helps me in order to understand Popen and re. The other references are in the source code.
Note that the above script might delete or destory your eps file. Before using it, please backup your file.

2008.3.28 One guest pointed out a bug in the above script as
Thanks for this great script. But there is a small bug in the regexp. The Bbox can also contain negative numbers, in which case the compiled regular expressions won't replace the BBox string.
To fix it replace in the syntax_* variables '[\d ]+' with '[\-\d ]+'
I really appreciate this comment since this is the first and unique feedback. However, the suggestion is not enough to apply the real eps file when I realize ghostscript does not reply the correct bounding box information even if I change the regular expressions.  I found the useful note (see page 18) : http://partners.adobe.com/public/developer/en/ps/5002.EPSF_Spec.pdf.

To fix these bug, I must redesign all python script. It also is a time-consuming work for me because I am not a professional programmer. Anyway, this is a sort of TODO list.

If you suffer from the negative bounding box informations, consult the adobe info booklet or try to understand the following differences. I think you will find the solution.

%%BoundingBox: -85 346 114 529
%%HiResBoundingBox: -85.509269 346.71008 113.18475 528.09641
%%EndComments
%%Page: 1 1
0 560 translate

%%BoundingBox: -85 346 114 529
%%HiResBoundingBox: -85.509269 346.71008 113.18475 528.09641
%%EndComments
%%Page: 1 1
200 560 translate
Then, You will open your eps file, translate, and save it.


신고
posted by citadel