Excel to PDF

Following my Word to PDF convertor script, here is the Excel version.

Prerequisites
MS Excel 2007
Office 2007 Save As PDF Plugin

Same rules apply. Copy and paste the code into notepad and save onto the desktop as ExceltoPdf.vbs.

<code>'Excel to PDF
'By John Reid
'(c) 2007 bloggingIT - http://ccgi.maxpower.plus.com/wp

'Feel free to use, modify, and redistribute - just leave the credits intact

'Quick Export to PDF
Const xlTypePDF = 0

if  Wscript.Arguments.Count &gt; 0 Then

 'Fire up MS Excel 2007
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set objExcel = CreateObject("Excel.Application")
 
 'Enumerate the passed in file names
 For i = 0 to wscript.arguments.count - 1
  Set objFile = objFSO.GetFile(WScript.Arguments(i))
  Set objDoc = objExcel.Workbooks.Open(WScript.Arguments(i),,TRUE)
  dirPath = objFSO.GetParentFolderName(objFile)
  fileBaseName = objFSO.GetBaseName(objFile)
  'Export to PDF using preferred settings
  pdf = objExcel.ActiveWorkbook.ExportAsFixedFormat (xlTypePDF,dirPath & "\" & fileBaseName & ".pdf")
  objExcel.ActiveWorkbook.Close(False)
 Next
 'Quit MS Excel
 objExcel.Quit
Else
 msgbox("You must select a file to convert")
End If</code>

Once saved, just select and drag any Excel document onto the script, and a PDF will be created in the same directory.

Yey!

Drag and Drop Convert Word to PDF

Sometimes I find that it’s useful to save my Word documents as PDFs.

After playing around with the Save As PDF plugin for Office, I decided that it would be cool if I could write a script to convert a job lot of Word documents.

Prerequisites
MS Word 2007
Save As PDF Office 2007 Plugin

Just copy and paste the code into Notepad and save the file as WordToPDF.vbs on your desktop.

<code>'Word to PDF
'By John Reid
'(c) 2007 bloggingIT - http://www.maxpower.plus.com
'Feel free to use, modify, and redistribute - just leave the credits intact
'Quick Export to PDF
Const wdExportAllDocument = 0
Const wdExportOptimizeForPrint = 0
Const wdExportDocumentContent = 0
Const wdExportFormatPDF = 17
Const wdExportCreateHeadingBookmarks = 1

if  Wscript.Arguments.Count > 0 Then
  'Fire up MS Word 2007
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objWord = CreateObject("Word.Application")

  'Enumerate the passed in file names
  For i = 0 to wscript.arguments.count - 1
  Set objFile = objFSO.GetFile(WScript.Arguments(i))
  Set objDoc = objWord.Documents.Open(WScript.Arguments(i),,TRUE)
  dirPath = objFSO.GetParentFolderName(objFile)
  fileBaseName = objFSO.GetBaseName(objFile)
  'Export to PDF using preferred settings
  pdf = objWord.ActiveDocument.ExportAsFixedFormat _
    (dirPath & "\" & fileBaseName & ".pdf", _
    wdExportFormatPDF, False, wdExportOptimizeForPrint, _
   wdExportAllDocument,,, _
   wdExportDocumentContent, _
   False, True, _
   wdExportCreateHeadingBookmarks)
 Next
 'Quit MS Word
 objWord.Quit(False)
Else
 msgbox("You must select a file to convert")
End If</code>

When you find a document that you wish to convert, just drag and drop the file onto the script.

Right, there’s an Excel version along shortly.

Using the RTSP Protocol with the PHP header function

I had a great deal of trouble getting Internet Explorer to redirect the header to a RTSP link using the header function in PHP.

I found that in IE, I would get a HTTP 402 error (page has been temporarily moved). IE would happily sit there and tell me it could not be found.

Firefox was a little more robust and displayed a page which resolved an alternatve link – “Object Moved” gracing the page and a link to the rtsp link. This would also automatically open the link in Firefox.

Thankfully, I found the answer on the Jalix PHP manual.

I think that the idea is to generate a RAM-style link to the RTSP protocol rather than redirecting directly to it:

Header ("Pragma: ");
Header ("Cache-Control: ");
Header ("Expires: ");
Header ("Content-Type: audio/x-pn-realaudio");

# insert DB code here
print "rtsp://host.com:554/$filename";

That should happily create a working link to the RTSP transport.

And to Schu, yes – that saved me loads of time.

The Joys of HTA

I’ve been developing a number of HTA tools lately.

Certainly a pretty nifty way to create script-based applications without the need for whole development suites. In fact, seeing as Notepad++ is my tool of choice – it’s a no-brainer.

A lot of custom scripts should never need to be written once I’ve finished a suite of Active Directory tools. The first one is the most useful, a tool to create users automatically on a domain. Now I’m working on a tool to enumerate all users in a domain and empower the user to either enable or disable an account, as well as reset the password and change obvious settings like requiring the user to change passwords, alter group membership and bits like that.

The only downer is that there’s no real way to compile the app once it’s complete. Well, none that I know of.

Assault of the dumbfounded

So here I am back at CCJ and everything is normal. There was a log in the technician book asking for a form to add Internet links to the school’s intranet. So I reinstalled Dreamweaver on the development machine (a loose term – it’s an Intel 500mhz with 64MB RAM).

Anyway, I sat down and completed my work eventually. It turns out and Dreamweaver MX 2004 and Windows 98 don’t like each other that much, so I had to reinstall MX v.6. I cursed writing the thing in ASP and was grateful that I had converted the new version to PHP. That still didn’t make it easier for me. I’ve avoided any ASP scripting this year, and only used VBScript for server-side administration on domains. For some reason, the insert record wizard doesn’t like to make it too easy to modify the action once it’s created. Once I had finished the form and discovered that I had missed a field out (I accidentally removed it), I had to start the page over for simplicity.

And what do I get when I say the work is done?
“So they can add links when they want to? That isn’t what I wanted.”

ARGH!

So I’ve had to jiggle to code. They can still add links, but there’s a stamp in the computer name list of the user, time and date that the link was added. At least then it can be traced.

They’ll have to like to like it or lump it for the time being.