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.

hello team please suggest how can fix below issue.
As I am using below code to generate pdf file but once we insert data in pdf file it create box in pdf file.

  Aspose.Words.Document document = new Aspose.Words.Document();
  DocumentBuilder documentBuilder = new DocumentBuilder(document);
  // Define the fonts folder path (adjust the path as needed for your environment)
  string fontsFolderPath = "D:\\Fonts\\";

  // 1) Register folder as a font source so Aspose can embed fonts from it.
  var folderSource = new Aspose.Words.Fonts.FolderFontSource(fontsFolderPath, true);
  // Ensure fonts from this folder are embedded when creating PDF

  // Apply to FontSettings used for this document
  var fontSettings = new FontSettings();
  fontSettings.SetFontsSources(new Aspose.Words.Fonts.FontSourceBase[] { folderSource });
  document.FontSettings = fontSettings;
  documentBuilder.Writeln("Amharic ዜና በአማርኛ Arabic عربي Azeri AZƏRBAYCAN Bangla বাংলা Burmese မြန်မာ Chinese 中文网 Dari دری French AFRIQUE Hausa HAUSA Hindi हिन्दी Gaelic NAIDHEACHDAN Gujarati ગુજરાતીમાં સમાચાર Igbo AKỤKỌ N’IGBO Indonesian INDONESIA Japanese 日本語 Kinyarwanda GAHUZA Kirundi KIRUNDI Korean 한국어 Kyrgyz Кыргыз Marathi मराठी Nepali नेपाली Noticias para hispanoparlantes Pashto پښتو Persian فارسی Polish PO POLSKU Portuguese BRASIL Punjabi ਪੰਜਾਬੀ ਖ਼ਬਰਾਂ Russian НА РУССКОМ Serbian  NA SRPSKOM Sinhala සිංහල Somali SOMALI Swahili  HABARI KWA KISWAHILI Tamil தமிழில் செய்திகள் Telugu తెలుగు వార్తలు Thai ข่าวภาษาไทย Tigrinya ዜና ብትግርኛ Turkish TÜRKÇE Ukrainian");
  document.Save("D:\\FontIssueDocFile\\testingfile.Pdf", Aspose.Words.SaveFormat.Pdf);

PDF file is attached for your refrence.
testingfile.Pdf (47.1 KB)

@RiteshK10 Usually, the such problems occur because the fonts used in your input document are not available on the machine where document is converted to PDF. The fonts are required to build document layout. If Aspose.Words cannot find the font used in the document, the font is substituted . This might lead into fonts mismatch and document layout differences due to the different fonts metrics. You can implement IWarningCallback to get notifications when font substitution is performed.

I tested your code on my side and the problem is not reproducible with my set of fonts. Here is the output document:
out.pdf (135.2 KB)

Though in the source document one font is set for the whole text, not all fonts contains the required glyphs. Therefore Aspose.Words applies font fallback mechanism. Please see our documentation for more information:
https://docs.aspose.com/words/net/manipulating-and-substitution-truetype-fonts/#font-fallback-settings-from-xml

In addition, some text in your test string requires open type features to be rendered properly. Aspose.Words.Shaping.Harfbuzz package provides support for OpenType features in Aspose.Words using the HarfBuzz text shaping engine. You should enabling open type features to get the expected result. To achieve this you should add reference to Aspose.Words Shaping Harfbuzz plugin and use the following code to convert your document:

Document doc = new Document(@"C:\Temp\in.docx");
doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;
doc.Save(@"C:\Temp\out_HarfBuzz.pdf");

out_HarfBuzz.Pdf (135.6 KB)

hello team,
can you please suggest which font need to install for below text in machine to fix this issue.

@RiteshK10 In the PDF produced on my side the following fonts are used:

1 Like