diff --git a/docs/topics/reading-and-writing-to-file.md b/docs/topics/reading-and-writing-to-file.md
index f8ba084b..e55471a7 100644
--- a/docs/topics/reading-and-writing-to-file.md
+++ b/docs/topics/reading-and-writing-to-file.md
@@ -707,7 +707,7 @@ $sty = $writer->generateStyles(false); // do not write
$newstyle = <<
$sty
-html {
+body {
background-color: yellow;
}
@@ -717,16 +717,22 @@ echo $writer->generateSheetData();
echo $writer->generateHTMLFooter();
```
-#### Writing UTF-8 HTML files
+#### Editing HTML during save via a callback
-A HTML file can be marked as UTF-8 by writing a BOM file header. This
-can be enabled by using the following code:
+You can also add a callback function to edit the generated html
+before saving. For example, you could change the gridlines
+from a thin solid black line:
-```php
+``` php
+function changeGridlines(string $html): string
+{
+ return str_replace('{border: 1px solid black;}',
+ '{border: 2px dashed red;}',
+ $html);
+}
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Html($spreadsheet);
-$writer->setUseBOM(true);
-
-$writer->save("05featuredemo.htm");
+$writer->setEditHtmlCallback('changeGridlines');
+$writer->save($filename);
```
#### Decimal and thousands separators
@@ -855,6 +861,12 @@ $writer->setPreCalculateFormulas(false);
$writer->save("05featuredemo.pdf");
```
+#### Editing Pdf during save via a callback
+
+You can also add a callback function to edit the html used to
+generate the Pdf before saving.
+[See under Html](#editing-html-during-save-via-a-callback).
+
#### Decimal and thousands separators
See section `\PhpOffice\PhpSpreadsheet\Writer\Csv` how to control the
diff --git a/samples/Basic/17b_Html.php b/samples/Basic/17b_Html.php
new file mode 100644
index 00000000..97bb29a3
--- /dev/null
+++ b/samples/Basic/17b_Html.php
@@ -0,0 +1,20 @@
+getFilename(__FILE__, 'html');
+$writer = new Html($spreadsheet);
+
+function changeGridlines(string $html): string
+{
+ return str_replace('{border: 1px solid black;}', '{border: 2px dashed red;}', $html);
+}
+
+$callStartTime = microtime(true);
+$writer->setEmbedImages(true);
+$writer->setEditHtmlCallback('changeGridlines');
+$writer->save($filename);
+$helper->logWrite($writer, $filename, $callStartTime);
diff --git a/samples/Pdf/21a_Pdf.php b/samples/Pdf/21a_Pdf.php
new file mode 100644
index 00000000..b5572afe
--- /dev/null
+++ b/samples/Pdf/21a_Pdf.php
@@ -0,0 +1,25 @@
+log('Hide grid lines');
+$spreadsheet->getActiveSheet()->setShowGridLines(false);
+
+$helper->log('Set orientation to landscape');
+$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
+$spreadsheet->setActiveSheetIndex(0)->setPrintGridlines(true);
+
+function changeGridlines(string $html): string
+{
+ return str_replace('{border: 1px solid black;}', '{border: 2px dashed red;}', $html);
+}
+
+$helper->log('Write to Mpdf');
+$writer = new Mpdf($spreadsheet);
+$filename = $helper->getFileName('21a_Pdf_mpdf.xlsx', 'pdf');
+$writer->setEditHtmlCallback('changeGridlines');
+$writer->save($filename);
diff --git a/samples/Pdf/21b_Pdf.php b/samples/Pdf/21b_Pdf.php
new file mode 100644
index 00000000..c67ff3d2
--- /dev/null
+++ b/samples/Pdf/21b_Pdf.php
@@ -0,0 +1,51 @@
+.*