html_fragment_to_pdf.Rd
This is the simple rendering function that will output a PDF file (potentially many pages) and a set of PNG files from HTML content. This is primarily used to render HTML content (e.g. a table) that is being included in a larger document. In this case the HTML fragment will not specify page dimensions which need to be provided (defaults to A4 size with 1 inch margins). The result can be embedded into an existing page using latex's includegraphics directive exactly the same way as a graphical figure might be used. The sizing of the output will always be smaller than the dimensions of a page, but will shrink to fit the content.
html_fragment_to_pdf(
htmlFragment,
outFile,
xMarginInches,
yMarginInches,
maxWidthInches,
maxHeightInches,
formats,
pngDpi,
converter
)
htmlFragment a HTML fragment, e.g. usually the table element, but may be the whole page. - (java expects a RCharacter)
outFile the full path with or without extension (if no extension specified then `formats` parameter will apply) - (defaulting to `tempfile('html2pdfr_')`) - (java expects a RFile)
xMarginInches page width margins - (defaulting to `1.0`) - (java expects a RNumeric)
yMarginInches page height margins - (defaulting to `1.0`) - (java expects a RNumeric)
maxWidthInches what is the maximum allowable width? (default is A4) - (defaulting to `8.27`) - (java expects a RNumeric)
maxHeightInches what is the maximum allowable height? (if the content is larger than this then it will overflow to another page) - (defaulting to `11.69`) - (java expects a RNumeric)
formats If the outFile does not specify a file extension then you can do so here as "png" or "pdf" or both. - (defaulting to `c('pdf','png')`) - (java expects a RCharacterVector)
pngDpi the dots per inch for png outputs if requested. - (defaulting to `300`) - (java expects a RNumeric)
converter (optional) a configured HTML converter, only needed if manually specifying fonts. - (defaulting to `html2pdfr::html_converter()`) - (java expects a HtmlConverter)
RCharacterVector: the filename(s) written to (with extension '.pdf' or '.png' if outFile did not have an extension).
library(testthat)
library(dplyr)
html = iris %>% group_by(Species) %>%
summarise(across(everything(), mean)) %>%
huxtable::as_hux() %>%
huxtable::theme_article() %>%
huxtable::to_html()
html_fragment_to_pdf(html)
#> [1] "/tmp/RtmpRJNqpL/html2pdfr_95f70229868e9.pdf"
#> [2] "/tmp/RtmpRJNqpL/html2pdfr_95f70229868e9.png"