Create PDF

Bianchi928
Bianchi928 used Ask the Experts™
on
How can I  modity this script to create a pdf with some fancy fonts instead of txt

Thanks
Cheers


Dim objWMIService, objitem, colitems, objFSO, strFile, objFile
Const ForWriting = 2
Const CreateIfNotExist = True

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\xlsbillfile.xls")

intRow = 2

Do Until objExcel.Cells(intRow,1).Value = ""
   strFile = "C:\Documents and Settings\Administrator\Desktop\Phone Bills\" & objExcel.Cells(intRow, 4).Value & ".txt"
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objFile = objFSO.OpenTextFile(strFile, ForWriting, CreateIfNotExist)
   objFile.WriteLine "Mobile Phone Usage for the month of March 2012"
   objfile.WriteLine ""
   objfile.WriteLine "Mobile NUmber :" & objExcel.Cells(intRow, 1).Value
   objfile.WriteLine "Amount        :" & "$" & objExcel.Cells(intRow, 2).Value
   intRow = intRow + 1
Loop

objExcel.Quit
objfile.close
Wscript.echo "Job Done"
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You will need an extra 3rd party library to create a pdf file with vb or vba scripting.

Here is one: http://bytescout.com/products/developer/pdfdocscoutsdk/pdfdocscout_example_vbscript.html
Why not print the excel sheet through a PDF print driver?

http://www.cutepdf.com/products/cutepdf/writer.asp
http://www.bullzip.com/products/pdf/info.php

Cheers,
    Chris

Author

Commented:
Thanks for that. That's where I need help. I have a printer called FinePrint PDFFactory and I want to automate the printing. I don't want any user interaction.
I found this while trawling Google

http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/06/save-a-microsoft-excel-workbook-as-a-pdf-file-by-using-powershell.aspx

Does it fit your requirement?

If not, then Googling for "Powershell print office document" should turn up the code you need.

Cheers,
    Chris

Author

Commented:
HI Chris,

You got me on the right track. I found this little Powershell thing that workjs only for one file

$word = new-object -ComObject "word.application"
$doc = $word.documents.open("C:\document.doc")
$saveaspath = [ref] "c:\document.pdf"
$formatPDF = [ref] 17
$doc.SaveAs($saveaspath,$formatPDF)
$doc.Close()


How can I modify to make it read & convert all the *.doc file from a directory tp pdf
The following script worked for me - getting all the documents from e:\*.docx

Cheers,
   Chris

$word = new-object -ComObject "word.application"

$items = Get-ChildItem e:\*.docx | where {!$_.PSIsContainer} 

foreach ($item in $items) {
    Write-Host $item.Name
    $doc = $word.documents.open($item.FullName)
    $saveaspath = $item.FullName
    $saveaspath += ".pdf"
    $formatPDF = 17
    $doc.SaveAs($saveaspath,$formatPDF)
    $doc.Close()
}
$word.Quit()

Open in new window

Author

Commented:
Oops I found the problem to the script

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial