1

I am trying to convert TIF files into PDF Files. Below is the code that does the conversion however, when it converts i loose the content in the TIF files and only get blank PDF files. How do I convert the files and keep the picture on the original TIF file.

$InputLocation = "C:\convert"





$tool = 'C:Program Files (x86)\PDFCreator\PDFCreator.exe'
$tiffs = get-childitem  -filter *.tif -path $InputLocation

foreach($tiff in $tiffs)
{
    $filename = $tiff.FullName
    $pdf = $tiff.FullName.split('.')[0] + '.pdf'


    'Processing ' + $filename  + ' to ' + $pdf      
    $param = "-sOutputFile=$pdf"
    & $tool /IF$filename /OF$pdf /NoPSCheck /NoStart

}
Peter3
  • 2,549
  • 4
  • 20
  • 40

2 Answers2

0

According to the command line reference you need double quotes around the file names and the output format.

e.g.

pdfcreator.exe /IF"C:\description.ps" /OF"C:\description.pdf" /OutputSubFormat"PDF/A-1b"
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
0

As @Preet Sangha has said, you need to double quote the parameters.

This should do it:

$InputLocation = "C:\convert"

$tool = 'C:Program Files (x86)\PDFCreator\PDFCreator.exe'
$tiffs = get-childitem  -filter *.tif -path $InputLocation

foreach($tiff in $tiffs)
{
    $filename = $tiff.FullName
    $pdf = $tiff.FullName.split('.')[0] + '.pdf'


    'Processing ' + $filename  + ' to ' + $pdf      
    $param = "-sOutputFile=$pdf"
    Start-Process $tool -ArgumentList ('/IF"' + $filename + '" /OF"' + $pdf + '/NoPSCheck /NoStart')
}

EDIT: Changed to use Start-Process instead of &

Graham Gold
  • 2,435
  • 2
  • 25
  • 34
  • The term 'C:\Program Files (x86)\PDFCreator\PDFCreator.exe/IF"C:\convert\00020001.TIF" /OF"C:\convert\00020001.pdf"/NoPSChec k /NoStart' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At M:\Powershell\convert.ps1:18 char:6 + & <<<< ($tool + '/IF"' + $filename + '" /OF"' + $pdf + '"/NoPSCheck /NoStart')+CategoryInfo: ObjectNotFound:(C:\Program File...SCheck /NoStart:String)[],CommandNotFoundException+ FullyQualifiedErrorId:CommandNotFoundException – Peter3 Jul 08 '13 at 14:00
  • @user2471571 - My mistake, hadn't had the time to try the code, just amended your existing code. Have amended to use Start-Process instead to run the program. I don't have the PDF Creator software to fully test but give it a go. – Graham Gold Jul 08 '13 at 15:41
  • I really appreciate all the help. It is running with no errors now but it is "deleting" the file now. I am guessing it could be something to do with the output path – Peter3 Jul 08 '13 at 17:10
  • Is it deleting the source or the destination? – Graham Gold Jul 08 '13 at 22:47
  • According to the vendor support site the IF/OF commands are only for converting from .ps (postscript) files. For everything else, they advise you to use the PF (print file) command. The poster had what sounds like the same issue as you, input file deleted even though DeleteIF option was not set. http://forums.pdfforge.org/discussion/10806/when-using-pdfcreator-command-line-it-generates-an-empty-pdf-document/p1 – Graham Gold Jul 08 '13 at 22:58
  • @GrahamGold: when I try this I get the PDFCreator 2.3 window popping up, with two buttons: one for "Application Settings" and the other for "Profile Settings". No TIF gets converted to a PDF. Any ideas? – val May 01 '16 at 04:29
  • 1
    @val I don't have PDF Creator, but a quick google suggests they've removed all but one of the command line options in the latest releases of their product - http://www.pdfforge.org/pdfcreator/manual/command-line-parameters – Graham Gold May 01 '16 at 04:39
  • @GrahamGold i found this line to work using imagemagick: convert $filename -density 300x300 -compress jpeg $pdf. see this post here: http://stackoverflow.com/questions/4719125/imagemagick-or-ghostscript-convert-a-multi-page-tiff-to-a-multi-page-pdf – val May 01 '16 at 07:28
  • @val thanks - if the OP ever pops back in here, because PDF Creator doesn't support command line anymore, an alternative is here for them :-) – Graham Gold May 01 '16 at 08:28