1

I have a very strange an unique issue in front of me. quick summary is I need to convert a word doc to a pdf. Easy enough right? Well the issue is that I need to convert a word doc to pdf while keeping the font as selectable text. Unfortunately the font I HAVE to use is myriad pro which is a mac font. This means that when I do the conversion to PDF with this method.

$path = 'C:\temp\Convert'

$wd = New-Object -ComObject Word.Application
Get-ChildItem -Path $path -Include *.doc, *.docx -Recurse |
    ForEach-Object {
        $doc = $wd.Documents.Open($_.Fullname)
        $pdf = $_.FullName -replace $_.Extension, '.pdf'
        $doc.ExportAsFixedFormat($pdf,17,$false,0,3,1,1,0,$false, $false,0,$false, $true)
        $doc.Close()
    }
$wd.Quit()

or

$word_app = New-Object -ComObject Word.Application
$word_app.visible = $False

##
##   Get the files from the folder
##
$files = Get-ChildItem $Ftype
##
##   process each file - open in WORD and save as PDF in output folder
##   then delete original WORD file
##
write-host "Starting DOC Conversion"
ForEach ($file in $files) { 
    $d2 = $file.name
    $Out = $OutPath + $d2 -replace ".doc", $NewSuffix
    #$Out = $Out -replace '\s',''
    $LogLine = "Converting from " + $file.fullname + " to " + $Out
    $LogLine >>'C:\temp\WordPDF.LOG'
    write-host $LogLine
    $document = $word_app.Documents.Open($file.fullname)
    #$document.ExportAsFixedFormat($Out,[Microsoft.Office.Interop.Word.WdExportOptimizeFor]::wdExportOptimizeForPrint)
    $document.SaveAs($Out, 17)

    $document.Close()
    $Dcounter = $Dcounter + 1
    $Wcounter = $Wcounter + 1
    if ($Deletefiles) {
        Remove-Item $file 
        write-host "Deleting " $file.fullname
        }
}
$word_app.Quit()

so i've tried the "exportAsFixedFormat" method and the "SaveAs". Both work as far as conversion goes but it creates a bitmap pdf instead of selectable text.

The only way i've found that would solve my problem is to "print to PDF" and here's how i've approached it..

#===================================
#Get the default printer and save to a variable
$DefPrinter=Get-WmiObject -Query " SELECT * FROM Win32_Printer WHERE Default=$true"
Write-Output $DefPrinter

#List all printers if you don't know the printer name
$xgetPrinters=Get-WmiObject -Query " SELECT * FROM Win32_Printer" | Select Name
Write-Output $xgetPrinters

#Set the default printer for printing while the code is executed
$Printer_net = New-Object -COM WScript.Network
$Printer_net.SetDefaultPrinter("Microsoft Print to PDF")

$xpath="C:\temp\ConvertDoc\"
$folders=get-childitem $xpath | select Name

$folders2=get-childitem $xpath



foreach($pdf_files in $folders)
{
$PDF_file_name = $pdf_files.Name;

Start-Process $xpath$PDF_file_name -Verb Print
}

This way creates a PDF with selectable text. Although there are two issues.

  1. Setting the default printer doesn't actually work. I have to go into windows settings and set the default printer manually.

  2. I can't figure out how to suppress the save as prompt and name the file the name of the current file it's trying to convert.

Can anyone help with this please. I am STUCK and out of ideas.

Keifer
  • 39
  • 2
  • 7

2 Answers2

0

The question is old so this is just a synopsys of how to resolve the OP question to avoid other unrelated answers.

  1. Setting the default printer doesn't actually work. I have to go into windows settings and set the default printer manually.

Windows has a "manage my printer" setting so ensure that is not on or else your going to find the goalposts keep moving. If you dont wish to set the default permanently you will need to call print to pdf using the driver and port name methods, that way you can try to address the second question.

  1. I can't figure out how to suppress the save as prompt and name the file the name of the current file it's trying to convert.

Windows by default for XPS and PDF printing uses a file port known as XPSPort: or PORTPROMPT: and those should be left exactly "as is" unchanged, So the answer is to duplicate "Microsoft Print to PDF" and change the copied driver to a new name with a port thats a file name thus for example set the printer to "My Print to PDF" and its output to something like c:\userdata\prinouts\printout.pdf then you can rename that output once it is completed or change the print call to print filename to Print "My Print to PDF" "Microsoft Print to PDF" "c:\wherever\IwantIt.pdf" based on filename>printer>driver>port

For more detail see How to skip choosing folder in microsoft pdf printer?

K J
  • 8,045
  • 3
  • 14
  • 36
-1

Adobe Acrobat > Edit > Preferences > Documents > Save settings and uncheck both options.

set options

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
chok120
  • 1
  • 1