Free Support Forum - aspose.com

PDF to DOC, and merge to DOC

I have an application that receives a PDF document, and I’m trying to convert it to a Doc, and append to an existing document. It works, but not without some formatting issues.
Is there a way to ensure margins are set properly, on the merge?

Using code sample provided on your site.

        WORDS.Document srcDoc = null;
        WORDS.ImportFormatMode mode = WORDS.ImportFormatMode.KeepSourceFormatting;
        string tempFileName = Path.GetTempFileName();

        try
        {
        if( format == FileFormat.Pdf )
        {
            // Instantiate the Document object
            PDF.Document document = new PDF.Document(stream);
            // Create DocSaveOptions object
            // Set the recognition mode as Flow
            // Set the Horizontal proximity as 2.5
            // Enable the value to recognize bullets during conversion process
            DocSaveOptions saveOptions = new DocSaveOptions
                                         {
                                             Mode = DocSaveOptions.RecognitionMode.Flow,
                                             RelativeHorizontalProximity = 2.5f,
                                             RecognizeBullets = true
                                         };
            // Save the resultant DOC file
            document.Save(tempFileName, saveOptions);
            srcDoc = new WORDS.Document(tempFileName);
        }
        else
            srcDoc = new WORDS.Document( stream);
        // Loop through all sections in the source document.
        // Section nodes are immediate children of the Document node so we can just enumerate the Document.
        foreach( WORDS.Section srcSection in srcDoc )
        {
            // Because we are copying a section from one document to another,
            // It is required to import the Section node into the destination document.
            // This adjusts any document-specific references to styles, lists, etc.
            //
            // Importing a node creates a copy of the original node, but the copy
            // Is ready to be inserted into the destination document.
            WORDS.Node dstSection = _document.ImportNode( srcSection, true, mode );

            // Now the new section node can be appended to the destination document.
            _document.AppendChild( dstSection );
        }
        return Save( DocumentPath);
        }
        catch( Exception exception )
        {
            Console.WriteLine( exception );
            throw;
        }
        finally
        {
            Utility.FileDelete(tempFileName);
        }

alliance.pdf (92.2 KB)
483[01]-3.zip (8.3 KB)

image.png (36.6 KB)
This is what I’m seeing in the merged document

@gmitchell.surgicalno,

Thank you for detail and sharing sample input and expected output files with us. We are looking into it. We will update you soon.

@gmitchell.surgicalno,

We have investigated the issue at our end. We have converted the PDF file shared by you to MS Word using Aspose.PDF for .NET 18.3 and merged the following documents using the Aspose.Words for .NET 18.3.

  1. Generated by Aspose.PDF
  2. 483[01]-3.doc Shared by you

We are unable to notice any issue. Final merged file is attached for your reference.
merged_file_18.3word.zip (2.1 MB)

Your version certainly looks better. The one thing I noticed that is different is the fact that I appended the PDF to the doc, and you inserted the pdf as the first page.

@gmitchell.surgicalno,

Thank you for input. Hope that using the above mentioned scheme, you will be able to resolve the issue.