raffaem / pdfsak

Utility to manipulate PDF files.
MIT License
43 stars 8 forks source link

Text font size #1

Closed andrii-pukhalevych closed 3 years ago

andrii-pukhalevych commented 4 years ago

Is it possible to set font size for generated text? And also use right/center align?

raffaem commented 3 years ago

You can specify a LaTeX font size directly before the text.

For example, the following adds today's date and page numbers in the pdf using a huge font size (notice the \huge option):

pdftools --input-file ./pdfs/wikipedia_algorithm.pdf --output ./out/addtext.pdf --text "\huge $page/$pages" 0.95 0.97 --text "\huge $day/$month/$year" 0.01 0.01 --fitpaper --overwrite

Not sure what do you mean by "also use right/center align". Can you clarify that please?

You can specify the text position directly in the command line.

andrii-pukhalevych commented 3 years ago

Thanks @raffaem. You should add this information to doc. For me it was not clear that text may include latext font size option. right align is needed when page numbers are added to bottom right side of page. In this case its better to specify position of right corner bottom corner (1 1 for example). 0.95 0.97 will cause shifting if page numbers jumps over 10, 100 etc:

 1/999
 10/999
 100/999

As you can see last letter is not aligned well here and it will looks not very good.

raffaem commented 3 years ago

Hello @andrii-pukhalevych ,

can you check whether, using the latest commit, the following command will add the page numbers in the way you want?

python3 -m pdftools -if slides.pdf -o slidesout.pdf --fitpaper --overwrite --text "\$page/\$pages" br 1 1

andrii-pukhalevych commented 3 years ago

br, tr - that exactly what I need.
Now its awesome :1st_place_medal:

andrii-pukhalevych commented 3 years ago

Maybe you also know easy way to not add page number on first page if possible. Now I concatenate conference proceedings (title + papers) with page numbers, then removing title and adding title without page number/

andrii-pukhalevych commented 3 years ago

Added pdftools link to conference website: http://itconf.nuos.edu.ua/2020/ and http://itconf.nuos.edu.ua/2021/ Its free IT internet conference in Ukraine. Will delete this comment after closing issue

raffaem commented 3 years ago

Maybe you also know easy way to not add page number on first page if possible. Now I concatenate conference proceedings (title + papers) with page numbers, then removing title and adding title without page number/

Hello again,

I think we have to think on it a bit because I don't know whether there is an easy feasible way to implement this.

pdftools use LaTeX pdfpages package under the hood to import the pdf, and set a page style on it using the pagecommand option:

\includepdf[keepaspectratio,pages={-},pagecommand=\thispagestyle{file0},fitpaper]{\detokenize{whiteslides.pdf}}

\fancypagestyle{file0}{
    [...] <- initialization
    \begin{textblock*}{\textboxwidth}[1,1](1\paperwidth, 1\paperheight)
        \raggedright \thepage/\pageref{LastPage}
    \end{textblock*}
} %end of fancypagestyle

Doing what you suggest would require importing the pdf in two steps and having two different page styles on them, something like:

Importing the first page, no page style: \includepdf[keepaspectratio, pages={1},fitpaper]{\detokenize{whiteslides.pdf}}

Importing all the other pages, with the page style to write page numbers: \includepdf[keepaspectratio, pages={2-},pagecommand=\thispagestyle{file0},fitpaper]{\detokenize{whiteslides.pdf}}

In the meantime you could try to call pdftools with the --debug option and modify the .tex file directly.

Added pdftools link to conference website: http://itconf.nuos.edu.ua/2020/ and http://itconf.nuos.edu.ua/2021/ Its free IT internet conference in Ukraine. Will delete this comment after closing issue

Thank you so much for the endorsement :)

raffaem commented 3 years ago

Maybe you also know easy way to not add page number on first page if possible.

Closed as not implemented for now