Title: | R Wrapper For Openhtmltopdf Java Library |
---|---|
Description: | HTML and CSS do a good job at automatically laying out and styling content particularly in tables, however it is not natively designed for pagination. This library converts HTML content into PDF and PNG formats for embedding into LaTeX documents, within the constraints of page sizes. It allows use of HTML table layout from HTML first libraries such as 'gt' and 'huxtable' within latex documents. It allows HTML content to grow in width up to the page dimensions, but preventing it from overflowing, and without forcing table layout to be wider than it would normally be. This heurisitic calculation of the output size up to fit within set limits is one of the differentiators between this and other HTML to PDF converters. Although the focus is on tables, any basic HTML content can be rendered, including simple SVG and MathML, up to the support of the underlying HTML rendering engine (https://github.com/danfickle/openhtmltopdf). |
Authors: | Rob Challen [aut, cre] |
Maintainer: | Rob Challen <[email protected]> |
License: | LGPL-3 |
Version: | 0.4.5 |
Built: | 2024-11-20 04:20:35 UTC |
Source: | https://github.com/terminological/html2pdfr |
HTML and CSS do a good job at automatically laying out and styling content particularly in tables, however it is not natively designed for pagination. This library converts HTML content into PDF and PNG formats for embedding into LaTeX documents, within the constraints of page sizes. It allows use of HTML table layout from HTML first libraries such as 'gt' and 'huxtable' within latex documents. It allows HTML content to grow in width up to the page dimensions, but preventing it from overflowing, and without forcing table layout to be wider than it would normally be. This heurisitic calculation of the output size up to fit within set limits is one of the differentiators between this and other HTML to PDF converters. Although the focus is on tables, any basic HTML content can be rendered, including simple SVG and MathML, up to the support of the underlying HTML rendering engine (https://github.com/danfickle/openhtmltopdf).
Version: 0.4.5
Classes:
JavaApi
HtmlConverter
Rob Challen [email protected] 0000-0002-5504-7768
The HTML in 'inFile' is assumed to be a complete document. Relative references are resolved with reference to the HTML file on the file system, so correctly located images etc whould be picked up without requiring a server. 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.
file_to_pdf( inFile, outFile, cssSelector, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter )
file_to_pdf( inFile, outFile, cssSelector, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter )
inFile |
inFile the full path the the HTML file - (java expects a RCharacter) |
outFile |
outFile the full path of the output file - (defaulting to ‘tempfile(’html2pdfr_')') - (java expects a RFile) |
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) |
RCharacterVector: the filename written to (with extension '.pdf' or '.png' if outFile did not have an extension).
library(testthat) dest = tempfile(fileext='.html') download.file('https://cran.r-project.org/banner.shtml', destfile = dest) file_to_pdf(dest)
library(testthat) dest = tempfile(fileext='.html') download.file('https://cran.r-project.org/banner.shtml', destfile = dest) file_to_pdf(dest)
for creating PDF and PNG files from HTML. In general this will be created automatically. but if you have specific fonts you want to use then you may need to pass them to this function and specify the result in the 'converter' parameter of the main functions.
html_converter( fontfiles, update )
html_converter( fontfiles, update )
fontfiles |
fontfiles - a character vector of font files that will be imported into the converter. - (defaulting to 'systemfonts::system_fonts()$path') - (java expects a RCharacterVector) |
update |
update - (defaulting to 'FALSE') - (java expects a RLogical) |
R6 HtmlConverter object:
conv = html2pdfr::html_converter()
conv = html2pdfr::html_converter()
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 )
html_document_to_pdf( html, outFile, baseUri, cssSelector, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter )
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) |
RCharacterVector: the filename written to (with extension '.pdf' or '.png' if outFile did not have an extension).
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/')
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/')
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 )
html_fragment_to_pdf( htmlFragment, outFile, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter )
htmlFragment |
htmlFragment a HTML fragment, e.g. usually the table element, but may be the whole page. - (java expects a RCharacter) |
outFile |
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 |
xMarginInches page width margins - (defaulting to '1.0') - (java expects a RNumeric) |
yMarginInches |
yMarginInches page height margins - (defaulting to '1.0') - (java expects a RNumeric) |
maxWidthInches |
maxWidthInches what is the maximum allowable width? (default is A4) - (defaulting to '8.27') - (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 '11.69') - (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','png')') - (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) |
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)
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)
missing description
Version: 0.4.5
Generated: 2024-04-24T15:58:01.271789527
fontfiles |
fontfiles - (java expects a String) |
no details
none
instance$clone()
instance$print()
new()
the default no-args constructor
J = html2pdfr::JavaApi$get() instance = J$HtmlConverter$new(fontfiles);
fontfiles - (java expects a String)
the new R6 HtmlConverter object
## ----------------------------------- ## Construct new instance of HtmlConverter ## ----------------------------------- ## Not run: J = html2pdfr::JavaApi$get() # appropriate parameter values must be provided instance = J$HtmlConverter$new(fontfiles) ## End(Not run)
## ----------------------------------- ## Construct new instance of HtmlConverter ## ----------------------------------- ## Not run: J = html2pdfr::JavaApi$get() # appropriate parameter values must be provided instance = J$HtmlConverter$new(fontfiles) ## End(Not run)
HTML and CSS do a good job at automatically laying out and styling content particularly in tables, however it is not natively designed for pagination. This library converts HTML content into PDF and PNG formats for embedding into LaTeX documents, within the constraints of page sizes. It allows use of HTML table layout from HTML first libraries such as 'gt' and 'huxtable' within latex documents. It allows HTML content to grow in width up to the page dimensions, but preventing it from overflowing, and without forcing table layout to be wider than it would normally be. This heurisitic calculation of the output size up to fit within set limits is one of the differentiators between this and other HTML to PDF converters. Although the focus is on tables, any basic HTML content can be rendered, including simple SVG and MathML, up to the support of the underlying HTML rendering engine (https://github.com/danfickle/openhtmltopdf).
Version: 0.4.5
Generated: 2024-04-24T15:58:01.201546101
logLevel |
optional - the slf4j log level as a string - one of OFF (most specific, no logging), FATAL (most specific, little data), ERROR, WARN, INFO, DEBUG, TRACE (least specific, a lot of data), ALL (least specific, all data) |
J = html2pdfr::JavaApi$get(logLevel)
JavaApi$installDependencies()
This package level method checks for, and installs any dependencies needed for the running of the package. It is called automatically on first package load and so in general does not need to be used directly.
html2pdfr::JavaApi$installDependencies()
none
nothing. called for side effects.
JavaApi$rebuildDependencies()
This package level method removes existing dependencies and re-installs dependencies needed for the running of the package. It is called automatically on first package load and so in general does not need to be called.
html2pdfr::JavaApi$rebuildDependencies()
none
nothing. called for side effects.
JavaApi$versionInformation()
This package level method returns debugging version information for the package
html2pdfr::JavaApi$versionInformation()
none
A list containing a set of versioning information about this package.
JavaApi$get()
This is the main entry point for the package and the root of the Java API in this package. All classes defined in the package are made available as items under this root. The JavaApi object manages the communication between R and Java.
J = html2pdfr::JavaApi$get() # package classes and functions are nested under the `J` api object.
logLevel The desired verbosity of the package. One of "OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE", "ALL".
A R6 html2pdfr::JavaApi object containing the access point to the objects and functions defined in this package
J$changeLogLevel(logLevel)
Once the package is initialised the log level can be changed to increase the level of messages from the api.
J = html2pdfr::JavaApi$get() J$changeLogLevel("DEBUG")
logLevel The desired verbosity of the package. One of "OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE", "ALL".
nothing. used for side effects.
J$reconfigureLog(log4jproperties)
Experimental / Advanced use: Once the package is initialised the log configureation can be changed to log to an external file for example.
J = html2pdfr::JavaApi$get() prp = fs::path(getwd(),"log4j.properties") if (fs::file_exists(prp)) { J$changeLogLevel(prp) }
log4jproperties a full path to a log4jproperies file
nothing. used for side effects.
J$printMessages()
Experimental / Internal use: Messages from Java to R are queued and printed after each function call. It is unlikely that any will be not printed so in normal circumstances this function should do nothing.
J = html2pdfr::JavaApi$get() J$printMessages()
none
nothing. used for side effects.
HtmlConverter$new()
the default no-args constructor
J = html2pdfr::JavaApi$get() J$HtmlConverter$new(fontfiles)
fontfiles - (java expects a String)
R6 HtmlConverter object:
HtmlConverter$htmlConverter()
Create a new HtmlConverter
for creating PDF and PNG files from HTML. In general this will be created automatically. but if you have specific fonts you want to use then you may need to pass them to this function and specify the result in the 'converter' parameter of the main functions.
J = html2pdfr::JavaApi$get() J$HtmlConverter$htmlConverter(fontfiles, update) # this method is also exposed as a package function: html2pdfr::html_converter(fontfiles, update)
fontfiles - a character vector of font files that will be imported into the converter. - (defaulting to 'systemfonts::system_fonts()$path') - (java expects a RCharacterVector)
update - (defaulting to 'FALSE') - (java expects a RLogical)
R6 HtmlConverter object:
conv = html2pdfr::html_converter()
HtmlConverter$urlToPdf()
Convert HTML document from a URL to a PDF document.
The URL is assumed to be a complete document. 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.
J = html2pdfr::JavaApi$get() J$HtmlConverter$urlToPdf(htmlUrl, outFile, cssSelector, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter) # this method is also exposed as a package function: html2pdfr::url_to_pdf(htmlUrl, outFile, cssSelector, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter)
htmlUrl the URL - (java expects a RCharacter)
outFile the full path of the output file - (defaulting to ‘tempfile(’html2pdfr_')') - (java expects a RFile)
cssSelector the part of the page you want to convert to PDF. - (defaulting to 'NA_character_') - (java expects a RCharacter)
xMarginInches page width margins - (defaulting to 'NA_real_') - (java expects a RNumeric)
yMarginInches page height margins - (defaulting to 'NA_real_') - (java expects a RNumeric)
maxWidthInches what is the maximum allowable width? - (defaulting to 'NA_real_') - (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 'NA_real_') - (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')') - (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) url_to_pdf('https://cran.r-project.org/banner.shtml')
HtmlConverter$fileToPdf()
Convert HTML document from a local file to a PDF document.
The HTML in 'inFile' is assumed to be a complete document. Relative references are resolved with reference to the HTML file on the file system, so correctly located images etc whould be picked up without requiring a server. 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.
J = html2pdfr::JavaApi$get() J$HtmlConverter$fileToPdf(inFile, outFile, cssSelector, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter) # this method is also exposed as a package function: html2pdfr::file_to_pdf(inFile, outFile, cssSelector, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter)
inFile the full path the the HTML file - (java expects a RCharacter)
outFile the full path of the output file - (defaulting to ‘tempfile(’html2pdfr_')') - (java expects a RFile)
cssSelector the part of the page you want to convert to PDF. - (defaulting to 'NA_character_') - (java expects a RCharacter)
xMarginInches page width margins - (defaulting to 'NA_real_') - (java expects a RNumeric)
yMarginInches page height margins - (defaulting to 'NA_real_') - (java expects a RNumeric)
maxWidthInches what is the maximum allowable width? - (defaulting to 'NA_real_') - (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 'NA_real_') - (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')') - (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 written to (with extension '.pdf' or '.png' if outFile did not have an extension).
library(testthat) dest = tempfile(fileext='.html') download.file('https://cran.r-project.org/banner.shtml', destfile = dest) file_to_pdf(dest)
HtmlConverter$htmlDocumentToPdf()
Convert HTML document from a string to a PDF document.
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.
J = html2pdfr::JavaApi$get() J$HtmlConverter$htmlDocumentToPdf(html, outFile, baseUri, cssSelector, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter) # this method is also exposed as a package function: html2pdfr::html_document_to_pdf(html, outFile, baseUri, cssSelector, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter)
html the html document as a string - (java expects a RCharacter)
outFile the full path of the output file - (defaulting to ‘tempfile(’html2pdfr_')') - (java expects a RFile)
baseUri the URI from which to interpret relative links in the html content. - (defaulting to 'NA_character_') - (java expects a RCharacter)
cssSelector the part of the page you want to convert to PDF. - (defaulting to 'NA_character_') - (java expects a RCharacter)
xMarginInches page width margins - (defaulting to 'NA_real_') - (java expects a RNumeric)
yMarginInches page height margins - (defaulting to 'NA_real_') - (java expects a RNumeric)
maxWidthInches what is the maximum allowable width? - (defaulting to 'NA_real_') - (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 'NA_real_') - (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')') - (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 written to (with extension '.pdf' or '.png' if outFile did not have an extension).
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/')
HtmlConverter$htmlFragmentToPdf()
Render HTML fragment from a string to a PDF image.
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.
J = html2pdfr::JavaApi$get() J$HtmlConverter$htmlFragmentToPdf(htmlFragment, outFile, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter) # this method is also exposed as a package function: html2pdfr::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)
## ----------------------------------- ## Check library dependencies for html2pdfr ## ----------------------------------- html2pdfr::JavaApi$installDependencies() ## ----------------------------------- ## Construct a html2pdfr Java API instance ## ----------------------------------- J = html2pdfr::JavaApi$get() # or a more verbose configuration # J = html2pdfr::JavaApi$get("DEBUG") ## ----------------------------------- ## Method `J$HtmlConverter$new(...)` ## ----------------------------------- ## Not run: # no example given - appropriate parameter values must be provided: J$HtmlConverter$new(fontfiles) # or alternatively: html2pdfr::new(fontfiles) ## End(Not run) ## ----------------------------------- ## Method `J$HtmlConverter$htmlConverter(...)` ## Aliased as `html2pdfr::html_converter(...)` ## ----------------------------------- conv = html2pdfr::html_converter() ## ----------------------------------- ## Method `J$HtmlConverter$urlToPdf(...)` ## Aliased as `html2pdfr::url_to_pdf(...)` ## ----------------------------------- library(testthat) url_to_pdf('https://cran.r-project.org/banner.shtml') ## ----------------------------------- ## Method `J$HtmlConverter$fileToPdf(...)` ## Aliased as `html2pdfr::file_to_pdf(...)` ## ----------------------------------- library(testthat) dest = tempfile(fileext='.html') download.file('https://cran.r-project.org/banner.shtml', destfile = dest) file_to_pdf(dest) ## ----------------------------------- ## Method `J$HtmlConverter$htmlDocumentToPdf(...)` ## Aliased as `html2pdfr::html_document_to_pdf(...)` ## ----------------------------------- 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/') ## ----------------------------------- ## Method `J$HtmlConverter$htmlFragmentToPdf(...)` ## Aliased as `html2pdfr::html_fragment_to_pdf(...)` ## ----------------------------------- 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)
## ----------------------------------- ## Check library dependencies for html2pdfr ## ----------------------------------- html2pdfr::JavaApi$installDependencies() ## ----------------------------------- ## Construct a html2pdfr Java API instance ## ----------------------------------- J = html2pdfr::JavaApi$get() # or a more verbose configuration # J = html2pdfr::JavaApi$get("DEBUG") ## ----------------------------------- ## Method `J$HtmlConverter$new(...)` ## ----------------------------------- ## Not run: # no example given - appropriate parameter values must be provided: J$HtmlConverter$new(fontfiles) # or alternatively: html2pdfr::new(fontfiles) ## End(Not run) ## ----------------------------------- ## Method `J$HtmlConverter$htmlConverter(...)` ## Aliased as `html2pdfr::html_converter(...)` ## ----------------------------------- conv = html2pdfr::html_converter() ## ----------------------------------- ## Method `J$HtmlConverter$urlToPdf(...)` ## Aliased as `html2pdfr::url_to_pdf(...)` ## ----------------------------------- library(testthat) url_to_pdf('https://cran.r-project.org/banner.shtml') ## ----------------------------------- ## Method `J$HtmlConverter$fileToPdf(...)` ## Aliased as `html2pdfr::file_to_pdf(...)` ## ----------------------------------- library(testthat) dest = tempfile(fileext='.html') download.file('https://cran.r-project.org/banner.shtml', destfile = dest) file_to_pdf(dest) ## ----------------------------------- ## Method `J$HtmlConverter$htmlDocumentToPdf(...)` ## Aliased as `html2pdfr::html_document_to_pdf(...)` ## ----------------------------------- 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/') ## ----------------------------------- ## Method `J$HtmlConverter$htmlFragmentToPdf(...)` ## Aliased as `html2pdfr::html_fragment_to_pdf(...)` ## ----------------------------------- 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)
The URL is assumed to be a complete document. 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.
url_to_pdf( htmlUrl, outFile, cssSelector, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter )
url_to_pdf( htmlUrl, outFile, cssSelector, xMarginInches, yMarginInches, maxWidthInches, maxHeightInches, formats, pngDpi, converter )
htmlUrl |
htmlUrl the URL - (java expects a RCharacter) |
outFile |
outFile the full path of the output file - (defaulting to ‘tempfile(’html2pdfr_')') - (java expects a RFile) |
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) |
RCharacterVector: the filename(s) written to (with extension '.pdf' or '.png' if outFile did not have an extension).
library(testthat) url_to_pdf('https://cran.r-project.org/banner.shtml')
library(testthat) url_to_pdf('https://cran.r-project.org/banner.shtml')