@@ -10,14 +10,19 @@ Date Author Change
1010 *************************************************************************************************
1111 10/07/2025 EPPlus Software AB EPPlus.Fonts.OpenType 1.0
1212 *************************************************************************************************/
13+ using EPPlus . Export . Pdf ;
14+ using EPPlus . Export . Pdf . PdfLayout ;
15+ using EPPlus . Export . Pdf . PdfSettings ;
16+ using EPPlus . Export . Pdf . PdfSettings . PdfPageSizes ;
17+ using EPPlus . Fonts . OpenType ;
18+ using EPPlus . Fonts . OpenType . Integration ;
19+ using OfficeOpenXml . Interfaces . Drawing . Text ;
20+ using OfficeOpenXml . Style ;
1321using System ;
1422using System . IO ;
1523using System . Linq ;
1624using System . Text ;
1725using System . Xml . Linq ;
18- using EPPlus . Export . Pdf ;
19- using EPPlus . Export . Pdf . PdfSettings ;
20- using EPPlus . Export . Pdf . PdfSettings . PdfPageSizes ;
2126
2227namespace EPPlusTest . PDF
2328{
@@ -125,5 +130,79 @@ public void TestWritePdf2()
125130 ExcelPdf pedeef = new ExcelPdf ( p . Workbook . Worksheets . First ( ) , pageSettings ) ;
126131 pedeef . CreatePdf ( "c:\\ epplustest\\ pdf\\ EmojiTest.pdf" ) ;
127132 }
133+
134+ [ TestMethod ]
135+ public void WritePrintAreas ( )
136+ {
137+ using var p = OpenTemplatePackage ( "PDFTest.xlsx" ) ;
138+ var cell = p . Workbook . Worksheets [ 0 ] . Cells [ "P118" ] ;
139+
140+ List < TextFragment > TextFragments = GetTextFragments ( cell . RichText ) ;
141+
142+
143+ var layout = OpenTypeFonts . GetTextLayoutEngineForFont ( TextFragments [ 0 ] . Font ) ;
144+
145+ var TextLines = layout . WrapRichTextLineCollection ( TextFragments , 51d ) ;
146+ ////var ShapedTexts = new List<PdfShapedText>();
147+ //for (int i = 0; i < TextFragments.Count; i++)
148+ //{
149+ // var tf = TextFragments[i];
150+ // var layout = OpenTypeFonts.GetTextLayoutEngineForFont(TextFragments[i].Font);
151+
152+ // var TextLines = layout.WrapRichTextLineCollection(TextFragments, 51d);
153+ //}
154+
155+ }
156+
157+ private static List < TextFragment > GetTextFragments ( ExcelRichTextCollection RichTextCollection , PdfCellStyle cellStyle = null )
158+ {
159+ var textFragments = new List < TextFragment > ( ) ;
160+ bool bold = false , italic = false , underline = false , strike = false ;
161+ ExcelUnderLineType underLineType = ExcelUnderLineType . None ;
162+ if ( cellStyle != null && cellStyle . dxfFont != null )
163+ {
164+ bold = cellStyle . dxfFont . Bold != null ? ( bool ) cellStyle . dxfFont . Bold : false ;
165+ italic = cellStyle . dxfFont . Italic != null ? ( bool ) cellStyle . dxfFont . Italic : false ;
166+ strike = cellStyle . dxfFont . Strike != null ? ( bool ) cellStyle . dxfFont . Strike : false ;
167+ underline = cellStyle . dxfFont . Underline != null ;
168+ underLineType = cellStyle . dxfFont . Underline != null ? ( ExcelUnderLineType ) cellStyle . dxfFont . Underline : ExcelUnderLineType . None ;
169+ }
170+ for ( int i = 0 ; i < RichTextCollection . Count ; i ++ )
171+ {
172+ var rt = RichTextCollection [ i ] ;
173+ var textFrag = new TextFragment ( ) ;
174+ textFrag . Font = new MeasurementFont ( ) ;
175+ textFrag . Text = rt . Text ;
176+
177+ textFrag . Font . FontFamily = rt . FontName ;
178+ textFrag . Font . Size = rt . Size ;
179+
180+ textFrag . RichTextOptions . IsBold = rt . Bold || bold ;
181+ textFrag . RichTextOptions . IsItalic = rt . Italic || italic ;
182+ //underline
183+ //none : 12
184+ //single : 13
185+ //Double : 4
186+ //accouting does not exsist
187+ textFrag . RichTextOptions . UnderlineType = 12 ;
188+ textFrag . RichTextOptions . UnderlineType = rt . UnderLineType == ExcelUnderLineType . Single ? 13 : textFrag . RichTextOptions . UnderlineType ;
189+ textFrag . RichTextOptions . UnderlineType = rt . UnderLineType == ExcelUnderLineType . Double ? 4 : textFrag . RichTextOptions . UnderlineType ;
190+ textFrag . RichTextOptions . StrikeType = rt . Strike || strike ? 2 : 1 ;
191+ textFrag . RichTextOptions . SuperScript = rt . VerticalAlign == ExcelVerticalAlignmentFont . Superscript ;
192+ textFrag . RichTextOptions . SubScript = rt . VerticalAlign == ExcelVerticalAlignmentFont . Subscript ;
193+ textFrag . RichTextOptions . FontColor = rt . Color ;
194+
195+ textFrag . Font . Style = ( textFrag . RichTextOptions . IsBold ? MeasurementFontStyles . Bold : 0 ) |
196+ ( textFrag . RichTextOptions . IsItalic ? MeasurementFontStyles . Italic : 0 ) |
197+ ( textFrag . RichTextOptions . UnderlineType != 12 ? MeasurementFontStyles . Underline : 0 ) |
198+ ( textFrag . RichTextOptions . StrikeType > 1 ? MeasurementFontStyles . Strikeout : 0 ) ;
199+
200+
201+ textFragments . Add ( textFrag ) ;
202+ OpenTypeFonts . GetFontSubFamily ( textFrag . Font . Style ) ;
203+ }
204+
205+ return textFragments ;
206+ }
128207 }
129208}
0 commit comments