Convert a source document to PDF¶
This is the single entry point for format conversion in this library: it validates the request, normalizes the file extension, and dispatches to the converter that matches it, before returning a uniform PdfResult.
| Field | Value |
|---|---|
| Operation ID | OP-SFC-001 |
| Trigger | Caller request — SyncfusionPdfService.Convert(request) (PdfAPI\Services\Syncfusion\SyncfusionPdfService.cs:82) |
| Inputs | ConvertRequest (File bytes, FileExtension, Options/Format, SourceSystemId) |
| Outputs | PdfResult (Document, Status, Message, Elapsed, OutputFormat, Extension, ImageId, PdfProcessorType = Syncfusion) |
| Primary components | ConverterFactory.Convert |
| Entry point | PdfApi.SyncFusionCore\Convert\ConverterFactory.cs |
Steps¶
- Reject a null request by throwing
ArgumentNullException(nameof(request))(BR-SFC-001). - Normalize
request.FileExtensionto lower case and trim leading/trailing.characters (BR-SFC-002). - Wrap
request.Filein aMemoryStreamand switch on the normalized extension, constructing the matching converter and calling itsConvert(stream, request)(BR-SFC-003): doc/docx→ Word document to PDFxls/xlsx→ Excel workbook to PDFrtf→ RTF document to PDFtxt→ Plain text to PDFgif/jpg/jpeg/png→ Raster image to PDFhtml→ HTML to PDFtif/tiff→ TIFF to multi-page PDFpdf→ PDF pass-through or PDF/A upgrade
Origin: Every branch delegates the actual byte-level conversion to
Execute a single conversion (converter template), which is implemented in this same library (PdfAPI.SyncFusionCore). 4. For thetxtbranch only: if the text conversion succeeded, recursively callConverterFactory.Convert(this operation) with a newConvertRequestwhoseFileis the produced PDF,FileExtension = "pdf", and the originalSourceSystemIdandOptions; replace the result with the recursive result (BR-SFC-004). - This resubmission routes back through step 3'snew PdfResult(SourceConversionType.Unknown, request)withMessage = "Unsuppported extension ({ext})"; no exception is thrown andStatusstays at its default (BR-SFC-005). 6. Setresult.Extensionto the normalized extension and return the result. TheMemoryStreamis disposed by the enclosingusing, and the converter also disposes it throughBaseConverter'susing (stream).
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([ConvertRequest received]) --> Null{"Request null?"}
Null -->|Yes| ThrowErr([ArgumentNullException])
Null -->|No| Norm["Normalize file extension<br>lower-case, trim dots"]
Norm --> Dispatch{"Extension<br>matches a converter?"}
Dispatch -->|"doc/docx/xls/xlsx/rtf/<br>image/html/tif/pdf"| RunConv["Run BaseConverter template<br>via matching converter"]
Dispatch -->|txt| RunText["Run TxtConverter via<br>BaseConverter template"]
Dispatch -->|No match| Unknown(["Return Unknown result<br>no exception thrown"])
RunText --> TextOk{"Text conversion<br>succeeded?"}
TextOk -->|Yes| Recurse["Recursively convert produced<br>PDF via pdf branch"]
TextOk -->|No| ReturnFailed([Return failed PdfResult])
Recurse --> RunConv
RunConv --> SetExt["Stamp normalized extension<br>on result"]
SetExt --> Result([Return PdfResult])
Failure and edge-case behavior¶
- A null request throws immediately; no other step executes.
- An unsupported extension never throws — it returns a non-throwing
PdfResultwithStatusleft at its default rather thanFailed. - Any exception inside the delegated converter is captured by
Execute a single conversion (converter template)and turned into a failedPdfResult, not propagated to this operation's caller.
Related documentation¶
Sources¶
PdfApi.SyncFusionCore\Convert\ConverterFactory.csPdfAPI\Services\Syncfusion\SyncfusionPdfService.cs