Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Dec 12, 2011 12:02 pm

Is it possible to add a PDF (as an image) into a spire.doc document?

graham.simmonds
 
Posts: 3
Joined: Mon Nov 21, 2011 11:21 am

Tue Dec 13, 2011 6:18 am

Hello graham,

Thank you for your inquiry.

Spire.Doc support add a PDF into a sprie.Doc by using method AppendOleObjec.

I aatached you the file and code. Please have a try.

If you still have any other questions, please don't hesitate to contact us.
Have a nice day.
Tina
Technical Support/Developer,
e-iceblue Support Team
User avatar

Tina.Lin
 
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

Tue Dec 13, 2011 10:43 am

Hi There,

Nope it didn't work. I am trying to do it in asp.net and the following is the my code:

Code: Select all
Dim PDFdoc As New Document()
'load a document

Dim PDFsection As Section = PDFdoc.AddSection()
'Add a new paragraph to the section.
Dim PDFparagraph As Paragraph = PDFsection.AddParagraph()
'Insert an OLE object (PDF) from the disk to the document.
Dim stream2 As Stream = New FileStream(Server.MapPath("icon.png"), FileMode.Open, FileAccess.Read)
Dim stream1 As Stream = New FileStream(Server.MapPath("Test.pdf"), FileMode.Open, FileAccess.Read)

PDFparagraph = PDFsection.AddParagraph()
Dim docPic As New DocPicture(PDFdoc)
docPic.LoadImage(System.Drawing.Image.FromStream(stream2))
docPic.HeightScale = 25
docPic.WidthScale = 25
Try
        PDFsection.AddParagraph.AppendOleObject(stream1, docPic, OleObjectType.AdobeAcrobatDocument)
Catch
End Try

PDFdoc.SaveToFile(Server.MapPath("CasePack/PDF" & EncID & ".doc"), FileFormat.Doc)


I tried what you sent me and I got an Object reference not found error when it was trying to AppendOleObject.

Thanks for the help

graham.simmonds
 
Posts: 3
Joined: Mon Nov 21, 2011 11:21 am

Wed Dec 14, 2011 10:14 am

Hello,

Please try the following code:

Code: Select all

Imports System.Web.UI
'using System.Web.UI.WebControls;

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields

Namespace InsertObject
   Partial Public Class test
      Inherits System.Web.UI.Page
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)


      End Sub

      Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
         Dim document As New Document()
         Dim path As String = Server.MapPath(".\Test.docx")
         document.LoadFromFile(path, FileFormat.Docx2010)

         Dim pic As New DocPicture(document)
         Dim imgPath As String = Server.MapPath(".\icon.png")
         Dim image As Image = Image.FromFile(imgPath)
         pic.LoadImage(image)

         Dim pdfPath As String = Server.MapPath(".\Test.pdf")
         document.LastParagraph.AppendOleObject(pdfPath, pic, OleObjectType.Package)
         document.SaveToFile(Server.MapPath(".\Result.docx"), FileFormat.Docx2010, Response, HttpContentType.Attachment)
         'document.SaveToFile(@"..\..\sample.docx", FileFormat.Docx2010);
         'System.Diagnostics.Process.Start(@"..\..\sample.docx");
      End Sub
   End Class
End Namespace


If you still have any other questions, please don't hesitate to contact us.
Have a nice day.
Tina
Technical Support/Developer,
e-iceblue Support Team
User avatar

Tina.Lin
 
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

Thu Dec 15, 2011 9:34 am

HI,

I'm sorry but I have tried your code but all it has in the document is the image displaying and not the pdf.

I am wondering is there a way of streaming the pdf straight into the document from a database?

Thanks for the help.

graham.simmonds
 
Posts: 3
Joined: Mon Nov 21, 2011 11:21 am

Fri Dec 16, 2011 1:51 am

Hello graham,

Thank you for your patience.

If you Insert a PDF into word by MS Word, you will see that it insert PDF treat as Object. It also dislay a image. You need to double click it like a hyperlink.

If you still have any other questions, please don't hesitate to contact us.

Have a nice day.
Tina
Technical Support/Developer,
e-iceblue Support Team
User avatar

Tina.Lin
 
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

Return to Spire.Doc

cron