1515
1616namespace Gotenberg . Sharp . API . Client . Domain . Builders . Faceted
1717{
18+ /// <summary>
19+ /// Adds embedded resources (assets) to PDF conversion requests. Assets are files referenced by your HTML content
20+ /// such as images, fonts, CSS stylesheets, and JavaScript files. The asset name must match exactly how it's
21+ /// referenced in your HTML (e.g., "logo.png" for <img src="logo.png"/>).
22+ /// </summary>
1823 public sealed class AssetBuilder
1924 {
2025 private readonly AssetDictionary _assets ;
@@ -24,6 +29,13 @@ internal AssetBuilder(AssetDictionary assets)
2429 this . _assets = assets ;
2530 }
2631
32+ /// <summary>
33+ /// Adds a single asset file. The name must be a relative filename with extension, matching the reference in your HTML.
34+ /// </summary>
35+ /// <param name="name">Filename as referenced in HTML (e.g., "styles.css", "logo.png"). Must include extension and not contain path separators.</param>
36+ /// <param name="value">The file content.</param>
37+ /// <returns>The builder instance for method chaining.</returns>
38+ /// <exception cref="ArgumentOutOfRangeException">Thrown when name is invalid (missing extension or contains path separators).</exception>
2739 public AssetBuilder AddItem ( string name , ContentItem value )
2840 {
2941 // ReSharper disable once ComplexConditionExpression
@@ -39,16 +51,39 @@ public AssetBuilder AddItem(string name, ContentItem value)
3951 return this ;
4052 }
4153
54+ /// <summary>
55+ /// Adds a single asset from string content (typically for text files like CSS or JavaScript).
56+ /// </summary>
57+ /// <param name="name">Filename as referenced in HTML.</param>
58+ /// <param name="value">File content as string.</param>
59+ /// <returns>The builder instance for method chaining.</returns>
4260 public AssetBuilder AddItem ( string name , string value ) => AddItem ( name , new ContentItem ( value ) ) ;
4361
62+ /// <summary>
63+ /// Adds a single asset from byte array (typically for binary files like images or fonts).
64+ /// </summary>
65+ /// <param name="name">Filename as referenced in HTML.</param>
66+ /// <param name="value">File content as bytes.</param>
67+ /// <returns>The builder instance for method chaining.</returns>
4468 public AssetBuilder AddItem ( string name , byte [ ] value ) => AddItem ( name , new ContentItem ( value ) ) ;
4569
70+ /// <summary>
71+ /// Adds a single asset from a stream.
72+ /// </summary>
73+ /// <param name="name">Filename as referenced in HTML.</param>
74+ /// <param name="value">Stream containing file content.</param>
75+ /// <returns>The builder instance for method chaining.</returns>
4676 public AssetBuilder AddItem ( string name , Stream value ) => AddItem ( name , new ContentItem ( value ) ) ;
4777
4878 #region 'n' assets
4979
5080 #region from dictionaries
5181
82+ /// <summary>
83+ /// Adds multiple assets from a dictionary. Useful for adding several files at once.
84+ /// </summary>
85+ /// <param name="items">Dictionary of filename to content mappings.</param>
86+ /// <returns>The builder instance for method chaining.</returns>
5287 public AssetBuilder AddItems ( Dictionary < string , ContentItem > ? items )
5388 {
5489 foreach ( var item in items . IfNullEmpty ( ) )
@@ -59,35 +94,70 @@ public AssetBuilder AddItems(Dictionary<string, ContentItem>? items)
5994 return this ;
6095 }
6196
97+ /// <summary>
98+ /// Adds multiple assets from a dictionary with string content.
99+ /// </summary>
100+ /// <param name="assets">Dictionary of filename to string content mappings.</param>
101+ /// <returns>The builder instance for method chaining.</returns>
62102 public AssetBuilder AddItems ( Dictionary < string , string > ? assets ) =>
63103 AddItems ( assets ? . ToDictionary ( a => a . Key , a => new ContentItem ( a . Value ) ) ) ;
64104
105+ /// <summary>
106+ /// Adds multiple assets from a dictionary with byte array content.
107+ /// </summary>
108+ /// <param name="assets">Dictionary of filename to byte array mappings.</param>
109+ /// <returns>The builder instance for method chaining.</returns>
65110 public AssetBuilder AddItems ( Dictionary < string , byte [ ] > ? assets ) =>
66111 AddItems ( assets ? . ToDictionary ( a => a . Key , a => new ContentItem ( a . Value ) ) ) ;
67112
113+ /// <summary>
114+ /// Adds multiple assets from a dictionary with stream content.
115+ /// </summary>
116+ /// <param name="assets">Dictionary of filename to stream mappings.</param>
117+ /// <returns>The builder instance for method chaining.</returns>
68118 public AssetBuilder AddItems ( Dictionary < string , Stream > ? assets ) =>
69119 AddItems ( assets ? . ToDictionary ( a => a . Key , a => new ContentItem ( a . Value ) ) ) ;
70120
71121 #endregion
72122
73123 #region from KVP enumerables
74124
125+ /// <summary>
126+ /// Adds multiple assets from a key-value pair enumerable.
127+ /// </summary>
128+ /// <param name="assets">Enumerable of filename to content mappings.</param>
129+ /// <returns>The builder instance for method chaining.</returns>
75130 public AssetBuilder AddItems ( IEnumerable < KeyValuePair < string , ContentItem > > assets ) =>
76131 AddItems (
77132 new Dictionary < string , ContentItem > (
78133 assets ? . ToDictionary ( a => a . Key , a => a . Value ) ?? throw new ArgumentNullException ( nameof ( assets ) ) ) ) ;
79134
135+ /// <summary>
136+ /// Adds multiple assets from a key-value pair enumerable with string content.
137+ /// </summary>
138+ /// <param name="assets">Enumerable of filename to string content mappings.</param>
139+ /// <returns>The builder instance for method chaining.</returns>
80140 public AssetBuilder AddItems ( IEnumerable < KeyValuePair < string , string > > assets ) =>
81141 AddItems (
82142 new Dictionary < string , ContentItem > (
83143 assets ? . ToDictionary ( a => a . Key , a => new ContentItem ( a . Value ) )
84144 ?? throw new ArgumentNullException ( nameof ( assets ) ) ) ) ;
85145
146+ /// <summary>
147+ /// Adds multiple assets from a key-value pair enumerable with byte array content.
148+ /// </summary>
149+ /// <param name="assets">Enumerable of filename to byte array mappings.</param>
150+ /// <returns>The builder instance for method chaining.</returns>
86151 public AssetBuilder AddItems ( IEnumerable < KeyValuePair < string , byte [ ] > > assets ) =>
87152 AddItems (
88153 assets ? . ToDictionary ( a => a . Key , a => new ContentItem ( a . Value ) )
89154 ?? throw new ArgumentNullException ( nameof ( assets ) ) ) ;
90155
156+ /// <summary>
157+ /// Adds multiple assets from a key-value pair enumerable with stream content.
158+ /// </summary>
159+ /// <param name="assets">Enumerable of filename to stream mappings.</param>
160+ /// <returns>The builder instance for method chaining.</returns>
91161 public AssetBuilder AddItems ( IEnumerable < KeyValuePair < string , Stream > > assets ) =>
92162 AddItems (
93163 assets ? . ToDictionary ( s => s . Key , a => new ContentItem ( a . Value ) )
0 commit comments