Skip to content

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

  1. Read the whole stream as ASCII text (BR-SFC-012).
  2. Split the text on Environment.NewLine (StringSplitOptions.None) into a line array.
  3. 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.
  4. Loop: take LinesPerPage (default 40) lines starting at the current offset, joined with \r\n via SAIF.Common.Extensions.ToStringAll (BR-SFC-014).
  5. Add a page, create a 12 pt PdfStandardFont(Helvetica), and a PdfStringFormat with Justify alignment, Top line alignment and a 15 pt paragraph indent; draw the block into the page client rectangle (BR-SFC-015).
  6. Advance the offset by LinesPerPage; stop when the offset reaches the line count (BR-SFC-014).
  7. 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 PdfResult rather than propagated here.
  • LinesPerPage is a public instance field, so a caller with a direct TxtConverter reference can override the default 40-line pagination.

Sources

  • PdfApi.SyncFusionCore\Convert\TxtConverter.cs