How	  a	  cupsfilter	  made	  a	  hard	    web	  conversion	  easier	  
100s	  of	  web	  page	  HTML	  reports	  to	  convert	  to	  PDF	  
How	  do	  I	  do	  it?	  
Manually?	  
Buy	  a	  Tool	  
Some	  other	  way...	  
Google	  is	  your	  friend…	  
First	  AIempt:	  #FAIL	  Landscape	  VS	  Portrait;	  data	  missing/cut	  off;	  borders	  not	  right	  
RTFM	  $ man convert!No manual entry for convert!
Idea:	  What	  if	  convert,	  is	  something	  else	                                             SSck	  Bug	  
*NIX	  gives	  us	  symbolic	  links.	  $ ls -ln convert!lrwxr-xr-x 1 0 0 20 Aug 14 2009convert -> /usr/sbin/cupsfilter!
Is	  there	  a	  manpage	  for	  cupsfilter?cupsfilter(8)                                Apple Inc.                        ...
OpSons? 	  	  /System/Library/Printers/Libraries/convert!Usage: convert [ options ]!Options:!  -e                   Use ev...
Tweak	  #1:	  OpSons	  Cupsfilter	  uses	  –o	  to	  set	  the	  opSons;	  convert	  uses	  -­‐a	  
Tweak	  #2:	  Media	  formats	  Media	  format	  opSons	  were	  "LeIer"	  "Legal"	  and	  "A4"	  but	  A4	  worked	  best...
What	  opSons	  did	  I	  need?	  /System/Library/Printers/Libraries/convert !-f   filename.htm !-o   filename.pdf !-a   l...
Working	  Example:	  /System/Library/Printers/Libraries/convert
-f   contactForm.html !-o   contactForm.pdf !-a   landscap...
Need	  to	  automate	  ConverSng	  hundreds	  of	  files.	  Shell	  to	  the	  rescue!	  
Shell	  out	  a	  soluSon	  for name in `ls *.htm` ; do !   /System/Library/Printers/Libraries/convert !   -f $name -o `ec...
Room	  for	  improvement?	  •  Paul	  Hankin	  suggested	  this	  change	  for	  the	     subsStuSon	  to	  automate	  the...
Victory!	  World	  is	  saved;	  the	  birds	  are	  singing,	  the	  rainbows	  are	  out,	  the	  sun	  is	  shining.	  ...
CreaSve	  Commons	  Imagery	  List	  These	  images	  are	  CreaSve	  Commons	  licensed	  images	  I	  found	  on	  Flick...
How a Cupsfilter Made a Hard Web Conversion Easier
Upcoming SlideShare
Loading in …5
×

How a Cupsfilter Made a Hard Web Conversion Easier

3,453 views

Published on

Greg Ostravich's presentation at DOSUG Ignite 2011 on how to use a Cupsfilter to batch convert files to PDF.

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,453
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

How a Cupsfilter Made a Hard Web Conversion Easier

  1. 1. How  a  cupsfilter  made  a  hard   web  conversion  easier  
  2. 2. 100s  of  web  page  HTML  reports  to  convert  to  PDF  
  3. 3. How  do  I  do  it?  
  4. 4. Manually?  
  5. 5. Buy  a  Tool  
  6. 6. Some  other  way...  
  7. 7. Google  is  your  friend…  
  8. 8. First  AIempt:  #FAIL  Landscape  VS  Portrait;  data  missing/cut  off;  borders  not  right  
  9. 9. RTFM  $ man convert!No manual entry for convert!
  10. 10. Idea:  What  if  convert,  is  something  else   SSck  Bug  
  11. 11. *NIX  gives  us  symbolic  links.  $ ls -ln convert!lrwxr-xr-x 1 0 0 20 Aug 14 2009convert -> /usr/sbin/cupsfilter!
  12. 12. Is  there  a  manpage  for  cupsfilter?cupsfilter(8) Apple Inc. cupsfilter(8)!NAME! cupsfilter - convert a file to another format using cups filters!SYNOPSIS! cupsfilter [ -c config-file ] [ -e ] -j job-id[,N] [ -m mime/type ] [ -n copies ] [ -o! name=value ] [ -p filename.ppd ] [ -t title ] filename!DESCRIPTION! cupsfilter is a front-end to the CUPS filter subsystem which allows you to convert a file to! a specific format, just as if you had printed the file through CUPS. By default, cupsfilter! generates a PDF file.!OPTIONS! -c config-file! Uses the named cupsd.conf configuration file.! -e! Use every filter from the PPD file.! -j job-id[,N]! Converts document N from the specified job. If N is omitted, document 1 is converted.! -m mime/type! Specifies the destination file type. The default file type is application/pdf. Use! printer/foo to convert to the printer format defined by the filters in the PPD file.! -n copies! Specifies the number of copies to generate.! -o name=value! Specifies options to pass to the CUPS filters.! -p filename.ppd! Specifies the PPD file to use.!
  13. 13. OpSons?    /System/Library/Printers/Libraries/convert!Usage: convert [ options ]!Options:! -e Use every filter from the PPD file! -f filename Set file to be converted (otherwise stdin)! -o filename Set file to be generated (otherwise stdout)! -i mime/type Set input MIME type (otherwise auto-typed)! -j mime/type Set output MIME type (otherwise application/pdf)! -P filename.ppd Set PPD file! -a name=value ... Set option(s)! -U username Set username for job! -J title Set title! -c copies Set number of copies! -u Remove the PPD file when finished! -D Remove the input file when finished!/usr/sbin/cupsfilter!Usage: cupsfilter -m mime/type [ options ] filename!Options:! -c cupsd.conf Set cupsd.conf file to use! -e Use every filter from the PPD file! -j job-id[,N] Filter file N from the specified job (default is file 1)! -n copies Set number of copies! -o name=value Set option(s)! -p filename.ppd Set PPD file! -t title Set title!
  14. 14. Tweak  #1:  OpSons  Cupsfilter  uses  –o  to  set  the  opSons;  convert  uses  -­‐a  
  15. 15. Tweak  #2:  Media  formats  Media  format  opSons  were  "LeIer"  "Legal"  and  "A4"  but  A4  worked  best.  
  16. 16. What  opSons  did  I  need?  /System/Library/Printers/Libraries/convert !-f filename.htm !-o filename.pdf !-a landscape !-a scaling=75 !-a media=A4!
  17. 17. Working  Example:  /System/Library/Printers/Libraries/convert
-f contactForm.html !-o contactForm.pdf !-a landscape !-a scaling=75 !-a media=A4!
  18. 18. Need  to  automate  ConverSng  hundreds  of  files.  Shell  to  the  rescue!  
  19. 19. Shell  out  a  soluSon  for name in `ls *.htm` ; do ! /System/Library/Printers/Libraries/convert ! -f $name -o `echo $name ! | sed s/htm/pdf/` ! -a landscape -a scaling=75 -a media=A4; !done !
  20. 20. Room  for  improvement?  •  Paul  Hankin  suggested  this  change  for  the   subsStuSon  to  automate  the  conversion:  $ {name/htm/pdf}  instead  of  back  quoSng   using  sed  •  Use  cupsfilter  directly;  specify  the  opSons   from  the  manpage.  
  21. 21. Victory!  World  is  saved;  the  birds  are  singing,  the  rainbows  are  out,  the  sun  is  shining.   *NIX  variant  (OS  X)  to  the  rescue!   I  could  have  used  OS  X,  Linux,  or  CygWin  on  a  PC  for  this.    Ran  in  an  hour  and  some  change  for  100s  of  files  in  a  few  different  directories.  
  22. 22. CreaSve  Commons  Imagery  List  These  images  are  CreaSve  Commons  licensed  images  I  found  on  Flickr  (through  a  Yahoo  search)  from  the  users  listed  below.  The  excepSons  are  the  Adobe  ™  icon  taken  from  the  Adobe  ™  website  and  the  wikipedia  page  where  I  got  the  Paper  image  from.  •  Reports  image:  artnoose  •  QuesSon  Marks:  crystaljingsr  •  Manual  labor/man  digging  a  ditch:  worldbank  •  Chisels:  cfa  •  Australian  Web  Bridge:  Smmythesuk  •  Broken  Bridge  (#FAIL):  ghostv  •  Light  Bulb  Idea:  preef  •  SSck  bug:  safoocat  •  Swirls  for  “opSons”  page:  kymberlyanne  •  Paper  size  image:   hIp://en.wikipedia.org/wiki/File:A_size_illustraSon2_with_leIer_and_legal.svg  •  Super  Hero  clip-­‐art:  hIp://www.clker.com/  •  Rainbow:  homer4k  

×