Link to home
Start Free TrialLog in
Avatar of annapolistech
annapolistechFlag for United States of America

asked on

converting doc to pdf with bookmarks and links enabled

I am converting Doc to PdF It  works fine using acrobat distiller and even pdfedit995,deskpdf etc..but the problem is bookmarks are not working in pdf file if convert through programmatically.Bookmarks works fine when you convert externally .e throu word right click and convert to pdf.
here is my code ..
 Dim wd As New Word.Application
Set wd = New Word.Application

wd.Documents.Open fileName:="C:\0000001.doc", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto

wd.Documents.Application.ActivePrinter = "deskPDF"   'or pdf995
wd.Application.PrintOut fileName:="", Range:=wdPrintAllDocument, Item:=wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=False, Background:=True, PrintToFile:=False

I think because of  wd.Application.PrintOut  bookmarks are not working .Is there any other method other than printout  to convert doc  to Pdf
Here is one more code gives same problem

Dim objWord As New Word.Application
Dim strDefaultPrinter As String
 
Dim pdf As String
Dim ps As String
Dim docname As String
OutputDir = "C:\outlook extractor"
    '**save the printer to restore later
strDefaultPrinter = objWord.ActivePrinter
objWord.Visible = False
    '**
'objWord.ActivePrinter = "Acrobat Distiller"
Dim objDistiller As New ACRODISTXLib.PdfDistiller
 ps = Mid(flename, 1, Len(flename) - 4) & ".ps"
docname = Replace(ps, ".ps", ".doc", , , vbTextCompare)
If InStr(1, flename, ".pdf", vbTextCompare) = 0 Then
    objWord.Documents.Open docname


   If (ps <> "") Then
        '**piece together the pdf name
        pdf = Replace(ps, ".ps", ".pdf", , , vbTextCompare)
        '**print out the postscript via distiller
       
        objWord.PrintOut False, False, False, ps, , , , , , , True
        '**print out the pdf from the postscript
        objDistiller.FileToPDF ps, pdf, ""  ' OutputDir & "\" & pdf, ""
       ' Fs.CopyFile pdf, OutputDir & ".pdf"
'        Fs.DeleteFile OutputDir & "\" & pdf
'        Fs.DeleteFile OutputDir & "\" & ps
    End If
   
    Fs.DeleteFile ps
    'fs.DeleteFile
   ' Fs.DeleteFile Replace(ps, ".ps", ".txt")
    ps = ""
    '**close the word file w/o saving
    Set objDistiller = Nothing
    objWord.ActiveDocument.Close False
    objWord.Quit
    Set objWord = Nothing
End If

Dim objWord As New Word.Application
Dim strDefaultPrinter As String
Dim Fol As Folder
Dim OutputDir As String
Dim pdf As String
Dim ps As String
Dim docname As String
OutputDir = "C:\outlook extractor"
    '**save the printer to restore later
strDefaultPrinter = objWord.ActivePrinter
objWord.Visible = False
    '**
'objWord.ActivePrinter = "Acrobat Distiller"
Dim objDistiller As New ACRODISTXLib.PdfDistiller
 ps = Mid(flename, 1, Len(flename) - 4) & ".ps"
docname = Replace(ps, ".ps", ".doc", , , vbTextCompare)
If InStr(1, flename, ".pdf", vbTextCompare) = 0 Then
    objWord.Documents.Open docname
 
 
   If (ps <> "") Then
        '**piece together the pdf name
        pdf = Replace(ps, ".ps", ".pdf", , , vbTextCompare)
        '**print out the postscript via distiller
        
        objWord.PrintOut False, False, False, ps, , , , , , , True
        '**print out the pdf from the postscript
        objDistiller.FileToPDF ps, pdf, ""  ' OutputDir & "\" & pdf, ""
       ' Fs.CopyFile pdf, OutputDir & ".pdf"
'        Fs.DeleteFile OutputDir & "\" & pdf
'        Fs.DeleteFile OutputDir & "\" & ps
    End If
    
    Fs.DeleteFile ps
    'fs.DeleteFile
   ' Fs.DeleteFile Replace(ps, ".ps", ".txt")
    ps = ""
    '**close the word file w/o saving
    Set objDistiller = Nothing
    objWord.ActiveDocument.Close False
    objWord.Quit
    Set objWord = Nothing
End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of wobbled
wobbled
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of annapolistech

ASKER

This is not the solution what I needed and it is too difficult to do in this method..
Sorry to be the bringer of bad news, but I do not know of another way to do this, in fact my method above is how we got round the issue within the organisation I work for.  It resulted in a substantial addin being built.
Forced accept.

Computer101
EE Admin