From 6ca56001100432b56deb8af12897853d9bb05634 Mon Sep 17 00:00:00 2001 From: Marc Bachmann Date: Wed, 27 Jan 2016 00:51:39 +0100 Subject: [PATCH 1/5] Add node_modules to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c53f0b4..0e69430 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pdf !example/businesscard.pdf +node_modules From 2ce36eb0619f50c1068d21ddce8e440052ebb9a8 Mon Sep 17 00:00:00 2001 From: Marc Bachmann Date: Wed, 27 Jan 2016 00:52:52 +0100 Subject: [PATCH 2/5] Add custom header and footer support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit You can use
--- src/scripts/pdf_a4_portrait.coffee | 54 +++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/src/scripts/pdf_a4_portrait.coffee b/src/scripts/pdf_a4_portrait.coffee index 12aeb4e..a480d11 100755 --- a/src/scripts/pdf_a4_portrait.coffee +++ b/src/scripts/pdf_a4_portrait.coffee @@ -54,15 +54,40 @@ setTimeout -> # ------------------------------ getContent = -> page.evaluate -> + getElements = (doc, wildcard) -> + wildcardMatcher = new RegExp("#{wildcard}(.*)") + hasElements = false + elements = {} + $elements = document.querySelectorAll("[id*='#{wildcard}']") + for $elem in $elements + if match = $elem.attributes.id.value.match(wildcardMatcher) + hasElements = true + i = match[1] + elements[i] = $elem.outerHTML + + $elem.parentNode.removeChild($elem) + + if hasElements + return elements + + getElement = (doc, id) -> + if $elem = doc.getElementById(id) + html = $elem.outerHTML + $elem.parentNode.removeChild($elem) + return html + styles = document.querySelectorAll('link,style') styles = Array::reduce.call(styles, ((string, node) -> string+node.outerHTML),'') - if $header = document.getElementById('pageHeader') - header = $header.outerHTML - $header.parentNode.removeChild($header) - if $footer = document.getElementById('pageFooter') - footer = $footer.outerHTML - $footer.parentNode.removeChild($footer) + # Wildcard headers e.g.
or
+ header = getElements(document, 'pageHeader-') + footer = getElements(document, 'pageFooter-') + + # Default header and footer e.g.