How to merge a pdf document to a word document as a single word document

i am trying to append a word document with a pdf.
but how to convert a pdf file into word to merge without saving it?

@khushboomehta

Thank you for contacting support.

You can convert a PDF document to Word document with Aspose.PDF for Java, as explained in Convert PDF to DOC or DOCX format. Then using Aspose.Words for Java API, you can move the cursor to the desired location and then insert that document using insertDocument method as explained in Insert a Document into another Document.

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Thanks for the quick reply Farhan
But lets say I have two documents

com.aspose.word.Document wordDocument = new com.aspose.word.Document(inputStream1);
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(inputStream2);

I have converted pdfDocument to docx using pdfconversionoptions

PdfFormatConversionOptions opts = new PdfFormatConversionOptions(inputStream2.toString(), SaveFormat.DOC, ConvertErrorAction.Delete);
pdfDocument.convert( opts );

using a document builder of aspose.word

DocumentBuilder  builder = new DocumentBuilder(wordDocument);
builder.moveToDocumentEnd();

but DocumentBuilder will only insert a document of aspose.word type. It will not take the pdfdocument as parameter

builder.insertDocument(pdfDocument, ImportFormatMode.KEEP_SOURCE_FORMATTING );

if i change the approach to use

wordDocument.appendDocument( pdfDocument, ImportFormatMode.KEEP_SOURCE_FORMATTING );

this will also not work

please suggest how i can insert the changed pdfDocument

@khushboomehta

We are checking the details and will get back to you with our findings soon.

@khushboomehta

Thanks for your inquiry. You can not use com.aspose.pdf.Document into DocumentBuilder.InsertDocument and Document.AppendDocument method. In your case, we suggest you following solution.

  1. Import the Word document into com.aspose.word.Document e.g. wordDocument.
  2. Import the PDF document into com.aspose.pdf.Document e.g. pdfDocument.
  3. Save the PDF document to DOCX using Aspose.PDF to disk or memory stream.
  4. Import the saved DOCX into Aspose.Words’ DOM e.g. aspose.word.Document e.g. wordDocument2.
  5. Now, you can pass wordDocument2 into DocumentBuilder.InsertDocument and Document.AppendDocument.
  6. Save the final document to DOCX.

thanks for replying