Quantcast
Channel: Adobe Community: Message List - Acrobat SDK
Viewing all articles
Browse latest Browse all 10848

convert html file to pdf silent vb.net

$
0
0

I am developing a plugin for a CAD application that creates setup sheets in html format and saves them to my C: drive. My company wants them saved as PDFs, and i want to do all of this silently.

 

Once the html sheet is created, i want the SDK to open it and convert it to a pdf. sounds simple enough, and i have gotten it to work with .rtf files, .txt files, etc. But as soon as i try to convert an html file it locks up my app after setting the output registry value to C:\Windows\splwow64.exe.

 

[code]

    Friend Sub ConvertFile(ByVal strFilePath As String, ByVal strOutputDir As String)

 

 

        'Two parts to converting a file:

        'a) update registry for silent conversion of strFilePath

        'b) perform the print command with the associated application - PrintToAdobePDF()

 

 

        Dim objThisFile As New FileInfo(strFilePath)   'get FileInfo object for file string

        Dim strFileExt As String = objThisFile.Extension   'get file extension

 

 

        'Documentation example for what we're going to do in the registry:

        'Set the key for the output file name to turn off prompting

        ' [HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\PrinterJobControl]

        ' "C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe" =

        ' "c:\\MyPDFoutputFileName.pdf"

        ' removed once the StartDoc(HDC hdc, CONST DOCINFO* lpdi) has successfully completed

 

 

        'Get application for current file

        Dim strAppPath As String = "C:\Windows\splwow64.exe"

 

 

        'Get file name without extension

        Dim strFilePrefix As String = System.IO.Path.GetFileNameWithoutExtension(strFilePath)

 

 

        'Create output file path

        Dim strOutputFile As String = strOutputDir & "\" & strFilePrefix & ".pdf"

        ' Registry Updates

        Dim objDistillerRegKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot

        Dim strDistillerSubKey As String = "SOFTWARE\\Adobe\\Acrobat Distiller\\PrinterJobControl"

        'Open Current User's Distiller Subkey for writing

        objDistillerRegKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(strDistillerSubKey, True)

 

 

        Dim strSaveOutputPath As String = ""

 

 

        'Distiller Registry Key

        If objDistillerRegKey Is Nothing Then   'if key is not there, create it

            objDistillerRegKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(strDistillerSubKey)

        End If

 

 

        If (Not objDistillerRegKey Is Nothing) Then     'set reg key value for this app and file

            objDistillerRegKey.SetValue(strAppPath, strOutputFile)

            objDistillerRegKey.Close()

        End If

 

 

        PrintToAdobePDF(strFilePath)

 

 

    End Sub

 

 

    Private Sub PrintToAdobePDF(ByVal InputfilePath As String)

 

        'Prints InputFilePath to the AdobePDF printer.

        'Since we just gathered all this info programmatically,

        'this function assumes the file is present, that it has an

        'associated application and that the current user has print privileges.

 

 

        'Define properties for the print process

        Dim pProcInfo As New ProcessStartInfo

 

 

        pProcInfo.FileName = InputfilePath

        pProcInfo.Verb = "Print"

 

 

        'Make process invisible

        pProcInfo.CreateNoWindow = True

        pProcInfo.WindowStyle = ProcessWindowStyle.Hidden

 

 

        'start print process

        Dim pMyProc As Process = Process.Start(pProcInfo)

        pMyProc.WaitForExit()

 

 

    End Sub

[/code]

 

i call these Subs with:

[code]

Dim inputFile As String = "C:\temp\Urgent.html"

ConvertFile(inputFile, "C:\temp")

[/code]

 

this is the first time i am trying to use the SDK instead of a third party converter and it is becoming a huge confusion. any input would be appreciated thanks!

 

(i have added a reference to acrobat and distiller in my project, and i am succesfully updating the registry)


Viewing all articles
Browse latest Browse all 10848

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>