srm-report 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +29 -0
- package/LICENSE +21 -0
- package/README.md +38 -2
- package/SKILL.md +97 -0
- package/assets/examples/project_21cse734p.py +150 -0
- package/bin/srm-report.js +171 -0
- package/package.json +34 -4
- package/references/content.md +40 -0
- package/references/families.md +38 -0
- package/references/rules.md +105 -0
- package/scripts/check_report.py +205 -0
- package/scripts/inspect_template.py +124 -0
- package/scripts/render_pages.py +34 -0
- package/scripts/rptlib.py +873 -0
- package/scripts/word_pass.ps1 +42 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Update every field in a .docx through hidden Word, save it, export a PDF, and report table page ranges.
|
|
2
|
+
# usage: powershell -NoProfile -ExecutionPolicy Bypass -File word_pass.ps1 -In C:\full\report.docx -Out C:\full\report.pdf [-Json C:\full\layout.json]
|
|
3
|
+
# Run it on a scratch copy, never on a file the user has open. It closes only the Word process it started.
|
|
4
|
+
param([Parameter(Mandatory=$true)][string]$In, [Parameter(Mandatory=$true)][string]$Out, [string]$Json = "")
|
|
5
|
+
$ErrorActionPreference = "Stop"
|
|
6
|
+
if (Test-Path -LiteralPath $Out) { Remove-Item -LiteralPath $Out -Force } # a failed run must not leave an old PDF for the checker
|
|
7
|
+
$dir = Split-Path $In -Parent; $name = Split-Path $In -Leaf
|
|
8
|
+
if (Test-Path -LiteralPath (Join-Path $dir ("~$" + $name.Substring([Math]::Min(2, $name.Length - 1))))) {
|
|
9
|
+
Write-Output "LOCKED: '$name' is open in Word. Copy it to a scratch folder and run on the copy."; exit 3
|
|
10
|
+
}
|
|
11
|
+
$before = @(Get-Process WINWORD -ErrorAction SilentlyContinue | ForEach-Object { $_.Id })
|
|
12
|
+
$w = New-Object -ComObject Word.Application
|
|
13
|
+
$mine = @(Get-Process WINWORD -ErrorAction SilentlyContinue | Where-Object { $before -notcontains $_.Id } | ForEach-Object { $_.Id })
|
|
14
|
+
try {
|
|
15
|
+
$w.Visible = $false; $w.DisplayAlerts = 0
|
|
16
|
+
$d = $w.Documents.Open($In, $false, $false, $false)
|
|
17
|
+
$d.Fields.Update() | Out-Null
|
|
18
|
+
foreach ($t in $d.TablesOfContents) { $t.Update() }
|
|
19
|
+
foreach ($t in $d.TablesOfFigures) { $t.Update() }
|
|
20
|
+
$d.Repaginate()
|
|
21
|
+
foreach ($t in $d.TablesOfContents) { $t.UpdatePageNumbers() }
|
|
22
|
+
foreach ($t in $d.TablesOfFigures) { $t.UpdatePageNumbers() }
|
|
23
|
+
$d.Save()
|
|
24
|
+
$d.ExportAsFixedFormat($Out, 17)
|
|
25
|
+
$rows = @(); $i = 0; $splits = 0
|
|
26
|
+
foreach ($t in $d.Tables) {
|
|
27
|
+
$i++
|
|
28
|
+
$s = $t.Range.Characters.First.Information(3); $e = $t.Range.Characters.Last.Information(3)
|
|
29
|
+
$txt = ($t.Range.Text -replace "[\r\n\a]", " "); if ($txt.Length -gt 50) { $txt = $txt.Substring(0, 50) }
|
|
30
|
+
if ($s -ne $e) { $splits++; Write-Output ("SPLIT table {0}: physical pages {1}-{2}: {3}" -f $i, $s, $e, $txt) }
|
|
31
|
+
$rows += [pscustomobject]@{ n = $i; start = $s; end = $e; text = $txt }
|
|
32
|
+
}
|
|
33
|
+
$pages = $d.ComputeStatistics(2)
|
|
34
|
+
Write-Output ("pages {0}, tables {1}, split tables {2}" -f $pages, $i, $splits)
|
|
35
|
+
if ($Json) { [pscustomobject]@{ pages = $pages; splits = $splits; tables = $rows } | ConvertTo-Json -Depth 4 | Out-File -Encoding utf8 $Json }
|
|
36
|
+
$d.Close(0)
|
|
37
|
+
} finally {
|
|
38
|
+
try { $w.Quit() } catch {}
|
|
39
|
+
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($w) | Out-Null
|
|
40
|
+
Start-Sleep -Milliseconds 800
|
|
41
|
+
foreach ($id in $mine) { Stop-Process -Id $id -Force -ErrorAction SilentlyContinue }
|
|
42
|
+
}
|