Plain text to PDF¶
Converts a plain-text stream to PDF bytes by splitting the text into fixed-size line blocks and drawing each block onto its own page with fixed typography. The PDF/A conformance level is not applied here — the produced PDF is resubmitted through Convert a source document to PDF for that.
| Field | Value |
|---|---|
| Operation ID | OP-SFC-006 |
| Trigger | Called by Execute a single conversion (converter template) via TxtConverter.ConvertItem, dispatched from Convert a source document to PDF for txt |
| Inputs | Source Stream, ConvertRequest |
| Outputs | PDF byte[] |
| Primary components | TxtConverter.ConvertItem, TxtConverter.LinesPerPage |
| Entry point | PdfApi.SyncFusionCore\Convert\TxtConverter.cs |
Steps¶
- Read the whole stream as ASCII text (BR-SFC-012).
- Split the text on
Environment.NewLine(StringSplitOptions.None) into a line array. - Create an unconstrained
PdfDocument— the PDF/A conformance level is not applied here (BR-SFC-004); the PDF/A upgrade happens when Convert a source document to PDF step 4 recursively resubmits the produced PDF. - Loop: take
LinesPerPage(default 40) lines starting at the current offset, joined with\r\nviaSAIF.Common.Extensions.ToStringAll(BR-SFC-014). - Add a page, create a 12 pt
PdfStandardFont(Helvetica), and aPdfStringFormatwithJustifyalignment,Topline alignment and a 15 pt paragraph indent; draw the block into the page client rectangle (BR-SFC-015). - Advance the offset by
LinesPerPage; stop when the offset reaches the line count (BR-SFC-014). - Save to a
MemoryStream, close the document, and return the bytes.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start(["ConvertItem called<br>with stream, request"]) --> Read[Read stream as ASCII text]
Read --> Split["Split into lines on<br>Environment.NewLine"]
Split --> Create["Create unconstrained<br>PdfDocument"]
Create --> Loop{"Offset < line count?"}
Loop -->|Yes| TakeBlock["Take LinesPerPage lines<br>from current offset"]
TakeBlock --> Draw["Add page, draw block with<br>12pt Helvetica, justified,<br>15pt indent"]
Draw --> Advance["Advance offset<br>by LinesPerPage"]
Advance --> Loop
Loop -->|No| Save["Save to MemoryStream,<br>close document"]
Save --> Return([Return PDF bytes])
Failure and edge-case behavior¶
- Any Syncfusion conversion failure surfaces as an exception, which is caught by
Execute a single conversion (converter template) and turned into a failed
PdfResultrather than propagated here. LinesPerPageis a public instance field, so a caller with a directTxtConverterreference can override the default 40-line pagination.
Related documentation¶
Sources¶
PdfApi.SyncFusionCore\Convert\TxtConverter.cs