4

I have a code.ps file converted to code.pdf , which I want to add to the end of every page in my test.pdf , i.e shrink the test.pdf's every page and add an image to the end of it .

I have written the following shell script to it , but it appends the code.pdf as a new page after every page of test.pdf ! ...Kindly help . Here is my code :-

#!/bin/sh
filename=test.pdf
pages="`pdftk $filename dump_data | grep NumberOfPages | cut -d : -f2`"
numpages=`for ((a=1; a <= $pages; a++)); do echo -n "A$a B1 "; done`
pdftk A=$filename B=code.pdf cat $numpages output $filename-alternated.pdf
exit 0
devnull
  • 118,548
  • 33
  • 236
  • 227
user3040487
  • 181
  • 1
  • 3
  • 7
  • If I understand you correctly a simple pdfnup call should fit your needs! – Jakob Nov 27 '13 at 22:17
  • Yes , I tried pdfnup ,but essentially it only merges the two pages into one , and perhaps there is no concept of adjusting the ratios of the the pages in the new one , as in, my problem can be better stated as the following : EXCEPT FOR CPDF , Is there any utility to 'STAMP' a .pdf/ .pdf file at the end of every page of ANOTHER .PDF FILE? – user3040487 Nov 28 '13 at 05:35
  • `pdftk` has a `stamp` (or `background` option) - but it simply overlays the two pdfs. I would use `pdfjam` to preprocess the test.pdf (scale and offest) and `pdftk` to compose them. This would require only two lines of code (three if code.pdf has to be preprocessed as well) and no loops. – Jakob Nov 28 '13 at 08:06
  • If you can be more specific on the format or the pdfs I can construct an answer. – Jakob Nov 28 '13 at 08:07
  • Yes!In the answer you gave ,, I want the image to be contained well within the borders of the original page,and at the end of the page .What I have created thus far is an image stamped at the end of the page but overlapping with some text over there ! – user3040487 Nov 28 '13 at 09:31

1 Answers1

8

A simple example of stamping an image (image.[pdf,png] onto a multipage pdf (text.pdf) allowing for manual tweaking of the scaling and offsets using pdfjam and pdftk could be:

# scale and offset the text part
pdfjam --scale 0.8 --frame True --offset '0cm 2.5cm' text.pdf
# scale and offset the image
pdfjam --paper 'a4paper' --scale 0.3 --offset '7cm -12cm' image.pdf
# combine both
pdftk text-pdfjam.pdf stamp image-pdfjam.pdf output combined.pdf

This might look like enter image description here

If you start with an image file (png, jpg) you can convert it to pdf using imagemagick like

convert image.png image.pdf

Of course, the scale factors and offsets have to be adjusted to your needs. I included the --frame option to highlight the scaling of the text.pdf part. The stamp option overlays the image, whereas the background option would underlay the image.

Jakob
  • 19,815
  • 6
  • 75
  • 94
  • Thankyou ,, Yes I lately tried kinda a similar thing , But thankyou so Much Jacob :) ...can we by any means remove the borders in the original page so as to make it look like a real new A4 page ? – user3040487 Nov 28 '13 at 09:19
  • THANKYOU SO MUCH Jakob!!!!Got what I wanted :) Wish I had a few repo points to upvote such lovely answer ! Thanks Once again brother! – user3040487 Nov 28 '13 at 09:38
  • To get rid of the border, simply remove the `--frame True` option in the first pdfjam call. - You may accept the answer, to finalize this question. – Jakob Nov 28 '13 at 09:51
  • @Jakob how do I use coordinates to place the image at a particular location on the page – Daniel Jun 30 '14 at 02:56
  • @Daniel `pdfjam` uses the LaTeX pdfpages pages, thus the [docu](http://mirror.unl.edu/ctan/macros/latex/contrib/pdfpages/pdfpages.pdf) is a good place to start. Here, the `offset` command is used to shift the image from the center of the page. Hope this can help you. – Jakob Jun 30 '14 at 05:41