Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3470
  • Last Modified:

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

0
annapolistech
Asked:
annapolistech
  • 2
1 Solution
 
wobbledCommented:
This is very difficult to do.  PDF's use a hotlink area to create hyperlinks.  It is not so much that the text itself is given a link as in html, a rectangle is drawn over the word / button etc and this is given co-ordinates for its position.  To do this in a straight print out from word, you will need to write this co-ordination information directly into the top of the PS file.  As you can guess this is pretty complex and requires a great deal of VBA coding as well as a good knowledge of creating PS files in such a way to be interpreted correctly by Adobe Distiller.
0
 
annapolistechAuthor Commented:
This is not the solution what I needed and it is too difficult to do in this method..
0
 
wobbledCommented:
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.
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now