WPCubed Product Support

Example of -csspath option

wpsupport

If you have a stylesheet in CSS format you can load it with

WPRichText1.LoadFromFile( 'test.htm', true, 'AUTO-csspath:"style.css"')

This is test,html

<html>
<head>
<link rel=stylesheet href="any_name.css">
</head>
<body>
<div class="Normal">Normal Line</div>
<div class="Text">Text Line</div>
<div class="Text">Text Line</div>
<div class="Text">Text Line</div>
</body></html>

This is style.css

.Normal{text-indent:0.00in;line-height:115%;text-align:left;vertical-align:top;font-family:'Calibri';font-size:11.00pt;margin:0.00in 0.00in 0.14in 0.00in;}
.Text{text-indent:0.00in;text-align:left;vertical-align:top;font-size:12.00pt;margin:0.00in;}
div{font-family:'Arial';font-size:11.00pt;}

If the file any_name.css actually exists, it is loaded instead of style.css, unless you modify the behavior using the event OnRequestHTTPString

procedure TForm1.WPRichText1RequestHTTPString(
RTFData: TWPRTFDataCollectionBase; Reader: TWPCustomTextReader;
const LoadPath, url: string; var LoadedString: AnsiString; var Ok: Boolean);

If you want to load a style sheet to your HTML data you do not need the csspath option. Simply load the CSS into your paragraph style collection using SetCSS. If you saved the styles in *WP*CSS format you can also use ParStyles.LoadFromFile.

WPRichText1.Clear;
WPRichText1.ParStyles.SetCSS(
'.Normal{font-family:"Calibri";font-size:11.00pt;}' + #10+
'.Text{font-family:"Arial";font-size:10.00pt;}');
WPRichText1.LoadFromFile( 'test.html', false );
#4 ♥ 0
3.8k Views 2 users read 3 min

Is there a simple example somewhere that shows how the -csspath parameter is supposed to be used?

#3 ♥ 0
wpsupport

This property is used by the HTML writer to write a relative link to the given path and not embed styles from the internal style collection.

The HTML reader will use this property by the default hander of RequestHTTPString. Here it will be (only) used to load the file from this path, if the provided path was NOT found.

#2 ♥ 0

It was noted in changes for 5.22 that there is an option to specify a style sheet.

"-csspath:"..." can be used to specify a CSS style for loading and saving"

I couldn't find an example of where this is done and what we should pass to it.

Here is what I tried:

FPaintEngine.Memo.TextLoadFormat:=FPaintEngine.Memo.TextLoadFormat+' -csspath:"\ReportStyleSheets\ReportStyles.css"';

Do I need to send the full path, or will a relative path do?

Do I need to add a link to it in a header in the html, or not?

Thanks!

#1 ♥ 0