The HTML in `html` is assumed to be a complete document. Relative references are resolved with reference to `baseUri` if it is given (which could be a `file://` URI). The resulting PDF size will be controlled by page media directives within the HTML, unless explicitly given here in `maxWidthInches` and `maxHeightInches`. If the `cssSelector` parameter is given the HTML fragment at that selector will be used. In this case it is will be resized to fit within the given dimensions and shrink wrapped so that the content is smaller. If no dimensions are present this will default to A4.

html_document_to_pdf(
  html,
  outFile,
  baseUri,
  cssSelector,
  xMarginInches,
  yMarginInches,
  maxWidthInches,
  maxHeightInches,
  formats,
  pngDpi,
  converter
)

Arguments

html

html the html document as a string - (java expects a RCharacter)

outFile

outFile the full path of the output file - (defaulting to `tempfile('html2pdfr_')`) - (java expects a RFile)

baseUri

baseUri the URI from which to interpret relative links in the html content. - (defaulting to `NA_character_`) - (java expects a RCharacter)

cssSelector

cssSelector the part of the page you want to convert to PDF. - (defaulting to `NA_character_`) - (java expects a RCharacter)

xMarginInches

xMarginInches page width margins - (defaulting to `NA_real_`) - (java expects a RNumeric)

yMarginInches

yMarginInches page height margins - (defaulting to `NA_real_`) - (java expects a RNumeric)

maxWidthInches

maxWidthInches what is the maximum allowable width? - (defaulting to `NA_real_`) - (java expects a RNumeric)

maxHeightInches

maxHeightInches what is the maximum allowable height? (if the content is larger than this then it will overflow to another page) - (defaulting to `NA_real_`) - (java expects a RNumeric)

formats

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')`) - (java expects a RCharacterVector)

pngDpi

pngDpi the dots per inch for png outputs if requested - (defaulting to `300`) - (java expects a RNumeric)

converter

converter (optional) a configured HTML converter, only needed if manually specifying fonts. - (defaulting to `html2pdfr::html_converter()`) - (java expects a HtmlConverter)

Value

RCharacterVector: the filename written to (with extension '.pdf' or '.png' if outFile did not have an extension).

Examples

library(testthat)
library(readr)
html = read_file('https://fred-wang.github.io/MathFonts/mozilla_mathml_test/')
html_document_to_pdf(html, baseUri = 'https://fred-wang.github.io/MathFonts/mozilla_mathml_test/')
#> [1] "/tmp/RtmpRJNqpL/html2pdfr_95f7075f2ee02.pdf"