Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NielsSteensma/Dhalang
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: TapInspect/Dhalang
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 12 commits
  • 3 files changed
  • 3 contributors

Commits on May 30, 2020

  1. Copy the full SHA
    2469666 View commit details
  2. Merge pull request #1 from TapInspect/timeouts_and_media_type

    bump timeout time and force media type to screen
    jznadams authored May 30, 2020
    Copy the full SHA
    d35a70b View commit details

Commits on Jun 24, 2020

  1. Merge branch 'master' of https://github.com/NielsSteensma/Dhalang int…

    …o NielsSteensma-master
    
    Conflicts:
    	lib/js/pdfgenerator.js
    jznadams committed Jun 24, 2020
    Copy the full SHA
    b04b48b View commit details
  2. Copy the full SHA
    bccc58c View commit details
  3. Copy the full SHA
    cc2adfa View commit details

Commits on Jun 25, 2020

  1. Fix puppeteer path

    jznadams committed Jun 25, 2020
    Copy the full SHA
    45c1cd2 View commit details

Commits on Oct 22, 2020

  1. Merge pull request #3 from NielsSteensma/master

    Update from base repo
    jznadams authored Oct 22, 2020
    Copy the full SHA
    6b058a7 View commit details

Commits on Oct 30, 2020

  1. Merge branch 'master' into pullrequests/NielsSteensma/master

    # Conflicts:
    #	lib/js/dhalang.js
    #	lib/js/pdf-generator.js
    jznadams committed Oct 30, 2020
    Copy the full SHA
    ecfff9c View commit details
  2. Merge pull request #5 from TapInspect/pullrequests/NielsSteensma/master

    Pullrequests/niels steensma/master
    jznadams authored Oct 30, 2020
    Copy the full SHA
    95a9393 View commit details
  3. Copy the full SHA
    9780ed3 View commit details

Commits on May 25, 2021

  1. Copy the full SHA
    8d8c03e View commit details
  2. Merge pull request #6 from TapInspect/get_url_as_file

    Add #get_url_as_file
    jznadams authored May 25, 2021
    Copy the full SHA
    3d9875f View commit details
Showing with 31 additions and 4 deletions.
  1. +29 −3 lib/PDF.rb
  2. +1 −1 lib/js/dhalang.js
  3. +1 −0 lib/js/pdf-generator.js
32 changes: 29 additions & 3 deletions lib/PDF.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Dhalang
# Allows consumers of this library to create PDFs with Puppeteer.
# Allows consumers of this library to create PDFs with Puppeteer.
class PDF
PUPPETEER_SCRIPT_PATH = File.expand_path('../js/pdf-generator.js', __FILE__).freeze
private_constant :PUPPETEER_SCRIPT_PATH

# Captures the full webpage under the given url as PDF.
#
# @param [String] url The url to get as PDF.
@@ -33,7 +33,33 @@ def self.get_from_html(html, options = {})
return binary_pdf_content
end



# Captures the full webpage under the given url as PDF
# Useful when creating dynamic content, for example invoices.
#
# @param [String] url The url to get as PDF.
# @param [String] output_file A file in which to store the PDF data
def self.get_from_url_as_file(url, output_file, options = {})
Puppeteer.visit(url, PUPPETEER_SCRIPT_PATH, output_file.path, "pdf", options)
end


# Captures the full HTML as PDF
# Useful when creating dynamic content, for example invoices.
#
# @param [String] html The html to get as PDF.
# @param [String] output_file A file in which to store the PDF data
def self.get_from_html_as_file(html, output_file, options = {})
html_file = FileUtils.create_temp_file("html", html)
url = "file://" + html_file.path
begin
Puppeteer.visit(url, PUPPETEER_SCRIPT_PATH, output_file.path, "pdf", options)
ensure
FileUtils.delete(html_file)
end
end


# Groups and executes the logic for creating a PDF of a webpage.
#
# @param [String] url The url to create a PDF for.
2 changes: 1 addition & 1 deletion lib/js/dhalang.js
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ exports.getConfiguration = function () {
/**
* Launches Puppeteer and returns its instance.
* @param {string} puppeteerModulePath - The path puppeteer is under.
* @returns {Promise<Object>}
* @returns {Promise<Object>}
* The launched instance of Puppeteer.
*/
exports.launchPuppeteer = async function (puppeteerModulePath) {
1 change: 1 addition & 0 deletions lib/js/pdf-generator.js
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ const createPdf = async () => {
browser = await dhalang.launchPuppeteer(configuration.puppeteerPath);
const page = await browser.newPage();
await dhalang.configurePage(page, configuration.userOptions);
await page.emulateMediaType('screen');
await page.goto(configuration.webPageUrl, configuration.userOptions.navigationParameters);
await page.waitForTimeout(250);
await page.pdf({