Word Templates vs HTML-to-PDF Pipelines for Business Documents
Choose the document source and rendering model that matches who edits the layout, where generation runs, which final formats are required, and how the output will be tested.
Quick answer: start with the required artifact and operating owner
Choose Word templates when business users must own the layout, reviewers need an editable DOCX, and the process already depends on Word pagination. Choose HTML-to-PDF when developers own the rendering stack, the content also serves a web experience, or generation must run as a browser-based service.
Both approaches can produce acceptable PDFs and both can fail. The decisive differences are authoring ownership, editable output, pagination rules, deployment, asset loading, version control, and the cost of regression testing.
Compare six requirements before selecting the renderer
Who owns the layout?
Word supports familiar editing by document specialists. HTML and CSS normally require developers or a controlled design system.
Is editable DOCX required?
If recipients revise the generated document in Word, a PDF-only browser pipeline does not satisfy the full output contract.
Where must generation run?
A Word workflow depends on a controlled desktop environment. A browser renderer can run locally, in a service, or in cloud infrastructure, depending on the implementation.
How complex is pagination?
Test long tables, headings, page breaks, headers, footers, images, and variable-length content in the actual renderer.
What else reuses the content?
HTML can share components with a web application. Word templates can share styles and assets with other business documents.
What must be governed?
Both need pinned versions, fonts, assets, test cases, approvals, retention, and a controlled release process.
Choose Word templates when the document remains a business artifact
Word is often the direct fit for contracts, letters, case packs, reports, and forms that business users already edit, review, and archive as DOCX.
Business-owned authoring
Editors can work with styles, tables, headers, footers, fields, and page layout in the same application used for review.
DOCX plus PDF
The workflow can retain an editable document and export a fixed-format copy from the same generated result.
Page-oriented review
Reviewers see the document through the same page model used for its normal business editing process.
Controlled local processing
A desktop workflow can keep source data and document generation on the local Windows machine when that is an operating requirement.
Word automation still requires a controlled Word installation, fonts, templates, asset paths, error handling, and realistic pagination tests. A familiar editor does not remove operating dependencies.
Choose HTML-to-PDF when the renderer belongs to an application stack
HTML fits systems where developers already own structured data, components, CSS, deployment, observability, and browser-version control.
Web-content reuse
The same data and components can support an application view and a print-specific output, with separate screen and print styles where required.
Service deployment
A headless browser can run behind an application or job queue without opening Word, provided the infrastructure and security model are controlled.
Code-based components
Developers can test templates, CSS, asset loading, and rendering behavior through the same source-control and deployment practices as the application.
Explicit print rules
Page size, margins, breaks, running content, and print colors belong to the print stylesheet and the chosen engine.
Browser rendering does not turn continuous web layout into reliable pagination automatically. Pin the engine, fonts, assets, and print settings, then regression-test the generated PDFs.
Compare the two pipelines on observable differences
Template editing
Word: familiar to document editors. HTML: normally maintained as markup, CSS, and components by developers.
Primary output
Word: editable DOCX and optional PDF. HTML: browser-rendered PDF unless another editable format is built separately.
Pagination controls
Word: sections, paragraph rules, tables, headers, and page layout. HTML: print CSS, paged-media support, and engine behavior.
Runtime
Word: controlled Windows and Word desktop environment. HTML: pinned browser runtime with controlled fonts and asset access.
Debugging
Word: inspect the generated DOCX, fields, ranges, and export stage. HTML: inspect markup, computed styles, network assets, and browser logs.
Release risk
Both: engine, font, template, data, or asset changes can alter output. Keep representative golden cases and final-PDF review gates.
Run one paired pilot before committing to the architecture
For every TestCaseID, produce one WORD PDF and one HTML PDF from the same frozen input. Record the renderer versions, fonts, templates, assets, and settings outside the timing measurement.
Short and long text
Test minimum, typical, and maximum content length. Look for blank pages, split headings, orphaned labels, and unexpected overflow.
Tables and repeated rows
Test tables that fit on one page and tables that cross several pages, including repeated headings and row-splitting rules.
Images and fonts
Use the same approved assets. Confirm sizing, aspect ratio, missing-font behavior, and whether every resource is embedded or reliably available.
Review and accessibility
Compare text extraction, reading order, links, bookmarks, metadata, and the accessibility requirements that apply to the real document.
BuildSeconds is useful, but also record setup, failure recovery, review time, correction time, deployment work, and the cost of maintaining the pipeline after updates.
Create a comparable pilot evidence sheet
Save the workbook as an Excel Macro-Enabled Workbook (.xlsm). Create PilotResults and use the exact A–L header order below.
A — TestCaseID; B — PipelineType; C — SourceVersion; D — OutputFile; E — BuildSeconds; F — FileBytes; G — PageCount; H — VisualCheck; I — TextCheck; J — AccessibilityCheck; K — Reviewer; L — ReviewStatus.
One pair per test
PipelineType must be exactly WORD or HTML. Each TestCaseID must contain one of each and use the same SourceVersion.
Controlled PDF folder
Place the generated files in PilotOutputs beside the workbook. Enter filenames only, not paths.
Explicit checks
VisualCheck and TextCheck use PASS or FAIL. AccessibilityCheck uses PASS, FAIL, or NOT_APPLICABLE with a documented reason outside the macro.
Human release status
ReviewStatus uses APPROVED, REJECTED, or PENDING. The helper blocks APPROVED when a recorded check has failed.
Free VBA helper: audit a Word-versus-HTML pilot
The macro validates exact headers and controlled values, requires one WORD and one HTML result per test case, verifies that both use the same source version, checks each PDF signature and byte count, and appends evidence to PipelinePilotAudit.
No renderer execution
The helper does not run Word, Chromium, or any HTML service. Generate the candidate files through their real production-like environments.
Comparable pairs
Duplicate or missing WORD/HTML rows, mismatched source versions, and reused filenames receive ERROR.
PDF evidence
The file must exist under PilotOutputs, start with a PDF signature, and match the recorded FileBytes value.
No artificial score
The report preserves timings, page counts, checks, and reviewer status without hiding trade-offs inside one weighted number.
Option Explicit
Private Const PILOT_SHEET As String = "PilotResults"
Private Const AUDIT_SHEET As String = "PipelinePilotAudit"
Private Const OUTPUT_FOLDER As String = "PilotOutputs"
Private Const FIRST_DATA_ROW As Long = 2
Private Const COL_TEST_CASE_ID As Long = 1
Private Const COL_PIPELINE_TYPE As Long = 2
Private Const COL_SOURCE_VERSION As Long = 3
Private Const COL_OUTPUT_FILE As Long = 4
Private Const COL_BUILD_SECONDS As Long = 5
Private Const COL_FILE_BYTES As Long = 6
Private Const COL_PAGE_COUNT As Long = 7
Private Const COL_VISUAL_CHECK As Long = 8
Private Const COL_TEXT_CHECK As Long = 9
Private Const COL_ACCESSIBILITY_CHECK As Long = 10
Private Const COL_REVIEWER As Long = 11
Private Const COL_REVIEW_STATUS As Long = 12
Private Const FILE_ATTRIBUTES As Long = 39
Public Sub AuditDocumentPipelinePilot()
Dim wb As Workbook
Dim pilotWs As Worksheet
Dim auditWs As Worksheet
Dim pairOwners As Object
Dim outputOwners As Object
Dim testCases As Object
Dim wordRows As Object
Dim htmlRows As Object
Dim lastRow As Long
Dim rowCount As Long
Dim dataIndex As Long
Dim nextAuditRow As Long
Dim values As Variant
Dim rowValid() As Boolean
Dim rowMessage() As String
Dim actualBytes() As Double
Dim outputPaths() As String
Dim runId As String
Dim outputFolderPath As String
Dim resultText As String
Dim errorCount As Long
On Error GoTo CleanFail
Set wb = ThisWorkbook
If wb.Path = vbNullString Then
Err.Raise vbObjectError + 4300, , _
"Save this workbook as an .xlsm file before running the audit."
End If
If wb.ReadOnly Then
Err.Raise vbObjectError + 4301, , _
"The workbook is read-only. Open a writable copy before running the audit."
End If
Set pilotWs = GetRequiredWorksheet(wb, PILOT_SHEET)
If pilotWs.ProtectContents Then
Err.Raise vbObjectError + 4302, , _
"The PilotResults sheet is protected. Unprotect it before running the audit."
End If
ValidatePilotHeaders pilotWs
lastRow = LastUsedRow(pilotWs)
If lastRow < FIRST_DATA_ROW Then
Err.Raise vbObjectError + 4303, , _
"No pilot records were found on PilotResults."
End If
rowCount = lastRow - FIRST_DATA_ROW + 1
values = pilotWs.Range( _
pilotWs.Cells(FIRST_DATA_ROW, COL_TEST_CASE_ID), _
pilotWs.Cells(lastRow, COL_REVIEW_STATUS)).Value2
ReDim rowValid(1 To rowCount)
ReDim rowMessage(1 To rowCount)
ReDim actualBytes(1 To rowCount)
ReDim outputPaths(1 To rowCount)
outputFolderPath = wb.Path & Application.PathSeparator & OUTPUT_FOLDER
RequireFolder outputFolderPath
Set pairOwners = CreateObject("Scripting.Dictionary")
pairOwners.CompareMode = vbTextCompare
Set outputOwners = CreateObject("Scripting.Dictionary")
outputOwners.CompareMode = vbTextCompare
Set testCases = CreateObject("Scripting.Dictionary")
testCases.CompareMode = vbTextCompare
Set wordRows = CreateObject("Scripting.Dictionary")
wordRows.CompareMode = vbTextCompare
Set htmlRows = CreateObject("Scripting.Dictionary")
htmlRows.CompareMode = vbTextCompare
' Pass 1 validates each row and the referenced PDF without running either pipeline.
For dataIndex = 1 To rowCount
PreflightPilotRow values, dataIndex, FIRST_DATA_ROW + dataIndex - 1, _
outputFolderPath, rowValid(dataIndex), rowMessage(dataIndex), _
outputPaths(dataIndex), actualBytes(dataIndex)
If rowValid(dataIndex) Then
RegisterPilotRow values, dataIndex, pairOwners, outputOwners, _
testCases, wordRows, htmlRows, rowValid, rowMessage
End If
Next dataIndex
' Pass 2 proves that every test case has one comparable WORD/HTML pair.
ValidatePilotPairs values, testCases, wordRows, htmlRows, rowValid, rowMessage
Set auditWs = GetOrCreateAuditSheet(wb)
If auditWs.ProtectContents Then
Err.Raise vbObjectError + 4304, , _
"The PipelinePilotAudit sheet is protected."
End If
ValidateAuditHeaders auditWs
nextAuditRow = NextAuditRow(auditWs)
runId = Format$(Now, "yyyymmdd-hhnnss")
For dataIndex = 1 To rowCount
If rowValid(dataIndex) Then
resultText = "PASS"
Else
resultText = "ERROR"
errorCount = errorCount + 1
End If
AppendAuditRow auditWs, nextAuditRow, runId, values, dataIndex, _
actualBytes(dataIndex), resultText, rowMessage(dataIndex)
nextAuditRow = nextAuditRow + 1
Next dataIndex
auditWs.Columns("A:Q").AutoFit
wb.Save
MsgBox "Pipeline pilot audit complete." & vbCrLf & _
"Run ID: " & runId & vbCrLf & _
"Pilot rows: " & rowCount & vbCrLf & _
"Errors: " & errorCount & vbCrLf & _
"Review: " & AUDIT_SHEET, vbInformation
Exit Sub
CleanFail:
MsgBox "Audit stopped: " & Err.Description, vbCritical
End Sub
Private Sub PreflightPilotRow( _
ByRef values As Variant, _
ByVal dataIndex As Long, _
ByVal sheetRow As Long, _
ByVal outputFolderPath As String, _
ByRef isValid As Boolean, _
ByRef validationMessage As String, _
ByRef outputPath As String, _
ByRef actualFileBytes As Double)
Dim testCaseId As String
Dim pipelineType As String
Dim sourceVersion As String
Dim outputFile As String
Dim visualCheck As String
Dim textCheck As String
Dim accessibilityCheck As String
Dim reviewer As String
Dim reviewStatus As String
Dim buildSeconds As Double
Dim recordedBytes As Double
Dim pageCount As Long
On Error GoTo InvalidRow
testCaseId = RequireExactText(values(dataIndex, COL_TEST_CASE_ID), _
"TestCaseID", sheetRow)
pipelineType = RequireExactText(values(dataIndex, COL_PIPELINE_TYPE), _
"PipelineType", sheetRow)
sourceVersion = RequireExactText(values(dataIndex, COL_SOURCE_VERSION), _
"SourceVersion", sheetRow)
outputFile = RequireExactText(values(dataIndex, COL_OUTPUT_FILE), _
"OutputFile", sheetRow)
buildSeconds = RequirePositiveNumber(values(dataIndex, COL_BUILD_SECONDS), _
"BuildSeconds", sheetRow)
recordedBytes = RequirePositiveWholeNumber( _
values(dataIndex, COL_FILE_BYTES), "FileBytes", sheetRow)
pageCount = RequirePositiveWholeNumber( _
values(dataIndex, COL_PAGE_COUNT), "PageCount", sheetRow)
visualCheck = RequireExactText(values(dataIndex, COL_VISUAL_CHECK), _
"VisualCheck", sheetRow)
textCheck = RequireExactText(values(dataIndex, COL_TEXT_CHECK), _
"TextCheck", sheetRow)
accessibilityCheck = RequireExactText( _
values(dataIndex, COL_ACCESSIBILITY_CHECK), _
"AccessibilityCheck", sheetRow)
reviewer = RequireExactText(values(dataIndex, COL_REVIEWER), _
"Reviewer", sheetRow)
reviewStatus = RequireExactText(values(dataIndex, COL_REVIEW_STATUS), _
"ReviewStatus", sheetRow)
ValidateIdentifier testCaseId, "TestCaseID", sheetRow
ValidateIdentifier sourceVersion, "SourceVersion", sheetRow
If pipelineType <> "WORD" And pipelineType <> "HTML" Then
Err.Raise vbObjectError + 4310, , _
"Row " & sheetRow & ": PipelineType must be exactly WORD or HTML."
End If
If visualCheck <> "PASS" And visualCheck <> "FAIL" Then
Err.Raise vbObjectError + 4311, , _
"Row " & sheetRow & ": VisualCheck must be exactly PASS or FAIL."
End If
If textCheck <> "PASS" And textCheck <> "FAIL" Then
Err.Raise vbObjectError + 4312, , _
"Row " & sheetRow & ": TextCheck must be exactly PASS or FAIL."
End If
If accessibilityCheck <> "PASS" And accessibilityCheck <> "FAIL" And _
accessibilityCheck <> "NOT_APPLICABLE" Then
Err.Raise vbObjectError + 4313, , _
"Row " & sheetRow & _
": AccessibilityCheck must be PASS, FAIL, or NOT_APPLICABLE."
End If
If reviewStatus <> "APPROVED" And reviewStatus <> "REJECTED" And _
reviewStatus <> "PENDING" Then
Err.Raise vbObjectError + 4314, , _
"Row " & sheetRow & _
": ReviewStatus must be APPROVED, REJECTED, or PENDING."
End If
If reviewStatus = "APPROVED" Then
If visualCheck <> "PASS" Or textCheck <> "PASS" Or _
accessibilityCheck = "FAIL" Then
Err.Raise vbObjectError + 4315, , _
"Row " & sheetRow & _
": APPROVED conflicts with one or more failed checks."
End If
End If
ValidatePdfFileName outputFile, sheetRow
outputPath = outputFolderPath & Application.PathSeparator & outputFile
ReadPdfMetadata outputPath, actualFileBytes
If actualFileBytes <> recordedBytes Then
Err.Raise vbObjectError + 4316, , _
"Row " & sheetRow & ": recorded FileBytes is " & _
Format$(recordedBytes, "0") & ", but the PDF contains " & _
Format$(actualFileBytes, "0") & " bytes."
End If
' Keep all required variables in the explicit evidence contract.
If Len(reviewer) = 0 Or buildSeconds <= 0 Or pageCount <= 0 Then
Err.Raise vbObjectError + 4317, , _
"Row " & sheetRow & ": incomplete pilot evidence."
End If
isValid = True
validationMessage = "Row evidence and PDF file passed preflight."
Exit Sub
InvalidRow:
isValid = False
validationMessage = Err.Description
Err.Clear
End Sub
Private Sub RegisterPilotRow( _
ByRef values As Variant, _
ByVal dataIndex As Long, _
ByVal pairOwners As Object, _
ByVal outputOwners As Object, _
ByVal testCases As Object, _
ByVal wordRows As Object, _
ByVal htmlRows As Object, _
ByRef rowValid() As Boolean, _
ByRef rowMessage() As String)
Dim testCaseId As String
Dim pipelineType As String
Dim outputFile As String
Dim pairKey As String
Dim firstIndex As Long
testCaseId = CStr(values(dataIndex, COL_TEST_CASE_ID))
pipelineType = CStr(values(dataIndex, COL_PIPELINE_TYPE))
outputFile = CStr(values(dataIndex, COL_OUTPUT_FILE))
pairKey = testCaseId & "|" & pipelineType
If Not testCases.Exists(testCaseId) Then testCases.Add testCaseId, True
If pairOwners.Exists(pairKey) Then
firstIndex = CLng(pairOwners(pairKey))
MarkRowError rowValid, rowMessage, firstIndex, _
"Duplicate " & pipelineType & " result for TestCaseID " & testCaseId & "."
MarkRowError rowValid, rowMessage, dataIndex, _
"Duplicate " & pipelineType & " result for TestCaseID " & testCaseId & "."
Else
pairOwners.Add pairKey, dataIndex
If pipelineType = "WORD" Then
wordRows.Add testCaseId, dataIndex
Else
htmlRows.Add testCaseId, dataIndex
End If
End If
If outputOwners.Exists(outputFile) Then
firstIndex = CLng(outputOwners(outputFile))
MarkRowError rowValid, rowMessage, firstIndex, _
"OutputFile is reused by another pilot row: " & outputFile & "."
MarkRowError rowValid, rowMessage, dataIndex, _
"OutputFile is reused by another pilot row: " & outputFile & "."
Else
outputOwners.Add outputFile, dataIndex
End If
End Sub
Private Sub ValidatePilotPairs( _
ByRef values As Variant, _
ByVal testCases As Object, _
ByVal wordRows As Object, _
ByVal htmlRows As Object, _
ByRef rowValid() As Boolean, _
ByRef rowMessage() As String)
Dim testCaseId As Variant
Dim wordIndex As Long
Dim htmlIndex As Long
Dim wordVersion As String
Dim htmlVersion As String
For Each testCaseId In testCases.Keys
wordIndex = 0
htmlIndex = 0
If wordRows.Exists(CStr(testCaseId)) Then _
wordIndex = CLng(wordRows(CStr(testCaseId)))
If htmlRows.Exists(CStr(testCaseId)) Then _
htmlIndex = CLng(htmlRows(CStr(testCaseId)))
If wordIndex = 0 Then
If htmlIndex > 0 Then
MarkRowError rowValid, rowMessage, htmlIndex, _
"Missing WORD result for TestCaseID " & CStr(testCaseId) & "."
End If
ElseIf htmlIndex = 0 Then
MarkRowError rowValid, rowMessage, wordIndex, _
"Missing HTML result for TestCaseID " & CStr(testCaseId) & "."
ElseIf Not rowValid(wordIndex) Or Not rowValid(htmlIndex) Then
If rowValid(wordIndex) Then
MarkRowError rowValid, rowMessage, wordIndex, _
"The paired HTML result is invalid for TestCaseID " & _
CStr(testCaseId) & "."
End If
If rowValid(htmlIndex) Then
MarkRowError rowValid, rowMessage, htmlIndex, _
"The paired WORD result is invalid for TestCaseID " & _
CStr(testCaseId) & "."
End If
Else
wordVersion = CStr(values(wordIndex, COL_SOURCE_VERSION))
htmlVersion = CStr(values(htmlIndex, COL_SOURCE_VERSION))
If StrComp(wordVersion, htmlVersion, vbBinaryCompare) <> 0 Then
MarkRowError rowValid, rowMessage, wordIndex, _
"SourceVersion does not match the HTML result."
MarkRowError rowValid, rowMessage, htmlIndex, _
"SourceVersion does not match the WORD result."
End If
End If
Next testCaseId
End Sub
Private Sub MarkRowError( _
ByRef rowValid() As Boolean, _
ByRef rowMessage() As String, _
ByVal dataIndex As Long, _
ByVal messageText As String)
If rowValid(dataIndex) Then
rowMessage(dataIndex) = messageText
ElseIf Len(rowMessage(dataIndex)) > 0 Then
rowMessage(dataIndex) = rowMessage(dataIndex) & " " & messageText
Else
rowMessage(dataIndex) = messageText
End If
rowValid(dataIndex) = False
End Sub
Private Function RequireExactText( _
ByVal rawValue As Variant, _
ByVal fieldName As String, _
ByVal sheetRow As Long) As String
Dim textValue As String
If IsError(rawValue) Then
Err.Raise vbObjectError + 4320, , _
"Row " & sheetRow & ": " & fieldName & " contains an Excel error."
End If
If VarType(rawValue) <> vbString Then
Err.Raise vbObjectError + 4321, , _
"Row " & sheetRow & ": " & fieldName & " must be stored as text."
End If
textValue = CStr(rawValue)
If Len(textValue) = 0 Then
Err.Raise vbObjectError + 4322, , _
"Row " & sheetRow & ": " & fieldName & " is required."
End If
If textValue <> Trim$(textValue) Then
Err.Raise vbObjectError + 4323, , _
"Row " & sheetRow & ": " & fieldName & _
" has leading or trailing whitespace."
End If
If ContainsControlCharacter(textValue) Then
Err.Raise vbObjectError + 4324, , _
"Row " & sheetRow & ": " & fieldName & _
" contains a control character."
End If
RequireExactText = textValue
End Function
Private Function RequirePositiveNumber( _
ByVal rawValue As Variant, _
ByVal fieldName As String, _
ByVal sheetRow As Long) As Double
If IsError(rawValue) Or Not IsNumeric(rawValue) Then
Err.Raise vbObjectError + 4330, , _
"Row " & sheetRow & ": " & fieldName & _
" must be a positive number."
End If
If CDbl(rawValue) <= 0 Then
Err.Raise vbObjectError + 4331, , _
"Row " & sheetRow & ": " & fieldName & _
" must be greater than zero."
End If
RequirePositiveNumber = CDbl(rawValue)
End Function
Private Function RequirePositiveWholeNumber( _
ByVal rawValue As Variant, _
ByVal fieldName As String, _
ByVal sheetRow As Long) As Long
Dim numericValue As Double
If IsError(rawValue) Or Not IsNumeric(rawValue) Then
Err.Raise vbObjectError + 4340, , _
"Row " & sheetRow & ": " & fieldName & _
" must be a positive whole number."
End If
numericValue = CDbl(rawValue)
If numericValue <= 0 Or numericValue <> Fix(numericValue) Or _
numericValue > 2147483647# Then
Err.Raise vbObjectError + 4341, , _
"Row " & sheetRow & ": " & fieldName & _
" must be a positive whole number."
End If
RequirePositiveWholeNumber = CLng(numericValue)
End Function
Private Sub ValidateIdentifier( _
ByVal value As String, _
ByVal fieldName As String, _
ByVal sheetRow As Long)
Dim index As Long
Dim character As String
For index = 1 To Len(value)
character = Mid$(value, index, 1)
If Not (character Like "[A-Za-z0-9_.-]") Then
Err.Raise vbObjectError + 4350, , _
"Row " & sheetRow & ": " & fieldName & _
" may contain only letters, digits, underscore, hyphen, and dot."
End If
Next index
End Sub
Private Sub ValidatePdfFileName(ByVal fileName As String, ByVal sheetRow As Long)
Dim forbidden As Variant
Dim item As Variant
Dim dotPosition As Long
Dim baseName As String
If InStr(1, fileName, "\", vbBinaryCompare) > 0 Or _
InStr(1, fileName, "/", vbBinaryCompare) > 0 Or _
InStr(1, fileName, ":", vbBinaryCompare) > 0 Then
Err.Raise vbObjectError + 4360, , _
"Row " & sheetRow & ": OutputFile must be a file name, not a path."
End If
forbidden = Array("*", "?", Chr$(34), "<", ">", "|")
For Each item In forbidden
If InStr(1, fileName, CStr(item), vbBinaryCompare) > 0 Then
Err.Raise vbObjectError + 4361, , _
"Row " & sheetRow & ": OutputFile contains a forbidden Windows character."
End If
Next item
If Right$(fileName, 1) = "." Or Right$(fileName, 1) = " " Then
Err.Raise vbObjectError + 4362, , _
"Row " & sheetRow & ": OutputFile cannot end with a dot or space."
End If
If LCase$(Right$(fileName, 4)) <> ".pdf" Then
Err.Raise vbObjectError + 4363, , _
"Row " & sheetRow & ": OutputFile must end in .pdf."
End If
dotPosition = InStr(1, fileName, ".", vbBinaryCompare)
If dotPosition <= 1 Then
Err.Raise vbObjectError + 4364, , _
"Row " & sheetRow & ": OutputFile has an invalid base name."
End If
baseName = Left$(fileName, dotPosition - 1)
If IsReservedWindowsName(baseName) Then
Err.Raise vbObjectError + 4365, , _
"Row " & sheetRow & ": OutputFile uses a reserved Windows name."
End If
End Sub
Private Function IsReservedWindowsName(ByVal baseName As String) As Boolean
Dim normalized As String
Dim suffix As String
normalized = UCase$(baseName)
Select Case normalized
Case "CON", "PRN", "AUX", "NUL", "CLOCK$"
IsReservedWindowsName = True
Exit Function
End Select
If Left$(normalized, 3) = "COM" Or Left$(normalized, 3) = "LPT" Then
suffix = Mid$(normalized, 4)
If suffix Like "[1-9]" Or suffix = ChrW$(&HB9) Or _
suffix = ChrW$(&HB2) Or suffix = ChrW$(&HB3) Then
IsReservedWindowsName = True
End If
End If
End Function
Private Function ContainsControlCharacter(ByVal value As String) As Boolean
Dim index As Long
Dim codePoint As Long
For index = 1 To Len(value)
codePoint = AscW(Mid$(value, index, 1))
If codePoint >= 0 And codePoint <= 31 Then
ContainsControlCharacter = True
Exit Function
End If
Next index
End Function
Private Sub ReadPdfMetadata(ByVal filePath As String, ByRef actualBytes As Double)
Dim foundName As String
Dim fileNumber As Integer
Dim signature As String
On Error GoTo FileError
foundName = Dir$(filePath, FILE_ATTRIBUTES)
If Len(foundName) = 0 Then
Err.Raise vbObjectError + 4370, , "PDF file was not found: " & filePath
End If
actualBytes = CDbl(FileLen(filePath))
If actualBytes < 5 Then
Err.Raise vbObjectError + 4371, , "PDF file is too small: " & filePath
End If
fileNumber = FreeFile
Open filePath For Binary Access Read As #fileNumber
signature = Space$(5)
Get #fileNumber, 1, signature
Close #fileNumber
fileNumber = 0
If signature <> "%PDF-" Then
Err.Raise vbObjectError + 4372, , _
"The file does not begin with a PDF signature: " & filePath
End If
Exit Sub
FileError:
On Error Resume Next
If fileNumber > 0 Then Close #fileNumber
On Error GoTo 0
Err.Raise vbObjectError + 4373, , _
"PDF file could not be checked: " & filePath & ". " & Err.Description
End Sub
Private Sub RequireFolder(ByVal folderPath As String)
Dim attributes As Long
On Error GoTo FolderError
attributes = GetAttr(folderPath)
If (attributes And vbDirectory) = 0 Then
Err.Raise vbObjectError + 4380, , _
"PilotOutputs is not a folder: " & folderPath
End If
Exit Sub
FolderError:
Err.Raise vbObjectError + 4381, , _
"PilotOutputs could not be accessed: " & folderPath & ". " & Err.Description
End Sub
Private Function GetRequiredWorksheet( _
ByVal wb As Workbook, _
ByVal sheetName As String) As Worksheet
On Error Resume Next
Set GetRequiredWorksheet = wb.Worksheets(sheetName)
On Error GoTo 0
If GetRequiredWorksheet Is Nothing Then
Err.Raise vbObjectError + 4390, , _
"Required worksheet not found: " & sheetName
End If
End Function
Private Function GetOrCreateAuditSheet(ByVal wb As Workbook) As Worksheet
On Error Resume Next
Set GetOrCreateAuditSheet = wb.Worksheets(AUDIT_SHEET)
On Error GoTo 0
If GetOrCreateAuditSheet Is Nothing Then
Set GetOrCreateAuditSheet = wb.Worksheets.Add( _
After:=wb.Worksheets(wb.Worksheets.Count))
GetOrCreateAuditSheet.Name = AUDIT_SHEET
WriteAuditHeaders GetOrCreateAuditSheet
End If
End Function
Private Function LastUsedRow(ByVal ws As Worksheet) As Long
Dim lastCell As Range
Set lastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, MatchCase:=False)
If lastCell Is Nothing Then
LastUsedRow = 0
Else
LastUsedRow = lastCell.Row
End If
End Function
Private Sub ValidatePilotHeaders(ByVal ws As Worksheet)
Dim headers As Variant
Dim columnNumber As Long
Dim rawValue As Variant
headers = Array("TestCaseID", "PipelineType", "SourceVersion", _
"OutputFile", "BuildSeconds", "FileBytes", "PageCount", _
"VisualCheck", "TextCheck", "AccessibilityCheck", _
"Reviewer", "ReviewStatus")
For columnNumber = 1 To UBound(headers) + 1
rawValue = ws.Cells(1, columnNumber).Value2
If IsError(rawValue) Or VarType(rawValue) <> vbString Then
Err.Raise vbObjectError + 4400, , _
"Header " & ws.Cells(1, columnNumber).Address(False, False) & _
" must be stored as exact text."
End If
If CStr(rawValue) <> CStr(headers(columnNumber - 1)) Then
Err.Raise vbObjectError + 4401, , _
"Expected header " & headers(columnNumber - 1) & " in " & _
ws.Cells(1, columnNumber).Address(False, False) & "."
End If
Next columnNumber
End Sub
Private Function AuditHeaders() As Variant
AuditHeaders = Array("RunID", "TestCaseID", "PipelineType", _
"SourceVersion", "OutputFile", "RecordedBytes", "ActualBytes", _
"BuildSeconds", "PageCount", "VisualCheck", "TextCheck", _
"AccessibilityCheck", "Reviewer", "ReviewStatus", "Result", _
"Message", "LoggedAt")
End Function
Private Sub WriteAuditHeaders(ByVal ws As Worksheet)
Dim headers As Variant
Dim columnNumber As Long
headers = AuditHeaders()
For columnNumber = 1 To UBound(headers) + 1
ws.Cells(1, columnNumber).Value = headers(columnNumber - 1)
Next columnNumber
End Sub
Private Sub ValidateAuditHeaders(ByVal ws As Worksheet)
Dim headers As Variant
Dim columnNumber As Long
headers = AuditHeaders()
For columnNumber = 1 To UBound(headers) + 1
If CStr(ws.Cells(1, columnNumber).Value2) <> _
CStr(headers(columnNumber - 1)) Then
Err.Raise vbObjectError + 4410, , _
"The PipelinePilotAudit headers do not match the expected contract."
End If
Next columnNumber
End Sub
Private Function NextAuditRow(ByVal ws As Worksheet) As Long
Dim lastRow As Long
lastRow = LastUsedRow(ws)
If lastRow < 1 Then
WriteAuditHeaders ws
NextAuditRow = 2
Else
NextAuditRow = lastRow + 1
End If
End Function
Private Sub AppendAuditRow( _
ByVal ws As Worksheet, _
ByVal targetRow As Long, _
ByVal runId As String, _
ByRef values As Variant, _
ByVal dataIndex As Long, _
ByVal actualFileBytes As Double, _
ByVal resultText As String, _
ByVal messageText As String)
ws.Cells(targetRow, 1).Value = runId
ws.Cells(targetRow, 2).Value = values(dataIndex, COL_TEST_CASE_ID)
ws.Cells(targetRow, 3).Value = values(dataIndex, COL_PIPELINE_TYPE)
ws.Cells(targetRow, 4).Value = values(dataIndex, COL_SOURCE_VERSION)
ws.Cells(targetRow, 5).Value = values(dataIndex, COL_OUTPUT_FILE)
ws.Cells(targetRow, 6).Value = values(dataIndex, COL_FILE_BYTES)
ws.Cells(targetRow, 7).Value = actualFileBytes
ws.Cells(targetRow, 8).Value = values(dataIndex, COL_BUILD_SECONDS)
ws.Cells(targetRow, 9).Value = values(dataIndex, COL_PAGE_COUNT)
ws.Cells(targetRow, 10).Value = values(dataIndex, COL_VISUAL_CHECK)
ws.Cells(targetRow, 11).Value = values(dataIndex, COL_TEXT_CHECK)
ws.Cells(targetRow, 12).Value = values(dataIndex, COL_ACCESSIBILITY_CHECK)
ws.Cells(targetRow, 13).Value = values(dataIndex, COL_REVIEWER)
ws.Cells(targetRow, 14).Value = values(dataIndex, COL_REVIEW_STATUS)
ws.Cells(targetRow, 15).Value = resultText
ws.Cells(targetRow, 16).Value = messageText
ws.Cells(targetRow, 17).Value = Now
End SubWord exposes fixed-format PDF export through Document.ExportAsFixedFormat. Puppeteer documents that Page.pdf() uses print CSS media by default. The W3C CSS Paged Media draft defines page-oriented controls such as size, margins, headers, footers, and page breaks.
Interpret the pilot without turning one metric into the decision
Faster build, slower review
A lower BuildSeconds value may be irrelevant if reviewers spend more time correcting page breaks or cannot edit the source artifact.
Smaller PDF, missing evidence
A smaller file is not automatically better. Confirm images, fonts, links, tags, metadata, and text extraction before comparing size.
Equal pages, different layout
PageCount is only a coarse signal. Review representative pages and content boundaries, not just the total.
One test case passes
A simple letter does not prove the pipeline can handle the longest table, largest image, optional sections, or multilingual content.
All checks pass
PASS confirms the recorded pilot contract. It does not prove production security, scalability, legal compliance, or future engine stability.
Mixed result
A hybrid architecture may be valid when one document family needs editable Word output and another is native to a web application.
Govern the selected pipeline as a production dependency
Pin the environment
Record Word or browser version, fonts, locale, templates, CSS, assets, and export options for every release.
Protect source data
Map where data, temporary files, logs, PDFs, and backups travel. “HTML” does not imply cloud, and “Word” does not automatically imply isolation.
Keep golden test cases
Preserve representative inputs and approved outputs for automated checks plus human visual review after material updates.
Separate generation from approval
A successful render is not authorization to release a contract, report, signature image, regulated notice, or accessibility claim.
Plan failure recovery
Define idempotency, output naming, partial-file handling, retries, logs, and how operators resume without duplicating records.
Measure maintenance
Track correction time, regression scope, deployment effort, and incident recovery—not only throughput in a clean benchmark.
Use DocxForge Pro when the chosen source is Word templates
DocxForge Pro is not an HTML-to-PDF renderer. It runs local Word-template workflows through Contractor and Factory and can create editable DOCX plus PDF output.
Contractor: one case, several different documents
Review one case dataset, then generate several different documents for that case from different Word templates. Use it when one customer, matter, property, or project needs a coordinated document pack.
Factory: many rows, one standard template
Select many independent Excel rows and apply one standard Word template to each selected row. Every row creates its own document for the same repeatable document type.
Choose DocxForge Pro after the pilot confirms that Word templates fit the required output and operating model. Use a separate HTML architecture when browser rendering is the actual requirement.
Contractor: different Word templates for one case
Review one case, then choose the different documents required for its pack.


Factory: one Word template across many rows
Review independent Excel rows, then apply one standard Word template to the batch.


Frequently asked questions
Are Word templates or HTML-to-PDF pipelines better for business documents?
Neither is universally better. Word templates usually fit business-owned layouts, editable DOCX delivery, and desktop review. HTML-to-PDF pipelines usually fit developer-owned systems, web-content reuse, CSS components, and service deployment. Choose from the required output and operating model.
Can an HTML-to-PDF pipeline produce an editable Word document?
Not by default. A browser PDF is a final-format output, not an editable DOCX. If users must revise the generated document in Word, include that requirement in the architecture decision and pilot.
Does Word guarantee identical PDF pagination on every machine?
No. Fonts, Word version, printer and layout environment, linked assets, and template content can affect pagination. Control the production environment and test the final PDF, not only the DOCX.
Does HTML automatically solve complex pagination?
No. Browser PDF generation uses print CSS and a specific rendering engine. Long tables, page breaks, running content, fonts, images, and engine upgrades still require explicit testing.
What does the VBA helper compare?
It validates evidence from a paired pilot. Each TestCaseID must have one WORD result and one HTML result created from the same SourceVersion. It checks the referenced PDF files, recorded sizes, page counts, review fields, and approval consistency. It does not run either renderer or calculate an artificial winner score.
Does DocxForge Pro render HTML templates?
No. DocxForge Pro is a Word-template workflow. Contractor creates several different documents for one reviewed case from different Word templates. Factory applies one standard Word template to many independent Excel rows and creates a separate document per selected row.