Merge document ranges into one PDF¶
Merges a set of document ranges into a single PDF. The merge itself is always performed without conformance; PDF/A is applied only as an optional, best-effort post-merge pass whose failure is logged rather than surfaced.
| Field | Value |
|---|---|
| Operation ID | OP-SFC-012 |
| Trigger | Caller request — SyncfusionPdfService constructs new PdfMerger(environmentService, logService) and calls Merge (PdfAPI\Services\Syncfusion\SyncfusionPdfService.cs:23) |
| Inputs | MergeRequest (DocumentRanges[], Options, SourceSystemId), optional trackingId |
| Outputs | PdfResult with SourceConversionType.Cache, Status = Succeeded, PdfProcessorType = Syncfusion, Elapsed, ImageId, TrackingId |
| Primary components | PdfMerger.Merge → private MergeDocumentRanges |
| Entry point | PdfApi.SyncFusionCore\Merge\PdfMerger.cs |
Steps¶
Mergecreates a discardedGuidand a placeholderPdfResult, starts aStopwatch, and callsMergeDocumentRangesinside atry/finally; thefinallystops the stopwatch and stampsElapsed.- On failure: there is no
catch, so any exception inMergeDocumentRangespropagates to the caller (BR-SFC-028). - Create the output
PdfDocumentwith conformanceNone— the merge itself is always non-conformant, regardless ofOptions.IsPdfa(BR-SFC-029). - For each
DocumentRange: callrange.Document.Load()(readsFilePathfrom disk whenFileis null,PdfAPI.Core), then use the whole file when the range is a single original range, or call Extract page ranges from a PDF when the range has more than onePageRangeor its first rangeIsPartial. Collect the byte arrays (BR-SFC-030).
Origin: Step 3's extraction is implemented in
Extract page ranges from a PDF(PdfAPI.SyncFusionCore) and executed on behalf of this operation. 4. CallSyncfusion.Pdf.PdfDocument.Merge(outputDoc, docs.ToArray()), save the result to aMemoryStreamand capture the bytes. 5. WhenOptions.IsPdfa: reload the merged bytes, setConformance = Pdf_A1B, save, and — only when the produced byte array is non-empty — replace the result and setrequest.Options.OutputFormat = PdfFormat.PdfA(BR-SFC-031). - If the PDF/A pass throws: build a warning message (appending[TrackingId: n]when a tracking id was supplied), construct anApplicationExceptionDetailvia Build an application exception detail (PdfHelper.GetApplicationDetail(_envService, "Merge", msg, ex)), and call_logService.LogException(detail). Processing continues and the non-conformant PDF is returned (BR-SFC-032).
> **Origin**: The exception-detail construction is implemented in [`Build an application exception detail`](build-application-exception-detail.md) (`PdfAPI.SyncFusionCore`) and executed on behalf of this operation.
- Wrap the bytes with
Document.Load(result, "pdf"), setStatus = Succeededunconditionally,PdfProcessorType = Syncfusion, andOutputFormat = PdfFormat.Pdf— the localoutputFormatvariable is never updated by the PDF/A branch, so a successful PDF/A merge still reportsOutputFormat = Pdfon the result whilerequest.Options.OutputFormatreportsPdfA(BR-SFC-033). - Parse
request.SourceSystemIdintoImageIdwithlong.TryParse, setTrackingId = trackingId ?? 0, and return the result (BR-SFC-009).
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start(["Merge called with<br>MergeRequest, trackingId"]) --> CreateOut["Create output PdfDocument<br>with conformance None"]
CreateOut --> ForEach{"More DocumentRanges<br>to process?"}
ForEach -->|Yes| LoadRange[range.Document.Load]
LoadRange --> RangeType{"Single original<br>range?"}
RangeType -->|Yes| WholeFile[Use whole file]
RangeType -->|No| ExtractSub["Extract page ranges<br>from a PDF"]
WholeFile --> ForEach
ExtractSub --> ForEach
ForEach -->|No| MergeDocs["PdfDocument.Merge<br>all collected docs"]
MergeDocs --> Save[Save merged bytes]
Save --> PdfaCheck{"Options.IsPdfa?"}
PdfaCheck -->|No| Wrap["Wrap with Document.Load,<br>Status = Succeeded"]
PdfaCheck -->|Yes| Reload["Reload, set Conformance<br>= Pdf_A1B, save"]
Reload --> ReloadOk{"Reload throws?"}
ReloadOk -->|No| ReplaceCheck{"Produced bytes<br>non-empty?"}
ReplaceCheck -->|Yes| PromoteFormat["Replace result,<br>promote OutputFormat<br>to PdfA"]
ReplaceCheck -->|No| Wrap
PromoteFormat --> Wrap
ReloadOk -->|Yes| LogWarn["Log warning via<br>ApplicationExceptionDetail,<br>keep non-conformant PDF"]
LogWarn --> Wrap
Wrap --> ParseId["Parse SourceSystemId,<br>set TrackingId"]
ParseId --> Result([Return PdfResult])
Failure and edge-case behavior¶
- A failure before or during the initial merge (steps 1–4) propagates to the caller — there is no
surrounding
catch. - A failure only in the post-merge PDF/A pass (step 5) is caught, logged, and does not fail the
operation: the plain PDF is returned and
Statusis stillSucceeded. - A merge result is always reported
Succeeded, even when the PDF/A upgrade failed and only the non-conformant PDF was returned.
Related documentation¶
Sources¶
PdfApi.SyncFusionCore\Merge\PdfMerger.csPdfApi.SyncFusionCore\Extract\PdfExtractor.csPdfApi.SyncFusionCore\PdfHelper.csPdfAPI\Services\Syncfusion\SyncfusionPdfService.cs