RTF document to PDF¶
Converts an RTF document stream to PDF bytes by rendering the RTF text as a metafile and drawing it across as many pages as the content requires.
| Field | Value |
|---|---|
| Operation ID | OP-SFC-005 |
| Trigger | Called by Execute a single conversion (converter template) via RtfConverter.ConvertItem, dispatched from Convert a source document to PDF for rtf |
| Inputs | Source Stream, ConvertRequest |
| Outputs | PDF byte[] |
| Primary components | RtfConverter.ConvertItem |
| Entry point | PdfApi.SyncFusionCore\Convert\RtfConverter.cs |
Steps¶
- Choose conformance:
Pdf_A1BwhenIsPdfa, otherwiseNone; create aPdfDocumentwith it (BR-SFC-011). - Add one page and read its client bounds.
- Read the whole stream as ASCII text (
StreamReader(stream, Encoding.ASCII)) (BR-SFC-012). - Convert the RTF text to a metafile with
PdfImage.FromRtf(text, bounds.Width, PdfImageType.Metafile). - Set
PdfMetafileLayoutFormat.SplitTextLines = trueso text flows across pages without a break, and draw the metafile at origin (BR-SFC-013). - 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"]) --> Conf["Choose conformance<br>Pdf_A1B or None"]
Conf --> Create["Create PdfDocument,<br>add one page"]
Create --> Read[Read stream as ASCII text]
Read --> Meta["Convert text to metafile<br>via PdfImage.FromRtf"]
Meta --> SplitLines["Set SplitTextLines = true,<br>draw metafile at origin"]
SplitLines --> 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. - Non-ASCII characters in the source RTF are not preserved because the stream is read with an
ASCII
StreamReader.
Related documentation¶
Sources¶
PdfApi.SyncFusionCore\Convert\RtfConverter.cs