Free Support Forum -

PDF / HTML document page insert in word


Can I insert PDF document(single or multi page) or a HTML document in a word document using Aspose?



PDF document insertion is not supported in Aspose.Words.

As for HTML document you can easily append it to word document with a code like this:

string fn1 = Application.StartupPath + "\\" + "doc1.doc";

string fn2 = Application.StartupPath + "\\" + "doc2.html";

Document doc1 = new Document(fn1);

Document doc2 = new Document(fn2);

for (int i = 0; i < doc2.Sections.Count; i++) {

Section section = (Section)doc1.ImportNode(doc2.SectionsIdea [I], true);



doc1.Save(Application.StartupPath + "\\" + "doc1+2.doc");


Following points:

1.>Appending is ok, but what if I want to insert HTML document in the middle of a word document. Also in your example you displayed html document having sections?

2.>Also if a image(chart) can be inserted, why can't a PDF page be a inserted in between a document? Are you planning to support insertion of PDF in future? The document that we are working on requires html and pdf documents to be inserted in the middle of a word document.



Aspose.Words permits you to load html documents exactly in the same manner as MS Word documents. The document is loaded into Aspose.Words object model tree. You can then prune and graft the tree nodes as much as you want while obeying the rules and limitations of the object model stipulating which node can be child of which. To prune and graft nodes between several document trees you need to implement ImportNode method.

I have provided a very basic example of appending the whole document to the end of another document just to give the idea. But the possibilities of information exchange between documents given by Aspose.Words library are practically limitless. Each case requires a specific approach.

You should also be aware that you can insert simple HTML lines in any place of the document by using DocumentBuilder.InsertHtml method.

Concerning insertion of PDF into documents. This is not the kind of functionality that MS Word itself provides. And I do not know of any other product on the market that does. It looks like a very peculiar task. And taking into account the complexity of imlementation I don't think we are going to support it anytime soon.

hello... Clear about html insertion.

As for pdf, if I have a single page pdf file and I do a copy paste operation into word, the page shows as image in word. By copy paste I do a cntrl-C on the file in windows explorer and then paste it into a open word document. Even Word automation supports it. Since PDF essentially is a image, won't it be treated the same as chart for example?



By pressing Ctrl-C on pdf file in windows explorer you actually run Acrobat Reader invisibly, which renders the file for you and puts it as rather low-resolution image in windows clipboard. You won't be able to do this trick on a system that has no Acrobat software installed. Acrobat is not an image. It has a rather complex format specification (actionally there are multiple format specifications which differ significantly - versions 1.1 - 1.5). It is not an easy task to parse arbitrary acrobat file and insert it to word. But we will consider doing it if the demand for these feature will be strong.