Solved

converting doc to pdf with bookmarks and links enabled

Posted on 2007-11-21
5
3,467 Views
Last Modified: 2013-11-25
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
Comment
Question by:annapolistech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
wobbled earned 500 total points
ID: 20327688
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
 

Author Comment

by:annapolistech
ID: 20371883
This is not the solution what I needed and it is too difficult to do in this method..
0
 
LVL 17

Expert Comment

by:wobbled
ID: 20377178
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
 
LVL 1

Expert Comment

by:Computer101
ID: 20560953
Forced accept.

Computer101
EE Admin
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Inserting page numbers in Portable Document Files not only enhances manageability but also makes them look professional. With numbered pages, the file appears more organized and it becomes easier to search for a particular page. The size and the vol…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question