convert word to pdf without losing digital signature image with word.interop.document

Viewed 50

I am using Interop.Word.Document to convert a Word document to PDF.

It is working fine for me, unless the document has a digital signature, which is not present in the final PDF.

Is there any parameter or line of code that must be added so the signature or signature drawing is not lost?

obs: no problem if the signature is "lost", the expected result it is that the signature or graphic representation of the signature can be seen visually, it would be good.

Update

Private Sub ConvertWordToPDF(filename As String)
    Dim wordApplication As New Microsoft.Office.Interop.Word.Application
    Dim wordDocument As Microsoft.Office.Interop.Word.Document = Nothing
    Dim outputFilename As String

    Try
        wordDocument = wordApplication.Documents.Open(filename)
        outputFilename = System.IO.Path.ChangeExtension(filename, "pdf")

        If Not wordDocument Is Nothing Then
            wordDocument.ExportAsFixedFormat(outputFilename, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF, True, Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForOnScreen, Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument, 0, 0, Microsoft.Office.Interop.Word.WdExportItem.wdExportDocumentContent, True, True, Microsoft.Office.Interop.Word.WdExportCreateBookmarks.wdExportCreateNoBookmarks, True, True, False)
        End If
    Catch ex As Exception
        'TODO: handle exception
    Finally
        If Not wordDocument Is Nothing Then
            wordDocument.Close(False)
            wordDocument = Nothing
        End If

        If Not wordApplication Is Nothing Then
            wordApplication.Quit()
            wordApplication = Nothing
        End If
    End Try

End Sub

I also verify that if the pdf is saved or exported from word, the digital signature is deleted, but if the print to pdf option is used, the image of the signature is kept.

They will know of any library to print virtual to pdf that is free or open source.

Update: the digital signature, in this case it would be the image of a signature, it is desired to be kept visible as an image or similar. It does not matter if the signature concept is lost and it only becomes an image.

Thank you,

1 Answers

The digital signature can't be copied between files. You need to re-sign the generated file separately.

Also I've noticed that you are running the code in ASP.NET. Pay attention to the following fact:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

Read more about that in the Considerations for server-side Automation of Office article.

If you deal with open XML document you may consider using the Open XML SDK instead, see Welcome to the Open XML SDK 2.5 for Office.

Related