Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ navigation:
title: Troubleshooting
position: 99
common-information:
title: Common Information
title: Common
position: 98
security:
title: Security
Expand Down
12 changes: 6 additions & 6 deletions common-information/device-independent-pixels.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ Most of the methods follow the same pattern for converting units:

__Example 1__ shows how to obtain row height as DIPs and convert it to Points.

#### __[C#] Example 1: Convert from DIP to Point__
#### __Example 1: Convert from DIP to Point__

{{region dips_1}}
```csharp

var rowHeightInDips = worksheet.Rows[0].GetHeight().Value.Value;
var rowHeightInPoints = UnitHelper.DipToPoint(rowHeightInDips);
{{endregion}}
```

except the **DipToUnit** and **UnitToDip** methods which accepts not only the units but the [UnitType](https://docs.telerik.com/devtools/document-processing/api/telerik.windows.documents.media.unittype) as well as a parameter:

__Example 2__ shows how to convert from Point to DIP and set the row height.

#### __[C#] Example 2: Convert from Point to DIP__
#### __Example 2: Convert from Point to DIP__

{{region dips_2}}
```csharp

double dips = UnitHelper.UnitToDip(60, UnitType.Point);
RowHeight newRowHeight = new RowHeight(dips, isCustom: true);
worksheet.Rows[0].SetHeight(newRowHeight);
{{endregion}}
```
57 changes: 57 additions & 0 deletions common-information/fileformatdetector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: FileFormatDetector
description: Detect file formats automatically using the FileFormatDetector of the Telerik Document Processing libraries.
page_title: FileFormatDetector
slug: fileformatdetector
position: 1
published: True
tags: file, format, detection, detector, pdf, docx, xlsx, zip, doc, xls, xlsm, txt, document, processing, libraries
---

# FileFormatDetector

The **FileFormatDetector** API provides automatic file format detection capabilities for various document types supported by Telerik Document Processing libraries. This utility enables you to programmatically identify the format of a document stream before attempting to process it, making it easier to handle documents of unknown types and providing better error handling in your applications.

The detector analyzes file signatures, headers, and content patterns to accurately identify document formats including PDF, DOCX, XLSX, RTF, and other supported formats. This is particularly useful when working with user-uploaded files or when processing documents from external sources where the file format might not be immediately known.

## Key Features

* **Automatic Format Detection**: Identifies document formats from a stream without requiring file extensions
* **Multiple Format Support**: Detects PDF, DOCX, XLSX, PPTX, RTF, and other document formats
* **Stream-Based**: Works directly with streams, making it compatible with various input sources
* **Error Handling**: Provides detailed error messages when detection fails
* **Lightweight**: Minimal overhead with efficient signature and header analysis

## API

**Namespace:** Telerik.Documents.Utilities.Detectors.FileFormat

### FileFormatDetector

The main class for detecting file formats.

| Member | Type | Description |
|--------|------|-------------|
| **Detect(Stream stream)** | Method | Detects the format of a file from a stream. Returns a **FileFormatDetectionResult** containing the detection outcome. |

### FileFormatDetectionResult

Represents the result of a file format detection operation.

| Member | Type | Description |
|--------|------|-------------|
| **IsSuccessful** | Property (bool) | Gets a value indicating whether a specific file format was successfully detected. Returns false if the format is unknown or detection failed. |
| **Format** | Property (DocumentFormatType) | Gets the detected document format type. Returns **DocumentFormatType.Unknown** if detection was unsuccessful. |
| **ErrorMessage** | Property (string) | Gets the error message if detection failed, or null if successful. |

## Using FileFormatDetector

The following example demonstrates how to detect the format of a document from a file stream:

<snippet id='libraries-common-fileformatdetector-detect-format'/>

## See Also

* [RadPdfProcessing Overview]({%slug radpdfprocessing-overview%})
* [RadWordsProcessing Overview]({%slug radwordsprocessing-overview%})
* [RadSpreadProcessing Overview]({%slug radspreadprocessing-overview%})
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,40 @@ For the sake of the example it is assumed that the source distribution ZIP file

2\. Uncomment the following line:

#### __[C#] Before
#### __Before

{{region cs-documentprocessing-protect-source_0}}
```csharp
public static bool IsValid()
{
// Uncomment the following line
// return ValidatePassPhrase();
return true;
}
{{endregion}}
```

#### __[C#] After
#### __After

{{region cs-documentprocessing-protect-source_1}}
```csharp
public static bool IsValid()
{
// Uncomment the following line
return ValidatePassPhrase();
}
{{endregion}}
```

3\. Change the ApplicationName constant to match the name of your application:

#### __[C#] Before
#### __Before

{{region cs-documentprocessing-protect-source_2}}
```csharp
internal const string ApplicationName = "MyApp";
{{endregion}}
```

#### __[C#] After
#### __After

{{region cs-documentprocessing-protect-source_3}}
```csharp
internal const string ApplicationName = "Sample Application Name v2.0 (tm)";
{{endregion}}
```


4\. Save __AssemblyProtection.cs__ and rebuild.
Expand Down
4 changes: 4 additions & 0 deletions docfx/filterConfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiRules:
- exclude:
type: Method
uidRegex: ^System\.Object\..*$
32 changes: 32 additions & 0 deletions docfx/metadata-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"metadata": [{
"src": [
{
"files": [
"src/Telerik.Windows.Documents.Core.dll",
"src/Telerik.Windows.Documents.Fixed.dll",
"src/Telerik.Windows.Documents.Fixed.FormatProviders.Ocr.dll",
"src/Telerik.Windows.Documents.TesseractOcr.dll",
"src/Telerik.Windows.Documents.CMapUtils.dll",
"src/Telerik.Windows.Documents.Flow.dll",
"src/Telerik.Windows.Documents.DrawingML.dll",
"src/Telerik.Windows.Documents.Flow.FormatProviders.Doc.dll",
"src/Telerik.Windows.Documents.Flow.FormatProviders.Pdf.dll",
"src/Telerik.Windows.Documents.Spreadsheet.dll",
"src/Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.dll",
"src/Telerik.Windows.Documents.Spreadsheet.FormatProviders.Xls.dll",
"src/Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.dll",
"src/Telerik.Windows.Documents.Spreadsheet.FormatProviders.Json.dll",
"src/Telerik.Documents.SpreadsheetStreaming.dll",
"src/Telerik.Windows.Documents.AIConnector.dll",
"src/Telerik.Documents.AI.Core.dll",
"src/Telerik.Documents.AI.RAG.dll",
"src/Telerik.Windows.Zip.dll",
"src/Telerik.Windows.Zip.Extensions.dll"
]
}
],
"dest": "metadata",
"filter": "filterConfig.yml"
}]
}
Loading