none
Convert word to pdf using word automation Services, Bookmarks links are not working in PDF. RRS feed

  • Question

  • Hi Team,

    My requirement Convert word(MSOffice2010) to pdf from sharepoint2016. I have used WordAutomationService and ConversionJob. The word document contains External Hyperlinks,Meta Data and Bookmars. I am getting PDF's after convert. But I am facing an issue with Bookmarks. When I click on Bookmark link its not firing.But its working same functionality in SP2010 and its not working SP2016. Please help me on this. 


    • Moved by Cindy Meister MVP Sunday, August 5, 2018 9:36 AM more about SharePoint behavior
    Friday, August 3, 2018 2:12 PM

All replies

  • Hi Team,

    My requirement Convert word(MSOffice2010) to pdf from sharepoint2016. I have used WordAutomationService and ConversionJob. The word document contains External Hyperlinks,Meta Data and Bookmars. I am getting PDF's after convert. But I am facing an issue with Bookmarks. When I click on Bookmark link its not firing.But its working same functionality in SP2010 and its not working SP2016. Please help me on this. 

    SPUser user = spSite.RootWeb.EnsureUser(Constants.PublishingAccount);
                            SPList destinationLibrary = web.TryGetList(Constants.DestinationLibrary);
                            SPFile file = web.GetFile(fileUrl);
                           
                            string destinationFileUrl = SPUtility.GetFullUrl(spSite, GetDestinationFileUrl(file, destinationLibrary));
                            if (!string.IsNullOrEmpty(destinationFileUrl))
                            {
                                SPFile dfile = web.GetFile(destinationFileUrl);
                                if (dfile.Exists)
                                {
                                    var ditem = dfile.Item;
                                    ditem.Delete();                                
                                }
                                var job = new ConversionJobSettings();                          
                                job.UpdateFields = true;
                                job.OutputFormat = SaveFormat.PDF;                          
                                ConversionJob pdfConversion = new ConversionJob("Word Automation Services", job);
                                pdfConversion.UserToken = spSite.UserToken;                          
                                string sourceUrl = SPEncode.UrlDecodeAsUrl(Convert.ToString(file.Item[SPBuiltInFieldId.EncodedAbsUrl]));
                                SPLogger.LogInfo(702, string.Format("Converting file {0} to {1} using word automation service", sourceUrl, destinationFileUrl));
                                pdfConversion.AddFile(sourceUrl, destinationFileUrl);
                                pdfConversion.Start();

    Friday, August 3, 2018 2:11 PM
  • As this appears to be more an issue with SharePoint and not with code written to automate the Word application, I'm going to move your question to a more appropriate forum.

    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Sunday, August 5, 2018 9:32 AM
  • Hi,

    Just use the save as option in MS Word and it will give the option of saving into PDF under "Save as Type". Or you can use any external tool to do the same

    Sunday, August 5, 2018 9:40 AM
  • You can use a Macro, in Word, to convert many Word documents to other types of files.

     

     

    Option Explicit On

     

    Sub ChangeDocsToTxtOrRTFOrHTML()

        'with export to PDF in Word 2007

        Dim fs As Object

        Dim oFolder As Object

        Dim tFolder As Object

        Dim oFile As Object

        Dim strDocName As String

        Dim intPos As Integer

        Dim locFolder As String

        Dim fileType As String

        On Error Resume Next

     

        locFolder = InputBox("Enter the folder path to DOCs", "File Conversion", "C:\Users\your_path_here\")

        Select Case Application.Version

            Case Is < 12

                Do

                    fileType = UCase(InputBox("Change DOC to TXT, RTF, HTML", "File Conversion", "TXT"))

                Loop Until (fileType = "TXT" Or fileType = "RTF" Or fileType = "HTML")

            Case Is >= 12

                Do

                    fileType = UCase(InputBox("Change DOC to TXT, RTF, HTML or PDF(2007+ only)", "File Conversion", "TXT"))

                Loop Until (fileType = "TXT" Or fileType = "RTF" Or fileType = "HTML" Or fileType = "PDF")

        End Select

     

        Application.ScreenUpdating = False

        Set fs = CreateObject("Scripting.FileSystemObject")

        Set oFolder = fs.GetFolder(locFolder)

        Set tFolder = fs.CreateFolder(locFolder & "Converted")

        Set tFolder = fs.GetFolder(locFolder & "Converted")

     

        For Each oFile In oFolder.Files

            Dim d As Document

            Set d = Application.Documents.Open(oFile.Path)

            strDocName = ActiveDocument.Name

            intPos = InStrRev(strDocName, ".")

            strDocName = Left(strDocName, intPos - 1)

            ChangeFileOpenDirectory tFolder

            Select Case fileType

                Case Is = "TXT"

                    strDocName = strDocName & ".txt"

                    ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatText

            Case Is = "RTF"

                    strDocName = strDocName & ".rtf"

                    ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatRTF

            Case Is = "HTML"

                    strDocName = strDocName & ".html"

                    ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatFilteredHTML

            Case Is = "PDF"

                    strDocName = strDocName & ".pdf"

                    ActiveDocument.ExportAsFixedFormat OutputFileName:=strDocName, ExportFormat:=wdExportFormatPDF

            End Select

            d.Close

            ChangeFileOpenDirectory oFolder

        Next oFile

        Application.ScreenUpdating = True

     

    End Sub

     

    I have NEVER heard of using SharePoint to do this.


    MY BOOK

    Monday, August 6, 2018 9:50 PM
  • In my requirement is they want to keep the files in SharePoint library it self. We are not considered external tools. Please let me know,if any alternate solution.
    Tuesday, August 7, 2018 1:39 PM
  • Thank you so much.. If you got any updates, Please post it. I am eagerly waiting for the solution.
    Tuesday, August 7, 2018 1:40 PM