add a .pdf file(.png basically) to the end of every page in another .pdf file
Asked Answered
D

1

5

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
Detachment answered 27/11, 2013 at 6:36 Comment(5)
If I understand you correctly a simple pdfnup call should fit your needs!Phonography
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?Detachment
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.Phonography
If you can be more specific on the format or the pdfs I can construct an answer.Phonography
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 !Detachment
P
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.

Phonography answered 28/11, 2013 at 8:46 Comment(5)
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 ?Detachment
THANKYOU SO MUCH Jakob!!!!Got what I wanted :) Wish I had a few repo points to upvote such lovely answer ! Thanks Once again brother!Detachment
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.Phonography
@Phonography how do I use coordinates to place the image at a particular location on the pageSkerl
@Skerl pdfjam uses the LaTeX pdfpages pages, thus the docu 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.Phonography

© 2022 - 2024 — McMap. All rights reserved.