/******************************************************************************* Stata Weaver Package Version 1.0 Developed by E. F. Haghish (2014) Center for Medical Biometry and Medical Informatics University of Freiburg, Germany haghish@imbi.uni-freiburg.de July, 2014 Package Description the Weaver ado file includes several programs which allow you to create dynamic reports directly from Stata do-file editor in HTML and PDF formats. The codes are presented in the following order: 1) Weaver Writing Codes This part of the ado file includes the codes and commands that are used for writing and styling the report. In short, these are the codes that you will be using for writing the codes in the do-editor in Stata. 2) open Weaver The weaver codes and all of the options are presented in this part of the ado file. This part also includes most of the CSS codes that are used for styling the dynamic report. 3) close Weaver this part of the ado file includes the codes that are used for closing the report. In addition to Stata codes, it also inclused several JavaScript codes that are used for styling the report and also, adding some functions to the report. 4) report this part of the ado file includes the codes that generate the report. The Weaver Package comes with no warranty */ ******************************************************************************** /* Weaver Writing Codes */ ******************************************************************************** /* ---- markup & mp ---- */ *quietly creates a log file program define markup version 11 syntax [anything(name=smclfile id="The smclfile name is")] if "`r(status)'" == "on" { local h = length("`r(filename)'") local h = `h'-5 global log = substr("`r(filename)'",1,`h') qui set more off qui set linesize 80 } if "`r(status)'" ~= "on" { *define filename if "`smclfile'"~="" { global log `smclfile' } if "`smclfile'" == "" { global log markdown } qui set more off quietly log using $log , replace qui set linesize 80 } end program define mp version 11 markup `0' end /* ---- markdown & md ---- */ program markdown version 11 syntax [anything(name=smclfile id="The smclfile name is")], /// [erase] [html] [Pandoc(str)] //Global syntax processing *check if Pandoc's path is defined if "`pandoc'" ~= "" { confirm file `"`pandoc'"' } if "`pandoc'" == "" { if "`c(os)'"=="Windows" { local pandoc pandoc } if "`c(os)'"=="MacOSX" { local pandoc /usr/local/bin/pandoc cap confirm file "`pandoc'" } if "`c(os)'"=="Unix" { local pandoc /usr/bin/pandoc cap confirm file "`pandoc'" } } *default input file if "`smclfile'" == "" { *get the Pandoc default export file from "markup" command * which is the $log global confirm file $log.smcl cap qui log c di _n(2) *convert to HTML using MarkDoc global useMarkDoc useMarkDoc markdoc $log, export(html) replace erase confirm file $log.html *if WEAVER is in use, append the HTML file to canvas if "$weaver" != "" cap confirm file `"$weaver"' tempname canvas needle tempfile memo cap set linesize $width set more off *openning the canvas cap file open `canvas' using `"$weaver"', /// write text append *reading the exported html file cap file open `needle' using $log.html, read cap file read `needle' line /* weave the html text to the canvas */ while r(eof)==0 { cap file write `canvas' /// `"`line'"' _n cap file read `needle' line } } if "`smclfile'" ~= "" & "`html'"=="" { cap qui log c *convert to HTML using MarkDoc global useMarkDoc useMarkDoc markdoc `smclfile', export(html) replace `erase' confirm file "`smclfile'.html" *if WEAVER is in use, append the HTML file to canvas if "$weaver" != "" cap confirm file `"$weaver"' tempname canvas needle tempfile memo cap set linesize $width set more off *openning the canvas cap file open `canvas' using `"$weaver"', /// write text append *reading the exported html file cap file open `needle' using "`smclfile'.html", read cap file read `needle' line /* weave the html text to the canvas */ while r(eof)==0 { cap file write `canvas' `"`line'"' _n cap file read `needle' line } } if "`smclfile'" ~= "" & "`html'"=="html" { *confirm the html document confirm file "`smclfile'.html" *if WEAVER is in use, append the HTML file to canvas if "$weaver" != "" cap confirm file `"$weaver"' tempname canvas needle tempfile memo cap set linesize $width set more off *openning the canvas cap file open `canvas' using `"$weaver"', /// write text append *reading the exported html file cap file open `needle' using "`smclfile'.html", read cap file read `needle' line /* weave the html text to the canvas */ while r(eof)==0 { cap file write `canvas' /// `"`line'"' _n cap file read `needle' line } } macro drop pandoc macro drop useMarkDoc end program md version 11 markdown `0' end /* ---- knit & kn ---- */ * knit prints a text paragraph in

"text"

html format program define knit version 11 if "$weaver" != "" cap confirm file `"$weaver"' tempname canvas cap file open `canvas' using `"$weaver"', write text append cap file write `canvas' "

" cap file write `canvas' `"`0'"' cap file write `canvas' "

" _n /* give a notice if Weaver not in use, but not an error */ if "$weaver" == "" { di _newline di _dup(17) "-" di as text " Nothing to {help weave}!" di _newline(2) } end program define kn version 11 knit `0' end /* ---- div ---- */ * separates the codes from the results and shows them in separate boxes program define div version 11 set linesize $width if "$weaver" != "" cap confirm file `"$weaver"' tempname canvas needle tempfile memo /* open new log, run command and close log */ set linesize $width set more off /* saving the results in `memo' */ cap log c quietly log using `memo', replace text `0' cap quietly log close /* Using existing log */ if `"`r(filename)'"' != "" { set linesize $width cap quietly log using r(filename), append r(type) if r(status) != "on" quietly log r(status) } /* open the canvas and print the Stata codes in the code tag */ cap file open `canvas' using `"$weaver"', write text append cap file write `canvas' ""`"`0'"'"" /* openning the results tag */ cap file write `canvas' "" /* reading the results from the log file */ cap file open `needle' using `memo', read cap file read `needle' line /* writing the results to the html file */ while r(eof)==0 { cap file write `canvas' `"`line' "' _n cap file read `needle' line } /* closing the results tag */ cap file write `canvas' "" /* give a notice if Weaver not in use, but not an error */ if "$weaver" == "" { di _newline di _dup(17) "-" di as text " Nothing to {help weave}!" di _newline(2) } end /* ---- codes & cod ---- */ * show The Code and Hide the Results program codes version 11 qui `0' if "$weaver" != "" cap confirm file `"$weaver"' if "$style" == "elegant" { local add style="border-radius:10px;" } tempname canvas cap file open `canvas' using `"$weaver"', write text append cap file write `canvas' `" `0' "' _newline /* give a notice if Weaver not in use, but not an error */ if "$weaver" == "" { di _newline di _dup(17) "-" di as text " Nothing to {help weave}!" di _newline(2) } end program cod version 11 qui `0' if "$weaver" != "" cap confirm file `"$weaver"' if "$style" == "elegant" { local add style="border-radius:10px;" } tempname canvas cap file open `canvas' using `"$weaver"', write text append cap file write `canvas' `" `0' "' _newline /* give a notice if Weaver not in use, but not an error */ if "$weaver" == "" { di _newline di _dup(17) "-" di as text " Nothing to {help weave}!" di _newline(2) } end /* ---- results & res ---- */ * The result command only shows the results, eliminating the code program define results version 11 set linesize $width if "$weaver" != "" cap confirm file `"$weaver"' tempname canvas needle tempfile memo /* open new log, run command and close log */ set linesize $width set more off /* saving the results in `memo' */ cap log c quietly log using `memo', replace text `0' quietly log close /* Open previous log */ if `"`r(filename)'"' != "" { set linesize $width quietly log using r(filename), append r(type) if r(status) != "on" quietly log r(status) } /* open the canvas and print the Stata results in the results tag */ cap file open `canvas' using `"$weaver"', write text append cap file write `canvas' `""' /* reading the results from the log file */ cap file open `needle' using `memo', read cap file read `needle' line /* writing the results to the html file */ while r(eof)==0 { cap file write `canvas' `"`line' "' _n cap file read `needle' line } /* closing the results tag */ cap file write `canvas' "" /* give a notice if Weaver not in use, but not an error */ if "$weaver" == "" { di _newline di _dup(17) "-" di as text " Nothing to {help weave}!" di _newline(2) } end program define res version 11 set linesize $width if "$weaver" != "" cap confirm file `"$weaver"' tempname canvas needle tempfile memo /* open new log, run command and close log */ set linesize $width set more off /* saving the results in `memo' */ cap log c quietly log using `memo', replace text `0' quietly log close /* Open previous log */ if `"`r(filename)'"' != "" { set linesize $width quietly log using r(filename), append r(type) if r(status) != "on" quietly log r(status) } /* open the canvas and print the Stata results in the results tag */ cap file open `canvas' using `"$weaver"', write text append cap file write `canvas' `""' /* reading the results from the log file */ cap file open `needle' using `memo', read cap file read `needle' line /* writing the results to the html file */ while r(eof)==0 { cap file write `canvas' `"`line' "' _n cap file read `needle' line } /* closing the results tag */ cap file write `canvas' "" /* give a notice if Weaver not in use, but not an error */ if "$weaver" == "" { di _newline di _dup(17) "-" di as text " Nothing to {help weave}!" di _newline(2) } end /* ---- img ---- */ * importing graphs and images into the report. program define img version 11 syntax anything, [Width(numlist max=1 >0 <=1000)] /// [Height(numlist max=1 int >0 <=1000)] [left|center|right] if "$weaver" != "" { cap confirm file `"$weaver"' tempname canvas file open `canvas' using `"$weaver"', write text append if "$format" == "normal" & missing("`width'") { local width 694 } if "$format" == "normal" & missing("`height'") { local height 494 } if "$format" == "landscape" & missing("`width'") { local width 1020 } if "$format" == "landscape" & missing("`height'") { local height 694 } if "$format" == "normal" & `width' > 694 { display as error "image width cannot be more than 694 " /// "pixles, unless you choose the {help landscape} option " /// "from the {help weave} command" exit 198 } if "$format" == "normal" & `height' > 1000 { display as error "image height cannot be more than 1000 pixles" exit 198 } if "$format" == "landscape" & `width' > 1020 { display as error "image width cannot be more than 1000 pixles" exit 198 } if "$format" == "landscape" & `height' > 694 { display as error "image height cannot be more than 694 " /// "pixles, unless you {bf:remove} the {help landscape} " /// "option from the {help weave} command" exit 198 } *check that only one of the align options is selected if "`left'" == "left" & "`center'" == "center" | /// "`left'" == "left" & "`right'" == "right" | /// "`center'" == "center" & "`right'" == "right" { di as err `"only one of the {bf:left}, "' /// `"{bf:center}, or {bf:right} can be applied"' exit 198 } *defining the default image alignment if missing("`left'") & missing("`center'") & missing("`right'") { local left left } if "`left'" == "left" { file write `canvas' `""' _newline } if "`center'" == "center" { file write `canvas' `""' _newline } if "`right'" == "right" { file write `canvas' `""' _newline } } /* give a notice if Weaver not in use, but not an error */ if "$weaver" == "" { di _newline di _dup(17) "-" di as text " Nothing to {help weave}!" di _newline(2) } end /* ---- html code ---- */ * adds html code program define html version 11 if "$weaver" != "" cap confirm file `"$weaver"' tempname canvas cap file open `canvas' using `"$weaver"', write text append cap file write `canvas' `"`0'"' _n /* give a notice if Weaver not in use, but not an error */ if "$weaver" == "" { di _newline di _dup(17) "-" di as text " Nothing to {help weave}!" di _newline(2) } end /* ---- linebreak ---- */ * moves to the next line */ program define linebreak version 11 if "$weaver" != "" cap confirm file `"$weaver"' tempname canvas cap file open `canvas' using `"$weaver"', write text append cap file write `canvas' "
" _n /* give a notice if Weaver not in use, but not an error */ if "$weaver" == "" { di _newline di _dup(17) "-" di as text " Nothing to {help weave}!" di _newline(2) } end /* ---- pagebreak ---- */ * page break, moving to the next page (only appears in prints and PDF) */ program pagebreak if "$weaver" != "" cap confirm file `"$weaver"' tempname canvas cap file open `canvas' using `"$weaver"', write text append cap file write `canvas' `"
"' _n /* give a notice if Weaver not in use, but not an error */ if "$weaver" == "" { di _newline di _dup(17) "-" di as text " Nothing to {help weave}!" di _newline(2) } end /* ---- quote & quo ---- */ * creates a distinguished text box to make a point, summary, etc. program define quote version 11 if "$weaver" != "" cap confirm file `"$weaver"' tempname canvas cap file open `canvas' using `"$weaver"', write text append cap file write `canvas' `"

"' _n cap file write `canvas' `"`0'"' _n cap file write `canvas' "

" _n /* give a notice if Weaver not in use, but not an error */ if "$weaver" == "" { di _newline di _dup(17) "-" di as text " Nothing to {help weave}!" di _newline(2) } end program define quo version 11 quote `0' end ******************************************************************************** /* open Weaver */ ******************************************************************************** program define weave version 11 syntax using/, [append|replace] [Erase] [UNbreak] [Title(str)] /// [AUthor(str)] [AFFiliation(str)] [ADDress(str)] [Date] /// [RUNhead(str)] [SUMmary(str)] [CONTents] [LANDscape] /// [STYle(name)] [NOScheme] [Font(str)] [Printer(name)] [SETpath(str)] //CHECKING THE COMMANDS AND OPTIONS *Store the current scheme global savescheme `c(scheme)' /* check if the HTML canvas is in use */ if "$weaver" != "" { di as err `"You are still weaving the $weaver canvas. "' /// `"To begin a new canvas, type {stata weavend} to close "' /// `"the current canvas."' exit 110 } /*check that append and replace options are not used together */ if "`append'" != "" & "`replace'" != "" { di as err `"Oops! You cannot use {bf:append} and "' /// `"{bf:replace} options together."' exit 198 } if "`erase'" == "erase" { global erase erase } if `"`landscape'"' == "landscape" { global format landscape global width 150 } if `"`landscape'"' != "landscape" { global format normal global width 90 } *check the printer names if "`printer'" == "princexml" { local printer prince } if "`printer'" == "wk" { local printer wkhtmltopdf } if "`printer'" ~= "" & "`printer'" ~= "prince" & "`printer'" /// ~= "wkhtmltopdf" { di as err "Printer name can be {bf:prince} or {bf:wkhtmltopdf}}" exit 198 } /*check that printer and setpath both are used together */ if "`printer'" == "" & "`setpath'" != "" { di as err `"If you specify the {bf:ptinter path}"' /// `" you should also use the {bf:printer(name) option }"' exit 198 } *define the printer's global global printer `printer' *check the Printer path if "`setpath'" ~= "" { global path `"`setpath'"' confirm file "$setpath" } /* Setup Style & Font */ global style `style' if "`style'" ~= "" & "`style'" ~= "modern" & "`style'" ~= "minimal" /// & "`style'" ~= "elegant" & "`style'" ~= "classic" /// & "`style'" ~= "stata" { di as err `"Style option can be {bf:classic}, {bf:modern},"' /// `" {bf:stata}, {bf:elegant}, or {bf:minimal}"' exit 198 } if "`style'" == "" | "`style'" == "modern" { if "`font'"=="" & "`printer'"=="prince" { local font Calibri, Arial, Helvetica, sans-serif } if "`font'"=="" & "`printer'"~="prince" { local font Arial, Helvetica, sans-serif } if "`noscheme'" == "" { set scheme s2color8 } } if "`style'" == "classic" { if "`font'"=="" { local font Times New Roman, Times, serif } if "`noscheme'" == "" { set scheme s1color } } if "`style'" == "minimal" { if "`font'"=="" { local font Courier New, Courier, monospace } if "`noscheme'" == "" { set scheme lean2 } } if "`style'" == "elegant" { if "`font'"=="" & "`printer'"=="prince" { local font Calibri, Arial, Helvetica, sans-serif } if "`font'"=="" & "`printer'"~="prince" { local font Arial, Helvetica, sans-serif } if "`noscheme'" == "" { set scheme s1color } } if "`style'" == "stata" { if "`font'"=="" & "`printer'"=="prince" { local font Calibri, Arial, Helvetica, sans-serif } if "`font'"=="" & "`printer'"~="prince" { local font Arial, Helvetica, sans-serif } if "`noscheme'" == "" { set scheme s2color } } /*----- DEFINING THE FILE NAMES -----*/ /* PDF file */ global pdfdoc `"`using'.pdf"' /* CANVAS file*/ local using `"`using'.html"' /* HTML file */ global htmldoc `"`using'"' /* creating the HTML canvas */ tempname canvas capture file open `canvas' using `"`using'"', write text /// `append' `replace' /* checking if the HTML canvas already exists */ if _rc == 602 { di as err `"Oops! `using' canvas is already weaved!"' /// `"Use {bf:append} or {bf:replace} options to extend or"' /// `"replace the existing canvas."' exit 602 } if "`append'" == "" { /* defining HTML5 */ file write `canvas' `""' _n file write `canvas' `""' _n file write `canvas' "" _n file write `canvas' `""' _n if `"`title'"' ~= "" { file write `canvas' `"`title'"' _n } /* MODERN (DEFAULT) STYLE */ if "`style'" == "" | "`style'" == "modern" { file write `canvas' _n(2) "" _newline(2) /// `"" _newline(4) } /* Stata STYLE */ if "`style'" == "stata" { file write `canvas' _n(2) "" _newline(2) /// `"" _newline(4) } /* CLASSIC STYLE */ if "`style'" == "classic" { file write `canvas' _n(2) "" _newline(2) /// `"" _newline(4) } /* MINIMAL STYLE */ if "`style'" == "minimal" { file write `canvas' _n(2) "" _newline(2) /// `"" _newline(4) } /* ELEGANT STYLE */ if "`style'" == "elegant" { file write `canvas' _n(2) "" _newline(2) /// `"" _newline(4) } /*----- CSS STYLING -----*/ file write `canvas' _n(2) /// "" _newline(2) /// `"" _newline(4) /* LANDSCAPE MODE STYLING */ *this options are used to style the landscape mode document. if `"`landscape'"' == "landscape" { file write `canvas' `"" _newline(4) } else { file write `canvas' `"" _newline(4) } /* ending the HTML head tag */ file write `canvas' "" _n file write `canvas' `""' _newline /* defining the title of the report, which appears on the first page */ if `"`title'"' != "" { file write `canvas' `"
`title'
"' _n } else { file write `canvas' "
" _newline } /* author name */ if `"`author'"' ~= "" { file write `canvas' `"
`author'
"' _n } /* adding the author's affiliation on the fitst page */ if `"`affiliation'"' ~= "" { file write `canvas' `"
`affiliation'
"' _n } /* adding the author email/contact information in the fitst page */ if `"`address'"' ~= "" { file write `canvas' `"
`address'
"' _n } /* adding the date in the fitst page */ if "`date'" == "date" { file write `canvas' /// `""' /// `""' _n(2) } /* adding the summary in the first page */ if `"`summary'"' ~= "" { file write `canvas' _newline(4) _n file write `canvas' `"

`summary'

"' _n } if "`unbreak'" == "" { file write `canvas' `"
"' _n } /* styling the first page, if "break" option selected */ if "`unbreak'" == "unbreak" { file write `canvas' /// `""' _n } if "`contents'" == "contents" & "`unbreak'" == "" { file write `canvas' /// `"Contents"' _n /// `"
"' _n /// `"
"' _n } if "`contents'" == "contents" & "`unbreak'" == "unbreak" { file write `canvas' /// `""' _n /// `"
"' _n /// `""' _n(4) } } /* THIS IS THE TABLE OF CONTENT JAVASCRIPT */ /* * Dynamic Table of Contents script * Based on a program by Matt Whitlock http://www.whitsoftdev.com * Rewritten and eddited by E. F. Haghish http://www.haghish.com */ file write `canvas' "" _newline(2) global weaver `"`using'"' di _newline(5) di as txt "| | / /__ ____ __ _____ _____ " di as txt "| | /| / / _ \/ __ `/ | / / _ \/ ___/ " di as txt "| |/ |/ / __/ /_/ /| |/ / __/ / " di as txt "|__/|__/\___/\__,_/ |___/\___/_/ produced " /// `"{bf:{browse `"${htmldoc}"'}} "' _n end ******************************************************************************** /* close Weaver */ ******************************************************************************** program define weavend version 11 /* checking that the Weaver is currently weaving a canvas */ if "$weaver" == "" { di as err "Oops! You can't close the Weaver because you haven't been weaving anything! Begin weaving by using {stata weave} command. See {help weaver} package for help." exit 111 } else { cap confirm file `"$weaver"' if _rc == 0 { tempname canvas file open `canvas' using `"$weaver"', write text append /* ---- Markdown Syntax ---- */ file write `canvas' _newline(2) "" _newline(2) /// "" _newline(2) /* Add Jquery */ file write `canvas' `" "' _newline /* ADDING THE JQUERY */ file write `canvas' " "' _newline * ---- JavaScript code for date (alternative to !date) ---- */ file write `canvas' _newline(2) "" _newline(2) /// "" _newline(2) /* ---- JavaScript "Easing" Code ---- */ file write `canvas' _newline(2) "" _newline(2) /* THIS IS THE SMOOTH ZOOM JAVASCRIPT */ /* * Smoothzoom * http://kthornbloom.com/smoothzoom * * Copyright 2014, Kevin Thornbloom * Free to use and modify under the MIT license. * http://www.opensource.org/licenses/mit-license.php */ file write `canvas' "" _newline(4) /* ADDING THE SMOOTH ZOOM SCRIPT */ file write `canvas' " " _newline file write `canvas' _n "" _n file write `canvas' _n "" _n } } if "$format" == "landscape" { local add --orientation Landscape --margin-right 13mm /// --margin-left 6mm /// --margin-top 12mm /// --margin-bottom 6mm } if "$format" ~= "landscape" { local add /// --margin-right 13mm /// --margin-left 6mm } /* SETTING THE PDF PRINTER */ * Microsoft Windows if "`c(os)'"=="Windows" { *Prince and the default printer setting if "$printer" == "prince" | "$printer" == "" { if "$path" == "" { cap shell /// C:\program files\prince\engine\bin\prince.exe /// --no-network --javascript "$htmldoc" -o "$pdfdoc" } if "$path" ~= "" { cap shell $path --no-network --javascript /// "$htmldoc" -o "$pdfdoc" } } if "$printer" == "wkhtmltopdf" { if "$path" == "" { shell /// c:\program files\wkhtmltopdf\bin\wkhtmltopdf.exe /// --footer-center [page] --footer-font-size 10 /// `add' /// "$htmldoc" "$pdfdoc" } if "$path" ~= "" { shell $path /// --footer-center [page] --footer-font-size 10 /// `add' /// "$htmldoc" "$pdfdoc" } } *open the pdfdoc winexec explorer "$pdfdoc" di as txt _newline(2) di as txt "| | / /__ ____ __ _____ _____ " di as txt "| | /| / / _ \/ __ `/ | / / _ \/ ___/ " di as txt "| |/ |/ / __/ /_/ /| |/ / __/ / " if "$erase"~="erase" { di as txt `"|__/|__/\___/\__,_/ |___/\___/_/ "' /// `"{it:produced {bf:{browse `"${pdfdoc}"'}} and {bf:{browse `"${htmldoc}"'}} reports}"' } if "$erase"=="erase" { di as txt `"|__/|__/\___/\__,_/ |___/\___/_/ "' /// `"{it:produced {bf:{browse `"${pdfdoc}"'}} }"' } } * Macintosh if "`c(os)'"=="MacOSX" { *Prince and the default printer setting if "$printer" == "prince" | "$printer" == "" { if "$path" == "" { cap shell /usr/local/bin/prince /// --no-network --javascript "$htmldoc" -o "$pdfdoc" } if "$path" ~= "" { cap shell $path --no-network --javascript /// "$htmldoc" -o "$pdfdoc" } } if "$printer" == "wkhtmltopdf" { if "$path" == "" { shell /usr/local/bin/wkhtmltopdf /// --footer-center [page] --footer-font-size 10 /// `add' /// "$htmldoc" "$pdfdoc" } if "$path" ~= "" { shell $path /// --footer-center [page] --footer-font-size 10 /// `add' /// "$htmldoc" "$pdfdoc" } } *open the pdfdoc shell open "$pdfdoc" di as txt _newline(2) di as txt "| | / /__ ____ __ _____ _____ " di as txt "| | /| / / _ \/ __ `/ | / / _ \/ ___/ " di as txt "| |/ |/ / __/ /_/ /| |/ / __/ / " if "$erase"~="erase" { di as txt `"|__/|__/\___/\__,_/ |___/\___/_/ "' /// `"{it:produced {bf:{browse `"${pdfdoc}"'}} and {bf:{browse `"${htmldoc}"'}} reports}"' } if "$erase"=="erase" { di as txt `"|__/|__/\___/\__,_/ |___/\___/_/ "' /// `"{it:produced {bf:{browse `"${pdfdoc}"'}}}"' } } *Linux if "`c(os)'"=="Unix" { *Prince and the default printer setting if "$printer" == "prince" | "$printer" == "" { if "$path" == "" { cap shell /usr/bin/prince /// --no-network --javascript "$htmldoc" -o "$pdfdoc" } if "$path" ~= "" { cap shell $path --no-network --javascript /// "$htmldoc" -o "$pdfdoc" } } if "$printer" == "wkhtmltopdf" { if "$path" == "" { shell /usr/bin/wkhtmltopdf /// --footer-center [page] --footer-font-size 10 /// `add' /// "$htmldoc" "$pdfdoc" } if "$path" ~= "" { shell $path /// --footer-center [page] --footer-font-size 10 /// `add' /// "$htmldoc" "$pdfdoc" } } *open the pdfdoc shell xdg-open "$pdfdoc" di as txt _newline(2) di as txt "| | / /__ ____ __ _____ _____ " di as txt "| | /| / / _ \/ __ `/ | / / _ \/ ___/ " di as txt "| |/ |/ / __/ /_/ /| |/ / __/ / " if "$erase"~="erase" { di as txt `"|__/|__/\___/\__,_/ |___/\___/_/ "' /// `"{it:produced {bf:{browse `"${pdfdoc}"'}} and {bf:{browse `"${htmldoc}"'}} reports}"' } if "$erase"=="erase" { di as txt `"|__/|__/\___/\__,_/ |___/\___/_/ "' /// `"{it:produced {bf:{browse `"${pdfdoc}"'}}}"' } } if "$erase"=="erase" { cap erase $htmldoc } *restore the original scheme cap set scheme $savescheme macro drop weaver macro drop format macro drop erase macro drop style macro drop savescheme end ******************************************************************************** /* Weaver reports */ ******************************************************************************** /* ---- report ---- */ /* create PDF report and opens it up */ program define report version 11 syntax [anything] [, Export(name) Printer(name) SETpath(str)] if "`anything'"~="" { global htmldoc `anything' } if "`export'"~="" { global pdfdoc `export'.pdf } /* SETTING THE PDF PRINTER */ if "$format" == "landscape" { local add --orientation Landscape --margin-right 13mm /// --margin-left 6mm /// --margin-top 12mm /// --margin-bottom 6mm } if "$format" ~= "landscape" { local add /// --margin-right 13mm /// --margin-left 6mm } /* SETTING THE PDF PRINTER */ * Microsoft Windows if "`c(os)'"=="Windows" { *Prince and the default printer setting if "$printer" == "prince" | "$printer" == "" { if "$path" == "" { cap shell /// C:\program files\prince\engine\bin\prince.exe /// --no-network --javascript "$htmldoc" -o "$pdfdoc" } if "$path" ~= "" { cap shell $path --no-network --javascript /// "$htmldoc" -o "$pdfdoc" } } if "$printer" == "wkhtmltopdf" { if "$path" == "" { shell /// c:\program files\wkhtmltopdf\bin\wkhtmltopdf.exe /// --footer-center [page] --footer-font-size 10 /// `add' /// "$htmldoc" "$pdfdoc" } if "$path" ~= "" { shell $path /// --footer-center [page] --footer-font-size 10 /// `add' /// "$htmldoc" "$pdfdoc" } } *open the pdfdoc winexec explorer "$pdfdoc" di as txt _newline(2) di as txt "| | / /__ ____ __ _____ _____ " di as txt "| | /| / / _ \/ __ `/ | / / _ \/ ___/ " di as txt "| |/ |/ / __/ /_/ /| |/ / __/ / " di as txt `"|__/|__/\___/\__,_/ |___/\___/_/ {it:produced {bf:{browse `"${pdfdoc}"'}} and {bf:{browse `"${htmldoc}"'}} reports}"' } * Macintosh if "`c(os)'"=="MacOSX" { *Prince and the default printer setting if "$printer" == "prince" | "$printer" == "" { if "$path" == "" { cap shell /usr/local/bin/prince /// --no-network --javascript "$htmldoc" -o "$pdfdoc" } if "$path" ~= "" { cap shell $path --no-network --javascript /// "$htmldoc" -o "$pdfdoc" } } if "$printer" == "wkhtmltopdf" { if "$path" == "" { shell /usr/local/bin/wkhtmltopdf /// --footer-center [page] --footer-font-size 10 /// `add' /// "$htmldoc" "$pdfdoc" } if "$path" ~= "" { shell $path /// --footer-center [page] --footer-font-size 10 /// `add' /// "$htmldoc" "$pdfdoc" } } *open the pdfdoc shell open "$pdfdoc" di as txt _newline(2) di as txt "| | / /__ ____ __ _____ _____ " di as txt "| | /| / / _ \/ __ `/ | / / _ \/ ___/ " di as txt "| |/ |/ / __/ /_/ /| |/ / __/ / " di as txt `"|__/|__/\___/\__,_/ |___/\___/_/ {it:produced {bf:{browse `"${pdfdoc}"'}} and {bf:{browse `"${htmldoc}"'}} reports}"' } *Linux if "`c(os)'"=="Unix" { *Prince and the default printer setting if "$printer" == "prince" | "$printer" == "" { if "$path" == "" { cap shell /usr/bin/prince /// --no-network --javascript "$htmldoc" -o "$pdfdoc" } if "$path" ~= "" { cap shell $path --no-network --javascript /// "$htmldoc" -o "$pdfdoc" } } if "$printer" == "wkhtmltopdf" { if "$path" == "" { shell /usr/bin/wkhtmltopdf /// --footer-center [page] --footer-font-size 10 /// `add' /// "$htmldoc" "$pdfdoc" } if "$path" ~= "" { shell $path /// --footer-center [page] --footer-font-size 10 /// `add' /// "$htmldoc" "$pdfdoc" } } *open the pdfdoc shell xdg-open "$pdfdoc" di as txt _newline(2) di as txt "| | / /__ ____ __ _____ _____ " di as txt "| | /| / / _ \/ __ `/ | / / _ \/ ___/ " di as txt "| |/ |/ / __/ /_/ /| |/ / __/ / " di as txt `"|__/|__/\___/\__,_/ |___/\___/_/ {it:produced {bf:{browse `"${pdfdoc}"'}} and {bf:{browse `"${htmldoc}"'}} reports}"' } end