creating pdftk watermark file from command line - watermark

I need pdftk to watermark a pdf. I’m generating the content of the watermark programatically and write it out into a text file. Then I use cupsfilter to create the watermark pdf, and then pdftk to apply the generated watermark pdf onto an eBook pdf.
I understand that pdftk applies page by page watermark pdf onto eBook pdf.
If I create a 62 line text file, with 61 empty lines and watermark text on 62nd, then it gets applied properly at around 5/6 of the page height on every page of the eBook pdf.
I add one more empty line, the watermark text disappears. It does not end up on the next page, it is simply not there.
My ultimate goal is to have the watermark text at the bottom of the second page of the eBook
So I would need to create a 3 page pdf, having the first page empty, watermark text at the bottom of the second page and an third page again empty
I tried to insert page break using BBEdit into the text file, but I do not get the expected result.
does anybody have a hint how could I create the required text file which once printed out with cupsflter into a pdf will create the needed watermark pdf (first and third page empty and line or two of text at the bottom of the second page)

OK, so first, the manual is not entirely clear about difference between stamp and multistamp, and background and multibackground - it explains that the watermark pdf will be applied page by page onto eBook pdf if the watermark pdf is a multipage pdf, and that if the watermark pdf has fewer pages than the eBook pdf, the last page of the watermark pdf will be applied to all surplus pages of the eBook, and this is correct, but only in case of multistamp/multibackground option. If you use stamp/background option then only the first page of the watermark pdf will be applied to all pages of the eBook pdf, this was the first to figure out.
So I created two txt files using echo, one empty (one space in it) and one with one line of watermark text. Than I used pdftk cat option to merge the empty pdf with the watermark pdf, so I got two page pdf having first page empty and second with the line of text. Than I merged this file once again with the empty pdf, and ended up with 3 pages pdf.
Then I applied this 3 page watermark pdf with multibackground option to the eBook and got what I wanted - first page no watermark, second page the line of text and third an all other pages with no watermark.

Related

PDF content stream operators are in reverse order. By using PDFBOX how we can re order it?

There are some PDF's which are generated by ocrmypdf library in hocr mode.
ocrmypdf.ocr("input.pdf", "output.pdf",pdf_renderer='hocr', keep_temporary_files=True)
These all pdf's content stream is in reverse order. The page last line is located first in content stream as shown in below figure.
PDF file
Because of this when I tag this pdf the jaws is reading last line first in every paragraph tag.

How to merge pages of a PDF document into a single page from command line?

I have an HTML document to be printed in an 80mm paper roll. So, I convert the HTML document to PDF and use the lp command to print it. Problem is: the generated PDF file breaks my document into pages. What I need is to merge PDF pages into a single page which has the height of the HTML document I am converting from

Imposed (nup'ped) PDF file does not allow selection of text

I have a PDF file with 5 pages. I have created an imposed (nup'ped) PDF file with all those pages on one long paper sheet. I used pdfpages LaTeX package for that and the following code:
\includepdf[pages={1-5},nup=1x5]{original.pdf}
The original PDF file had recognized and selectable text on all pages. But in the resulting file (result.pdf) only the first two pages allow text selection. The imposition was done correctly and looks as expected.
It turned out to be the poppler's 50`000 characters limit per page.

How to resize a PDF page with itext without scaling the content (in Java)

I have been trying for days to find a solution for my problem: I want to resize an existing pdf from A4 to a given individual smaller page size. And I need the real page size to be changed, not the crop box or something like that.
The original pdf will always consist of only one page and all content (e.g. texts (some with hyperlinks), images and tables) will fit into the wanted page size. In fact I want to trim the pfd page to a rectangle that exactly fits to the existing content (the content starts at the left upper corner).
As I found no way to change the page size of an existing pdf page, I tried to create a new pdf with the wanted page size and copy all the content of the original pdf to the new pdf. But that doesn't work either (I can create the new pdf page with the wanted size, but I cannot copy the content).
Any solution (iText 5 or 7) is welcome.

Export PDF Page contents to individual pages

I have a pdf document which contains more than one page within each page.
The original document is only 2 pages - size A4, but has multiple pages on each of the 2 pages.
I need to export each of these "pages within each page" to an individual pdf page.
I have tried increasing the zoom of the pages and printing from there, but it prints incorrectly.
What could I do within Adobe reader or similar program to export each of these pages each as their own pdf page ?
Link to PDF
Within Acrobat reader, you could make a clever use of custom poster printing (possibly to print as a new PDF):
https://apple.stackexchange.com/questions/12305/split-a-single-page-pdf-into-multiple-pages
Otherwise you can do any of these:
Splitting single page into two pages with ghostscript
Alternatively you could use other tools such as Inkscape to do the splitting.