PDF file distorted

hello,
when we create doc file and insert pdf file inside doc and convert into pdf then PDF file is disctorting.
As we are using below code.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Aspose.Words.Drawing.Shape headerLogo = builder.InsertImage(System.Web.HttpContext.Current.Server.MapPath("logopath"));
string reportFontName = "Arial";
headerLogo.Width = 100;
headerLogo.Height = 50;
headerLogo.WrapType = WrapType.None;
headerLogo.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
headerLogo.RelativeVerticalPosition = RelativeVerticalPosition.Page;
headerLogo.Left = (builder.PageSetup.PageWidth - headerLogo.Width) / 2;
headerLogo.Top = 10;
builder.Writeln();
builder.Writeln();
builder.MoveToDocumentStart();

DateTime currentDateTime = DateTime.Now;
builder.Font.Name = reportFontName;
builder.Font.Size = 10;
builder.Font.Bold = true;
builder.Writeln($"Source Input {currentDateTime.ToString("dd-MM-yy HH:mm:ss")}");
builder.Writeln();
if (model.doctype == "file")
{
    string filepath = CommonFunctions.SanitizePath(Server.MapPath("~/TempFiles/"), model.filePath);
    string extension = System.IO.Path.GetExtension(filepath).ToLower();
    if (!string.IsNullOrEmpty(filepath) && System.IO.File.Exists(filepath))
    {
        else if (extension == ".pdf")
        {
            using (MemoryStream mst = new MemoryStream())
            {
                var pdf = new Aspose.Pdf.Document(filepath);
                pdf.Save(mst, Aspose.Pdf.SaveFormat.DocX);

                mst.Position = 0;
                Document pdfDoc = new Document(mst);
                builder.InsertDocument(pdfDoc, ImportFormatMode.KeepSourceFormatting);
            }
            builder.InsertBreak(BreakType.PageBreak);
        }
    }
}
builder.Writeln();
builder.Font.Size = 10;
builder.Font.Bold = true;
builder.Writeln($"Here is the tested data of the text: ");
builder.Writeln();

builder.Writeln($"tested pdf data");
builder.Writeln();
builder.Font.Size = 10;
builder.Font.Bold = false;
builder.Writeln("test data");
doc.Save(pdfpath, SaveFormat.Pdf);

please see below screen shot. inserted pdf file is override with header logo. So, please suggest how can fix it.

Screenshot_2026-04-03-16-47-08-92_40deb401b9ffe8e1df2f1cc5ba480b12_Translated_2026-04-03_16-53-47.pdf (249.5 KB)

@RiteshK10 In your code you are converting PDF document to DOCX using Aspose.PDF. By default Aspose.PDF produces DOCX document with absolutely positioned content, which perfectly preserves layout, but make is hard to change content. Since you are inserting content before inserting content from the PDF document, the absolutely positioned content is shifted and causes the problem.

Have you tried loading PDF document by Aspose.Words directly?

Document pdfDoc = new Document(@"C:\Temp\in.pdf");
builder.InsertDocument(pdfDoc, ImportFormatMode.KeepSourceFormatting);

But please note, Aspose.Words is designed to work with MS Word documents. MS Word documents are flow documents and they have structure very similar to Aspose.Words Document Object Model. But on the other hand PDF documents are fixed page format documents. While loading PDF document, Aspose.Words converts Fixed Page Document structure into the Flow Document Object Model. Unfortunately, such conversion does not guaranty 100% fidelity.