Thread: Faxing HTML

    #1
  1. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,042
    Rep Power
    535

    Faxing HTML


    Hello, I am trying to fax some HTML. I will be using PHP to access the command prompt. I think I am close, but I am very new with Linux, and am hoping someone can help me put the following two together. Thanks

    Hylafax allows one to send a fax from the command line.
    Code:
    sendfax -n -m -f "John Doe" -d "555-555-1212" somefile.ps;
    htmldoc converts a html document to postscript document. I figured out how to save a HTML document as a PS document and could probably make this work, but I would rather not have to. Supposedly, there is something called a "filter" which will do it on the fly.
    Code:
    echo "<html><body><h1>Heading</h1><p>Some HTML output...</p></body></html>" | 
    htmldoc --format ps3 --bodyfont Helvetica --header ... --footer ... --webpage - | lpr
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    Two options:
    a) Have htmldoc output, not save to a file, then pipe it (with a |) into sendfax. Only works if htmldoc can write to stdout and sendfax can read from stdin.
    b) Have htmldoc save to a random temporary file, then have sendfax read from it. (Then delete the file.)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,042
    Rep Power
    535
    Thank you requinix,

    Really didn't want to save the file, have sendfax read it, then delete it unless I absolutely had to.

    It appears (given my limited Linux expertise) that htmldoc can write to stdout and sendfax can read from stdin.

    Pipe it with a |? Maybe in California, but I do not know if that is legal in Washington.

    Forgive me I will learn in time, but would you be willing to give me the command assuming that one could write to stdout and the other could read from stdin?

    Thank you, Michael
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,042
    Rep Power
    535
    Well, this turned out to be easy! I love this Linux thing!
    Code:
    echo "<html><body><h1>Heading</h1><p>Some HTML output...</p></body></html>" | 
    htmldoc --format ps3 --bodyfont Helvetica --header ... --footer ... --webpage - |
    sendfax -n -m -f "John Doe" -d "555-555-1212"
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,042
    Rep Power
    535
    One more question. When just sending a fax, I can include the file name (i.e. somefile.pdf).
    Code:
    sendfax -n -m -f "John Doe" -d "555-555-1212" somefile.pdf
    My fax server is on a different machine than somefile.pdf but is accessible at http://mysite.com/somefile.pdf. My workaround has been to save a copy of somefile.pdf on the fax server, but it would have been nice not to have to. I tried adding the url into the sendfax command, but it didn't work. Is there some sort of getFileFromUrl Linux command which can be piped to sendfax?

    Thanks again
  10. #6
  11. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    Use wget. It's a very powerful tool for retrieving stuff over HTTP (and more).
    Code:
    wget http://mysite.com/somefile.pdf -O - |
    sendfax -n -m -f "John Doe" -d "555-555-1212"
    Note: wget spits stuff out on stderr too. Use -s to disable it.

    If you used it with a webpage too,
    Code:
    wget http://mysite.com/somefile.htm -O - |
    htmldoc ... - |
    sendfax -n -m -f "John Doe" -d "555-555-1212"
    Once you get used to Unix's shells, you'll never see Windows' cmd.exe the same way again.
    Reminds me: I should probably learn PowerShell sometime...
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,042
    Rep Power
    535
    Wow, I like that wget!

    The following will not work but hopefully represents what I am trying to accomplish. I realize I am just piping the output of htmldoc to wget which doesn't make any sense.
    Code:
    echo "<html><body><p>Some HTML output to make the cover page...</p></body></html>" | 
    htmldoc --format ps3 --bodyfont Helvetica --header ... --footer ... --webpage - |
    wget http://mysite.com/mainfaxdocument.pdf -O - |
    sendfax -n -m -f "John Doe" -d "555-555-1212"
    Instead I somehow need to combine them. If I had both files on my local fax server, I could do the following which would work but I would rather not need to store the temporary files on my local fax server.
    Code:
    sendfax -n -m -f "John Doe" -d "555-555-1212" coverpage.ps mainfaxdocument.pdf
    Any way to do this without saving them on the local server?

    Thanks
  14. #8
  15. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,733
    Rep Power
    1959
    If you have two machines, you will have to split it up into two steps.

    Starting with last step, this will be the fax server. Here you will call wget to get the pdf file and then pipe it into the fax command.

    The first step is on the webserver, where you have to prepare the PDF file. For this you will have to create a script to run the htmldoc.

    htmldoc.org has an explanation/manual on how you can use HTMLDOC on a Web Server
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,042
    Rep Power
    535
    Thank you MrFujin,

    No, I was not clear. The PDF file on the webserver already exists as a PDF file, and I do not need to prepare the PDF file using htmldoc.

    The fax server is sent two fields (among a few others like a fax number) from the webserver:
    1. The URL to the PDF file located on the webserver
    2. Some HTML


    The fax server must then convert the recently received HTML into a PS or PDF file, and then send both the newly created PS file as well as the remote PDF file to sendfax.

    I can send either one or the other using stdin to sendfax and all works well, but not both at the same time.

    I can also save copies of both on the fax server and then use the alternative method for saving content to sendfax (is there a Linux term for this?) instead of stdin, and then delete them:
    sendfax -n -m -f "John Doe" -d "555-555-1212" coverpage.ps mainfaxdocument.pdf

    The second method works and I am okay with it, but I would like to learn the best way to do things like this.

    Thank you

IMN logo majestic logo threadwatch logo seochat tools logo