Re: [R] adding "Page X of XX" to PDFs
On 02/12/2023 5:37 p.m., CALUM POLWART wrote: You could easily omit the Page X of xX, but leave the timestamp Then add Page X of XX programmatically using pdftools or some similar pdf command line tools. You don't need to use command line tools -- I showed how to do it by creating an R Markdown document with each page of the PDF on a numbered page of the result. Here's a minor improvement of my post: --- title: "Numbered" output: pdf_document: extra_dependencies: ["pdfpages", "fancyhdr", "lastpage"] --- \cfoot{Page \thepage\ of \pageref{LastPage}} \addtocounter{page}{-1} \includepdf[pages={1-},pagecommand={\thispagestyle{fancy}}]{Rplots.pdf} This works regardless of the number of pages in Rplots.pdf. Duncan Murdoch On Sat, 2 Dec 2023, 22:35 , wrote: Having read all of the replies, it seems there are solutions for the question and the OP points out that some solutions such as making the document twice will affect the creation date. I suspect the additional time to do so is seconds or at most minutes so it may not be a big deal. But what about the idea of creating a PDF with a placeholder like "Page N of XXX" and after the file has been created, dates and all, perhaps edit it programmatically and replace all instances of XXX with something of the same length like " 23" as there seem to be tools like the pdftools package that let you get the number of pages. I have no idea if some program, perhaps external, can do that and retain the date you want. -Original Message- From: R-help On Behalf Of Dennis Fisher Sent: Friday, December 1, 2023 3:53 PM To: r-help@r-project.org Subject: [R] adding "Page X of XX" to PDFs OS X R 4.3.1 Colleagues I often create multipage PDFs [pdf()] in which the text "Page X" appears in the margin. These PDFs are created automatically using a massive R script. One of my clients requested that I change this to: Page X of XX where XX is the total number of pages. I don't know the number of expected pages so I can't think of any clever way to do this. I suppose that I could create the PDF, find out the number of pages, then have a second pass in which the R script was fed the number of pages. However, there is one disadvantage to this -- the original PDF contains a timestamp on each page -- the new version would have a different timestamp -- so I would prefer to not use this approach. Has anyone thought of some terribly clever way to solve this problem? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding "Page X of XX" to PDFs
You could easily omit the Page X of xX, but leave the timestamp Then add Page X of XX programmatically using pdftools or some similar pdf command line tools. On Sat, 2 Dec 2023, 22:35 , wrote: > Having read all of the replies, it seems there are solutions for the > question and the OP points out that some solutions such as making the > document twice will affect the creation date. > > I suspect the additional time to do so is seconds or at most minutes so it > may not be a big deal. > > But what about the idea of creating a PDF with a placeholder like "Page N > of > XXX" and after the file has been created, dates and all, perhaps edit it > programmatically and replace all instances of XXX with something of the > same > length like " 23" as there seem to be tools like the pdftools package that > let you get the number of pages. I have no idea if some program, perhaps > external, can do that and retain the date you want. > > -Original Message- > From: R-help On Behalf Of Dennis Fisher > Sent: Friday, December 1, 2023 3:53 PM > To: r-help@r-project.org > Subject: [R] adding "Page X of XX" to PDFs > > OS X > R 4.3.1 > > Colleagues > > I often create multipage PDFs [pdf()] in which the text "Page X" appears in > the margin. These PDFs are created automatically using a massive R script. > > One of my clients requested that I change this to: > Page X of XX > where XX is the total number of pages. > > I don't know the number of expected pages so I can't think of any clever > way > to do this. I suppose that I could create the PDF, find out the number of > pages, then have a second pass in which the R script was fed the number of > pages. However, there is one disadvantage to this -- the original PDF > contains a timestamp on each page -- the new version would have a different > timestamp -- so I would prefer to not use this approach. > > Has anyone thought of some terribly clever way to solve this problem? > > Dennis > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone / Fax: 1-866-PLessThan (1-866-753-7784) > www.PLessThan.com > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding "Page X of XX" to PDFs
Having read all of the replies, it seems there are solutions for the question and the OP points out that some solutions such as making the document twice will affect the creation date. I suspect the additional time to do so is seconds or at most minutes so it may not be a big deal. But what about the idea of creating a PDF with a placeholder like "Page N of XXX" and after the file has been created, dates and all, perhaps edit it programmatically and replace all instances of XXX with something of the same length like " 23" as there seem to be tools like the pdftools package that let you get the number of pages. I have no idea if some program, perhaps external, can do that and retain the date you want. -Original Message- From: R-help On Behalf Of Dennis Fisher Sent: Friday, December 1, 2023 3:53 PM To: r-help@r-project.org Subject: [R] adding "Page X of XX" to PDFs OS X R 4.3.1 Colleagues I often create multipage PDFs [pdf()] in which the text "Page X" appears in the margin. These PDFs are created automatically using a massive R script. One of my clients requested that I change this to: Page X of XX where XX is the total number of pages. I don't know the number of expected pages so I can't think of any clever way to do this. I suppose that I could create the PDF, find out the number of pages, then have a second pass in which the R script was fed the number of pages. However, there is one disadvantage to this -- the original PDF contains a timestamp on each page -- the new version would have a different timestamp -- so I would prefer to not use this approach. Has anyone thought of some terribly clever way to solve this problem? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding "Page X of XX" to PDFs
On 02/12/2023 2:07 p.m., Ben Bolker wrote: Sorry, jumped into the thread too late. (On the other hand, once the document gets complicated enough, it may be worth it in the long run to convert to something that actually has a document-generating back-end, rather than reinventing everything from scratch ...) I agree with that comment. However, if one is stuck with a multipage PDF file, and wants to add page numbering, you could use the LaTeX pdfpages package. For example, this R Markdown document includes all 10 plots from Rplots.pdf on pages with "x of y" page numbering. --- title: "Numbered" output: pdf_document: extra_dependencies: ["pdfpages", "fancyhdr", "lastpage"] --- \cfoot{Page \thepage\ of \pageref{LastPage}} \addtocounter{page}{-1} \includepdf[pages={1-10},pagecommand={\thispagestyle{fancy}}]{Rplots.pdf} It would make more sense to do this in a LaTeX document, but I'm not sure if Dennis knows LaTeX... Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding "Page X of XX" to PDFs
Sorry, jumped into the thread too late. (On the other hand, once the document gets complicated enough, it may be worth it in the long run to convert to something that actually has a document-generating back-end, rather than reinventing everything from scratch ...) On 2023-12-02 2:03 p.m., Jeff Newmiller via R-help wrote: He clearly stated he was using the pdf() graphics device. On December 2, 2023 10:36:44 AM PST, Ben Bolker wrote: It's still not entirely clear to me what framework you're using to generate the PDF, but if it's rmarkdown/Rnw (Sweave)/Quarto-based, then as far as I know all of those frameworks use LaTeX as the last step in the script-to-PDF pipeline, and allow the inclusion of arbitrary LaTeX code, so the 'lastpage' package would do this for you: https://stackoverflow.com/questions/70343001/how-to-show-the-total-number-of-pages-in-a-pdf-via-the-rmarkdown-i-e-display https://tex.stackexchange.com/questions/227/how-can-i-add-page-of-on-my-document On 2023-12-02 12:23 p.m., Ebert,Timothy Aaron wrote: Would this work in general? Say I have a document with figures, special equations, text, and tables. The text and tables are relatively easy. The figures would need a conversion from pixels to lines, and the equations maybe printed out, counted as a figure, and then added to the line count. It would also be tricky if a title line was at 32 point font and the text at 12, and the more complex the formatting the harder to deal with rows as related to page size. Thankfully I do not think I will have to do this, so the question is for theoretical interest on my part (at least for now). Tim -Original Message- From: R-help On Behalf Of Jeff Newmiller via R-help Sent: Saturday, December 2, 2023 11:46 AM To: r-help@r-project.org Subject: Re: [R] adding "Page X of XX" to PDFs [External Email] One of the most fundamental characteristics of R programming is the use of data frames of column vectors, and one of the very first challenges I had as a then-Perl-programmer was coming to grips with the fact that unknown-length CSV files would be read completely into memory as rows and once the entire CSV was in memory it would be transposed into column vectors. I was resistant to this philosophy at first, but the advantages in computation speed and simplicity eventually won me over. I would say that if you want to know how many pages you are going to produce with R, then you are going to have to count them before you create them. Building a dataframe that describes (in terms of parameters to be passed to a page-generating function in each row) what you are going to put on each page before you actually print it can make this pre-counting problem trivial, and the code that does the printing is likely to be more modular and testable as well. On December 1, 2023 12:53:25 PM PST, Dennis Fisher wrote: OS X R 4.3.1 Colleagues I often create multipage PDFs [pdf()] in which the text "Page X" appears in the margin. These PDFs are created automatically using a massive R script. One of my clients requested that I change this to: Page X of XX where XX is the total number of pages. I don't know the number of expected pages so I can't think of any clever way to do this. I suppose that I could create the PDF, find out the number of pages, then have a second pass in which the R script was fed the number of pages. However, there is one disadvantage to this -- the original PDF contains a timestamp on each page -- the new version would have a different timestamp -- so I would prefer to not use this approach. Has anyone thought of some terribly clever way to solve this problem? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) http://www.plessthan.com/ __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Sent from my phone. Please excuse my brevity. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do re
Re: [R] adding "Page X of XX" to PDFs
He clearly stated he was using the pdf() graphics device. On December 2, 2023 10:36:44 AM PST, Ben Bolker wrote: > It's still not entirely clear to me what framework you're using to generate > the PDF, but if it's rmarkdown/Rnw (Sweave)/Quarto-based, then as far as I > know all of those frameworks use LaTeX as the last step in the script-to-PDF > pipeline, and allow the inclusion of arbitrary LaTeX code, so the 'lastpage' > package would do this for you: > >https://stackoverflow.com/questions/70343001/how-to-show-the-total-number-of-pages-in-a-pdf-via-the-rmarkdown-i-e-display > >https://tex.stackexchange.com/questions/227/how-can-i-add-page-of-on-my-document > > > >On 2023-12-02 12:23 p.m., Ebert,Timothy Aaron wrote: >> Would this work in general? Say I have a document with figures, special >> equations, text, and tables. The text and tables are relatively easy. The >> figures would need a conversion from pixels to lines, and the equations >> maybe printed out, counted as a figure, and then added to the line count. It >> would also be tricky if a title line was at 32 point font and the text at >> 12, and the more complex the formatting the harder to deal with rows as >> related to page size. >> >> Thankfully I do not think I will have to do this, so the question is for >> theoretical interest on my part (at least for now). >> >> Tim >> >> -Original Message- >> From: R-help On Behalf Of Jeff Newmiller via >> R-help >> Sent: Saturday, December 2, 2023 11:46 AM >> To: r-help@r-project.org >> Subject: Re: [R] adding "Page X of XX" to PDFs >> >> [External Email] >> >> One of the most fundamental characteristics of R programming is the use of >> data frames of column vectors, and one of the very first challenges I had as >> a then-Perl-programmer was coming to grips with the fact that unknown-length >> CSV files would be read completely into memory as rows and once the entire >> CSV was in memory it would be transposed into column vectors. I was >> resistant to this philosophy at first, but the advantages in computation >> speed and simplicity eventually won me over. >> >> I would say that if you want to know how many pages you are going to produce >> with R, then you are going to have to count them before you create them. >> Building a dataframe that describes (in terms of parameters to be passed to >> a page-generating function in each row) what you are going to put on each >> page before you actually print it can make this pre-counting problem >> trivial, and the code that does the printing is likely to be more modular >> and testable as well. >> >> On December 1, 2023 12:53:25 PM PST, Dennis Fisher >> wrote: >>> OS X >>> R 4.3.1 >>> >>> Colleagues >>> >>> I often create multipage PDFs [pdf()] in which the text "Page X" appears in >>> the margin. These PDFs are created automatically using a massive R script. >>> >>> One of my clients requested that I change this to: >>>Page X of XX >>> where XX is the total number of pages. >>> >>> I don't know the number of expected pages so I can't think of any clever >>> way to do this. I suppose that I could create the PDF, find out the number >>> of pages, then have a second pass in which the R script was fed the number >>> of pages. However, there is one disadvantage to this -- the original PDF >>> contains a timestamp on each page -- the new version would have a different >>> timestamp -- so I would prefer to not use this approach. >>> >>> Has anyone thought of some terribly clever way to solve this problem? >>> >>> Dennis >>> >>> Dennis Fisher MD >>> P < (The "P Less Than" Company) >>> Phone / Fax: 1-866-PLessThan (1-866-753-7784) >>> http://www.plessthan.com/ >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.r-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> -- >> Sent from my phone. Please excuse my brevity. >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://
Re: [R] adding "Page X of XX" to PDFs
It's still not entirely clear to me what framework you're using to generate the PDF, but if it's rmarkdown/Rnw (Sweave)/Quarto-based, then as far as I know all of those frameworks use LaTeX as the last step in the script-to-PDF pipeline, and allow the inclusion of arbitrary LaTeX code, so the 'lastpage' package would do this for you: https://stackoverflow.com/questions/70343001/how-to-show-the-total-number-of-pages-in-a-pdf-via-the-rmarkdown-i-e-display https://tex.stackexchange.com/questions/227/how-can-i-add-page-of-on-my-document On 2023-12-02 12:23 p.m., Ebert,Timothy Aaron wrote: Would this work in general? Say I have a document with figures, special equations, text, and tables. The text and tables are relatively easy. The figures would need a conversion from pixels to lines, and the equations maybe printed out, counted as a figure, and then added to the line count. It would also be tricky if a title line was at 32 point font and the text at 12, and the more complex the formatting the harder to deal with rows as related to page size. Thankfully I do not think I will have to do this, so the question is for theoretical interest on my part (at least for now). Tim -Original Message- From: R-help On Behalf Of Jeff Newmiller via R-help Sent: Saturday, December 2, 2023 11:46 AM To: r-help@r-project.org Subject: Re: [R] adding "Page X of XX" to PDFs [External Email] One of the most fundamental characteristics of R programming is the use of data frames of column vectors, and one of the very first challenges I had as a then-Perl-programmer was coming to grips with the fact that unknown-length CSV files would be read completely into memory as rows and once the entire CSV was in memory it would be transposed into column vectors. I was resistant to this philosophy at first, but the advantages in computation speed and simplicity eventually won me over. I would say that if you want to know how many pages you are going to produce with R, then you are going to have to count them before you create them. Building a dataframe that describes (in terms of parameters to be passed to a page-generating function in each row) what you are going to put on each page before you actually print it can make this pre-counting problem trivial, and the code that does the printing is likely to be more modular and testable as well. On December 1, 2023 12:53:25 PM PST, Dennis Fisher wrote: OS X R 4.3.1 Colleagues I often create multipage PDFs [pdf()] in which the text "Page X" appears in the margin. These PDFs are created automatically using a massive R script. One of my clients requested that I change this to: Page X of XX where XX is the total number of pages. I don't know the number of expected pages so I can't think of any clever way to do this. I suppose that I could create the PDF, find out the number of pages, then have a second pass in which the R script was fed the number of pages. However, there is one disadvantage to this -- the original PDF contains a timestamp on each page -- the new version would have a different timestamp -- so I would prefer to not use this approach. Has anyone thought of some terribly clever way to solve this problem? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) http://www.plessthan.com/ __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Sent from my phone. Please excuse my brevity. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding "Page X of XX" to PDFs
Would this work in general? Say I have a document with figures, special equations, text, and tables. The text and tables are relatively easy. The figures would need a conversion from pixels to lines, and the equations maybe printed out, counted as a figure, and then added to the line count. It would also be tricky if a title line was at 32 point font and the text at 12, and the more complex the formatting the harder to deal with rows as related to page size. Thankfully I do not think I will have to do this, so the question is for theoretical interest on my part (at least for now). Tim -Original Message- From: R-help On Behalf Of Jeff Newmiller via R-help Sent: Saturday, December 2, 2023 11:46 AM To: r-help@r-project.org Subject: Re: [R] adding "Page X of XX" to PDFs [External Email] One of the most fundamental characteristics of R programming is the use of data frames of column vectors, and one of the very first challenges I had as a then-Perl-programmer was coming to grips with the fact that unknown-length CSV files would be read completely into memory as rows and once the entire CSV was in memory it would be transposed into column vectors. I was resistant to this philosophy at first, but the advantages in computation speed and simplicity eventually won me over. I would say that if you want to know how many pages you are going to produce with R, then you are going to have to count them before you create them. Building a dataframe that describes (in terms of parameters to be passed to a page-generating function in each row) what you are going to put on each page before you actually print it can make this pre-counting problem trivial, and the code that does the printing is likely to be more modular and testable as well. On December 1, 2023 12:53:25 PM PST, Dennis Fisher wrote: >OS X >R 4.3.1 > >Colleagues > >I often create multipage PDFs [pdf()] in which the text "Page X" appears in >the margin. These PDFs are created automatically using a massive R script. > >One of my clients requested that I change this to: > Page X of XX >where XX is the total number of pages. > >I don't know the number of expected pages so I can't think of any clever way >to do this. I suppose that I could create the PDF, find out the number of >pages, then have a second pass in which the R script was fed the number of >pages. However, there is one disadvantage to this -- the original PDF >contains a timestamp on each page -- the new version would have a different >timestamp -- so I would prefer to not use this approach. > >Has anyone thought of some terribly clever way to solve this problem? > >Dennis > >Dennis Fisher MD >P < (The "P Less Than" Company) >Phone / Fax: 1-866-PLessThan (1-866-753-7784) >http://www.plessthan.com/ > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://www.r-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. -- Sent from my phone. Please excuse my brevity. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding "Page X of XX" to PDFs
https://community.rstudio.com/t/total-number-of-pages-in-quarto-pdf/177316/2 On Sat, 2 Dec 2023 at 09:39, Dennis Fisher wrote: > OS X > R 4.3.1 > > Colleagues > > I often create multipage PDFs [pdf()] in which the text "Page X" appears > in the margin. These PDFs are created automatically using a massive R > script. > > One of my clients requested that I change this to: > Page X of XX > where XX is the total number of pages. > > I don't know the number of expected pages so I can't think of any clever > way to do this. I suppose that I could create the PDF, find out the number > of pages, then have a second pass in which the R script was fed the number > of pages. However, there is one disadvantage to this -- the original PDF > contains a timestamp on each page -- the new version would have a different > timestamp -- so I would prefer to not use this approach. > > Has anyone thought of some terribly clever way to solve this problem? > > Dennis > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone / Fax: 1-866-PLessThan (1-866-753-7784) > www.PLessThan.com > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- John Kane Kingston ON Canada [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding "Page X of XX" to PDFs
One of the most fundamental characteristics of R programming is the use of data frames of column vectors, and one of the very first challenges I had as a then-Perl-programmer was coming to grips with the fact that unknown-length CSV files would be read completely into memory as rows and once the entire CSV was in memory it would be transposed into column vectors. I was resistant to this philosophy at first, but the advantages in computation speed and simplicity eventually won me over. I would say that if you want to know how many pages you are going to produce with R, then you are going to have to count them before you create them. Building a dataframe that describes (in terms of parameters to be passed to a page-generating function in each row) what you are going to put on each page before you actually print it can make this pre-counting problem trivial, and the code that does the printing is likely to be more modular and testable as well. On December 1, 2023 12:53:25 PM PST, Dennis Fisher wrote: >OS X >R 4.3.1 > >Colleagues > >I often create multipage PDFs [pdf()] in which the text "Page X" appears in >the margin. These PDFs are created automatically using a massive R script. > >One of my clients requested that I change this to: > Page X of XX >where XX is the total number of pages. > >I don't know the number of expected pages so I can't think of any clever way >to do this. I suppose that I could create the PDF, find out the number of >pages, then have a second pass in which the R script was fed the number of >pages. However, there is one disadvantage to this -- the original PDF >contains a timestamp on each page -- the new version would have a different >timestamp -- so I would prefer to not use this approach. > >Has anyone thought of some terribly clever way to solve this problem? > >Dennis > >Dennis Fisher MD >P < (The "P Less Than" Company) >Phone / Fax: 1-866-PLessThan (1-866-753-7784) >www.PLessThan.com > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. -- Sent from my phone. Please excuse my brevity. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding "Page X of XX" to PDFs
Can you provide a very simplified version of how the PDF is created? On Sat, 2 Dec 2023, 14:39 Dennis Fisher, wrote: > OS X > R 4.3.1 > > Colleagues > > I often create multipage PDFs [pdf()] in which the text "Page X" appears > in the margin. These PDFs are created automatically using a massive R > script. > > One of my clients requested that I change this to: > Page X of XX > where XX is the total number of pages. > > I don't know the number of expected pages so I can't think of any clever > way to do this. I suppose that I could create the PDF, find out the number > of pages, then have a second pass in which the R script was fed the number > of pages. However, there is one disadvantage to this -- the original PDF > contains a timestamp on each page -- the new version would have a different > timestamp -- so I would prefer to not use this approach. > > Has anyone thought of some terribly clever way to solve this problem? > > Dennis > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone / Fax: 1-866-PLessThan (1-866-753-7784) > www.PLessThan.com > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding "Page X of XX" to PDFs
You need to use raw LaTeX See section 4 here Von meinem iPad gesendet > Am 02.12.2023 um 15:39 schrieb Dennis Fisher : > > OS X > R 4.3.1 > > Colleagues > > I often create multipage PDFs [pdf()] in which the text "Page X" appears in > the margin. These PDFs are created automatically using a massive R script. > > One of my clients requested that I change this to: >Page X of XX > where XX is the total number of pages. > > I don't know the number of expected pages so I can't think of any clever way > to do this. I suppose that I could create the PDF, find out the number of > pages, then have a second pass in which the R script was fed the number of > pages. However, there is one disadvantage to this -- the original PDF > contains a timestamp on each page -- the new version would have a different > timestamp -- so I would prefer to not use this approach. > > Has anyone thought of some terribly clever way to solve this problem? > > Dennis > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone / Fax: 1-866-PLessThan (1-866-753-7784) > www.PLessThan.com > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] adding "Page X of XX" to PDFs
OS X R 4.3.1 Colleagues I often create multipage PDFs [pdf()] in which the text "Page X" appears in the margin. These PDFs are created automatically using a massive R script. One of my clients requested that I change this to: Page X of XX where XX is the total number of pages. I don't know the number of expected pages so I can't think of any clever way to do this. I suppose that I could create the PDF, find out the number of pages, then have a second pass in which the R script was fed the number of pages. However, there is one disadvantage to this -- the original PDF contains a timestamp on each page -- the new version would have a different timestamp -- so I would prefer to not use this approach. Has anyone thought of some terribly clever way to solve this problem? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.