Skip to content

Commit 87ca197

Browse files
committed
Add images and links
1 parent bdf4a51 commit 87ca197

File tree

6 files changed

+77
-22
lines changed

6 files changed

+77
-22
lines changed

knowledge-base/exporting-xlsx-to-pdf-formatting-issues.md

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,89 @@ res_type: kb
1717
This article demonstrates how to deal with formatting difficulties when exporting an XLSX file to PDF using the RadSpreadProcessing library in .NET Standard.
1818

1919
The most common scenario is:
20-
1. Export an XLSX file to PDF using the RadSpreadProcessing library.
20+
1. [Export an XLSX file to PDF]({%slug radspreadprocessing-formats-and-conversion-pdf-pdfformatprovider%}) using the RadSpreadProcessing library.
2121
2. Observe the resulting PDF file with truncated columns or different font.
2222

23+
![Export Differences](images/exporting-xlsx-to-pdf-formatting-issues01.png)
24+
2325
## Solution
24-
The limitations of .NET Standard may cause differences in font and text size (text measuring) when converting to PDF format.
26+
The limitations of .NET Standard may cause differences in the font and text size (text measuring) when converting to PDF format.
27+
28+
1\. To address the issue with the size discrepancy, set a [SpreadFixedTextMeasurer]({%slug radspreadprocessing-cross-platform-text-measure%}}) to handle the problem with the size:
2529

26-
1.To address the issue with the size discrepancy, set a `SpreadFixedTextMeasurer` to handle the problem with the size:
2730
```csharp
28-
SpreadTextMeasurerBase fixedTextMeasurer = new SpreadFixedTextMeasurer();
29-
SpreadExtensibilityManager.TextMeasurer = fixedTextMeasurer;
31+
SpreadTextMeasurerBase fixedTextMeasurer = new SpreadFixedTextMeasurer();
32+
SpreadExtensibilityManager.TextMeasurer = fixedTextMeasurer;
3033
```
3134

32-
2. Implement a `FontsProvider` to handle differences in fonts. This class provides a mechanism to read the fonts used in the document:
35+
2\. Implement a [FontsProvider]({%slug pdfprocessing-implement-fontsprovider%}) to handle differences in fonts.
36+
3337
```csharp
34-
public class FontsProvider : Telerik.Windows.Documents.Extensibility.FontsProviderBase
35-
{
36-
public override byte[] GetFontData(Telerik.Windows.Documents.Core.Fonts.FontProperties fontProperties)
37-
{
38-
//...implementation details...
39-
}
40-
}
38+
FontsProviderBase fontsProvider = new FontsProvider();
39+
FixedExtensibilityManager.FontsProvider = fontsProvider;
4140
```
4241

43-
3. Update the `FontsProvider` implementation to include the necessary fonts and their corresponding font files.
42+
This class provides a mechanism to read the fonts used in the document:
43+
44+
```csharp
45+
public class FontsProvider : Telerik.Windows.Documents.Extensibility.FontsProviderBase
46+
{
47+
public override byte[] GetFontData(Telerik.Windows.Documents.Core.Fonts.FontProperties fontProperties)
48+
{
49+
string fontFileName = fontProperties.FontFamilyName + ".ttf";
50+
string fontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
51+
52+
//The fonts can differ depending on the file
53+
if (fontProperties.FontFamilyName == "Trebuchet MS")
54+
{
55+
if (fontProperties.FontStyle == FontStyles.Italic && fontProperties.FontWeight == FontWeights.Bold)
56+
{
57+
fontFileName = $"trebucbi.ttf";
58+
}
59+
else if (fontProperties.FontStyle == FontStyles.Italic)
60+
{
61+
fontFileName = $"trebucit.ttf";
62+
}
63+
else if (fontProperties.FontWeight == FontWeights.Normal)
64+
{
65+
fontFileName = "trebuc.ttf";
66+
}
67+
else if (fontProperties.FontWeight == FontWeights.Bold)
68+
{
69+
fontFileName = $"trebucbd.ttf";
70+
}
71+
}
72+
73+
74+
//...add more fonts if needed...
75+
76+
DirectoryInfo directory = new DirectoryInfo(fontFolder);
77+
FileInfo[] fontFiles = directory.GetFiles();
4478

45-
Please refer to the attached sample project for a complete implementation. Test the solution on your end to verify if it resolves the formatting issue.
79+
var fontFile = fontFiles.FirstOrDefault(f => f.Name.Equals(fontFileName, StringComparison.InvariantCultureIgnoreCase));
80+
if (fontFile != null)
81+
{
82+
var targetPath = fontFile.FullName;
83+
using (FileStream fileStream = File.OpenRead(targetPath))
84+
{
85+
using (MemoryStream memoryStream = new MemoryStream())
86+
{
87+
fileStream.CopyTo(memoryStream);
88+
return memoryStream.ToArray();
89+
}
90+
}
91+
}
92+
93+
return null;
94+
}
95+
}
96+
```
97+
Now, the font in the exported PDF document is the correct one and the text is not clipped.
4698

47-
## Notes
48-
It is important to note that the limitations of .NET Standard may still result in slight differences in font and text size when converting to PDF format.
99+
![Hande Export Differences](images/exporting-xlsx-to-pdf-formatting-issues02.png)
49100

50101
## See Also
51-
- [RadSpreadProcessing Documentation](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/overview)
52-
- [Troubleshooting Exporting XLSX to PDF in RadSpreadProcessing](https://www.telerik.com/support/kb/document-processing/details/exporting-xlsx-to-pdf-formatting-issues)
102+
- [Cross-Platform Support]({%slug radspreadprocessing-cross-platform%}})
103+
- [Text Measuring]({%slug radspreadprocessing-cross-platform-text-measure%}})
104+
- [Fonts in PdfProcessing]({%slug radpdfprocessing-cross-platform-fonts%})
105+
- [How to implement FontsProvider]({%slug pdfprocessing-implement-fontsprovider%})
166 KB
Loading
169 KB
Loading

libraries/radpdfprocessing/cross-platform/fonts.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ You can find a detailed **FixedExtensibilityManager** and **FontsProvider** desc
2020

2121
>important If the FontsProvider property is not set, a default font will be used when exporting the document.
2222
23+
## See Also
24+
- [How to Eliminate Formatting Issues when Exporting XLSX to PDF Format]({%slug exporting-xlsx-to-pdf-formatting-issues%}})

libraries/radspreadprocessing/cross-platform-support/text-measure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ You can assign any **SpreadTextMeasurerBase** implementation to the **SpreadExte
109109

110110

111111
## See Also
112-
112+
* [How to Eliminate Formatting Issues when Exporting XLSX to PDF Format]({%slug exporting-xlsx-to-pdf-formatting-issues%}})
113113
* [Cross-Platform Support]({%slug radspreadprocessing-cross-platform%})
114114
* [Using XlsxFormatProvider]({%slug radspreadprocessing-formats-and-conversion-xlsx-xlsxformatprovider%})
115115
* [Using PdfFormatProvider]({%slug radspreadprocessing-formats-and-conversion-pdf-pdfformatprovider%})

libraries/radspreadprocessing/formats-and-conversion/pdf/pdfformatprovider.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ The result from the export method is a document that can be opened in any applic
6969
>tip __RadFixedDocument__ is the base class of the __RadPdfProcessing__ library. Additional information on the library and its functionality can be found [here]({%slug radpdfprocessing-overview%}).
7070
7171
## See Also
72-
73-
* [Import/Load and Export/Save RadSpreadProcessing Workbook]({%slug import-export-save-load-workbook%})
72+
- [How to Eliminate Formatting Issues when Exporting XLSX to PDF Format]({%slug exporting-xlsx-to-pdf-formatting-issues%}})
73+
- [Import/Load and Export/Save RadSpreadProcessing Workbook]({%slug import-export-save-load-workbook%})
7474

0 commit comments

Comments
 (0)