Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
Add line numbering to a .docx with ActiveXObject('Word.Application')

Hi i want to add line numbering to the opened .docx file before converting it to .pdf and i really didn't find how to do that on code, it is converting my .docx file to pdf but i wanna add line numbering too, am using ActiveXObject with javascript to do that on server

var obj = new ActiveXObject("Scripting.FileSystemObject");
var docPath = WScript.Arguments(0);
docPath = obj.GetAbsolutePathName(docPath);
var pdfPath = docPath.replace(/\.doc[^.]*$/, ".pdf");
var objWord = null;
try
{
    objWord = new ActiveXObject("Word.Application");
    objWord.Visible = false;
    var objDoc = objWord.Documents.Open(docPath);
    var format = 17;
    objDoc.SaveAs(pdfPath, format);

    objDoc.Close();
    WScript.Echo("Saving '" + docPath + "' as '" + pdfPath + "'...");
}
catch(e){
    WScript.Echo(e);
}
finally
{
    if (objWord != null)
    {
        objWord.Quit();
    }
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to automate Word but you don't know how to do it in code, start recording a macro, do what you want, then stop recording and review the code. You should be able to figure out what you need from the generated code.

Here's an example of a recorded macro:

Sub Macro1
  With Selection.PageSetup
    With .LineNumbering
        .Active = True
        .StartingNumber = 1
        .CountBy = 1
        .RestartMode = wdRestartContinuous
        .DistanceFromText = wdAutoPosition
    End With
    .Orientation = wdOrientPortrait
    .TopMargin = InchesToPoints(1)
    .BottomMargin = InchesToPoints(1)
    .LeftMargin = InchesToPoints(1)
    .RightMargin = InchesToPoints(1)
    .Gutter = InchesToPoints(0)
    .HeaderDistance = InchesToPoints(0.5)
    .FooterDistance = InchesToPoints(0.5)
    .PageWidth = InchesToPoints(8.5)
    .PageHeight = InchesToPoints(11)
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin
    .SectionStart = wdSectionNewPage
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .VerticalAlignment = wdAlignVerticalTop
    .SuppressEndnotes = False
    .MirrorMargins = False
    .TwoPagesOnOne = False
    .BookFoldPrinting = False
    .BookFoldRevPrinting = False
    .BookFoldPrintingSheets = 1
    .GutterPos = wdGutterPosLeft
  End With
End Sub

Based on that example, I would assume your code would need to include this for line numbers:

objDoc.PageSetup.LineNumbering.Active = true;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!