### HTML Attribute Examples Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm Shows various ways to define attributes within HTML start tags, including unquoted, quoted, and empty attribute values. ```html ``` -------------------------------- ### Clone PD4ML Examples Repository Source: https://github.com/zxfr/pd4ml-examples/blob/master/README.md Command to retrieve the PD4ML examples project from the GitHub repository. ```bash git clone https://github.com/zxfr/pd4ml-examples.git ``` -------------------------------- ### Apply CSS styling to HTML documents Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm Provides an example of using the style element to define global CSS rules for an HTML document, specifically changing background and text colors. ```html Sample styled page

Sample styled page

This page is just a demo.

``` -------------------------------- ### Identify invalid HTML semantic combinations Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm Examples of semantically contradictory HTML elements where roles or types conflict, leading to conformance errors. ```html
``` -------------------------------- ### Configure CSS At-rules for PDF Layout and Fonts Source: https://github.com/zxfr/pd4ml-examples/blob/master/README.md Shows how to define page margins and sizes using @page, and how to import custom fonts using @font-face within the PD4ML rendering context. ```css @page :first { margin: 10pt; size: A4 landscape; } @font-face { font-family: "Consolas"; src: url("java:/html/rc/FiraMono-Regular.ttf") format("ttf"); } @font-face { font-family: 'Open Sans'; font-style: normal; font-weight: 400; src: url(https://fonts.gstatic.com/s/lato/v11/qIIYRU-oROkIk8vfvxw6QvesZW2xOQ-xsNqO47m55DA.woff) format('woff'); } ``` -------------------------------- ### Define IDL Interface Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm An example of an Interface Definition Language (IDL) structure used to define contract specifications within the documentation. ```IDL interface Example { // this is an IDL definition }; ``` -------------------------------- ### Basic HTML to PDF Conversion with PD4ML Source: https://context7.com/zxfr/pd4ml-examples/llms.txt Demonstrates the fundamental workflow of initializing a PD4ML instance, parsing HTML content, and exporting the result to a PDF file. This example highlights the use of proprietary tags for page breaks and the library's ability to handle output streams. ```java import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import com.pd4ml.PD4ML; public class BasicConversion { public static void main(String[] args) throws Exception { PD4ML pd4ml = new PD4ML(); // HTML content with page break using proprietary tag String html = "TESTHello, World!"; ByteArrayInputStream bais = new ByteArrayInputStream(html.getBytes()); // Read and parse HTML pd4ml.readHTML(bais); // Write result as PDF File pdf = File.createTempFile("result", ".pdf"); FileOutputStream fos = new FileOutputStream(pdf); pd4ml.writePDF(fos); } } ``` -------------------------------- ### Implement Custom Resource Provider (Java) Source: https://context7.com/zxfr/pd4ml-examples/llms.txt This Java code shows how to create a custom `ResourceProvider` to load content from non-standard sources. The `DummyProvider` example handles resources with the 'dummy' protocol, demonstrating how to intercept resource loading requests and provide custom content, such as data from a database or encrypted storage. ```java import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.FileOutputStream; import java.net.URL; import com.pd4ml.PD4ML; import com.pd4ml.ResourceProvider; import com.pd4ml.cache.FileCache; public class CustomResourceProviderExample { public static class DummyProvider extends ResourceProvider { public static final String PROTOCOL = "dummy"; @Override public BufferedInputStream getResourceAsStream(String resource, FileCache cache) { if (!resource.toLowerCase().startsWith(PROTOCOL)) { return null; } // Interpret resource parameter (e.g., as database key) String content = "[" + resource.substring(PROTOCOL.length() + 1) + "]"; return new BufferedInputStream(new ByteArrayInputStream(content.getBytes())); } @Override public boolean canLoad(String resource, FileCache cache) { return resource.toLowerCase().startsWith(PROTOCOL); } } public static void main(String[] args) throws Exception { PD4ML pd4ml = new PD4ML(); // Register custom resource provider pd4ml.addCustomResourceProvider("com.example.DummyProvider"); // Load content using custom protocol pd4ml.readHTML(new URL("dummy:my.exotic.protocol")); pd4ml.writePDF(new FileOutputStream("custom-resource.pdf")); } } ``` -------------------------------- ### Convert HTML to PDF using PD4ML API Source: https://github.com/zxfr/pd4ml-examples/blob/master/README.md Demonstrates the two-phase conversion process in Java. It reads an HTML string from an input stream and writes the rendered output to a PDF file. ```java PD4ML pd4ml = new PD4ML(); String html = "TESTHello, World!"; ByteArrayInputStream bais = new ByteArrayInputStream(html.getBytes()); pd4ml.readHTML(bais); FileOutputStream fos = new FileOutputStream("hello.pdf"); pd4ml.writePDF(fos); ``` -------------------------------- ### Monitor PDF Conversion Progress (Java) Source: https://context7.com/zxfr/pd4ml-examples/llms.txt This Java example demonstrates how to monitor the progress of PDF conversion using a `ProgressListener`. A `ProgressMeter` class is implemented to receive updates on conversion stages and display progress information, including elapsed time and status messages. ```java import java.io.FileOutputStream; import java.net.URL; import com.pd4ml.PD4ML; import com.pd4ml.ProgressListener; public class ProgressMonitoringExample { public static class ProgressMeter implements ProgressListener { private long startTime = -1; @Override public void progressUpdate(int messageID, int progress, String note, long msec) { if (startTime < 0) startTime = msec; String tick = String.format("%7d", msec - startTime); String progressString = String.format("%3d", progress); String step = switch (messageID) { case CONVERSION_BEGIN -> "conversion begin"; case MAIN_DOC_READ -> "doc read"; case HTML_PARSED -> "html parsed"; case RENDERER_TREE_BUILT -> "document tree structure built"; case HTML_LAYOUT_IN_PROGRESS -> "layouting..."; case HTML_LAYOUT_DONE -> "layout done"; case PAGEBREAKS_ALIGNED -> "pagebreaks aligned"; case TOC_GENERATED -> "TOC generated"; case DOC_RENDER_IN_PROGRESS -> "generating doc page"; case DOC_WRITE_BEGIN -> "writing doc..."; case CONVERSION_END -> "done."; default -> ""; }; System.out.println(tick + " " + progressString + " " + step + " " + note); } } public static void main(String[] args) throws Exception { PD4ML pd4ml = new PD4ML(); pd4ml.monitorProgressWith(new ProgressMeter()); pd4ml.readHTML(new URL("java:/advanced/A003.htm")); pd4ml.writePDF(new FileOutputStream("output.pdf")); } } ``` -------------------------------- ### Convert HTML and Merge with Existing PDF using Java Source: https://context7.com/zxfr/pd4ml-examples/llms.txt This example demonstrates how to initialize the PD4ML engine, convert an HTML string into a PDF, and append specific pages from an existing PDF document. It uses the PD4ML and PdfDocument classes to handle the conversion and merging process, outputting the result to a file. ```java import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.net.URL; import com.pd4ml.PD4ML; import com.pd4ml.PdfDocument; public class ConvertAndMergeExample { public static void main(String[] args) throws Exception { PD4ML pd4ml = new PD4ML(); String html = "TESTHello, World!"; URL pdfUrl = new URL("java:/pdftools/PDFOpenParameters.pdf"); PdfDocument existingPdf = new PdfDocument(pdfUrl, null); pd4ml.setPageHeader("HEADER $[page] of $[total]", 40, "1+"); // Merge pages 2-4 from existing PDF, append after converted content pd4ml.merge(existingPdf, 2, 4, true); pd4ml.readHTML(new ByteArrayInputStream(html.getBytes())); pd4ml.writePDF(new FileOutputStream("converted-merged.pdf")); // Count pages in resulting PDF PdfDocument result = new PdfDocument(new FileInputStream("converted-merged.pdf"), null); System.out.println("Total pages: " + result.getNumberOfPages()); } } ``` -------------------------------- ### Generate PDF Bookmarks from HTML Headings with Java Source: https://context7.com/zxfr/pd4ml-examples/llms.txt Automatically generates PDF bookmarks (outline) from HTML heading tags (h1-h6) for improved document navigation. This Java example utilizes the PD4ML library to read HTML content and output a PDF with navigable bookmarks. ```java import java.io.FileOutputStream; import java.net.URL; import com.pd4ml.PD4ML; public class BookmarksExample { public static void main(String[] args) throws Exception { PD4ML pd4ml = new PD4ML(); pd4ml.setHtmlWidth(900); pd4ml.addStyle( "@font-face {\n" + " font-family: \"Arial\";\n" + " src: url(\"java:/html/rc/LibreFranklin-Regular.ttf\") format(\"ttf\");\n" + "}\n" + "@font-face {\n" + " font-family: \"Consolas\";\n" + " src: url(\"java:/html/rc/FiraMono-Regular.ttf\") format(\"ttf\");\n" + "}", false ); // Enable automatic bookmark generation from h1-h6 tags pd4ml.generateBookmarksFromHeadings(true); pd4ml.readHTML(new URL("java:/html/H001.htm")); pd4ml.writePDF(new FileOutputStream("with-bookmarks.pdf")); } } ``` -------------------------------- ### Automatic Counter Implementation Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm Utilizes CSS counters to automatically number figures, issues, and examples within the document body. It targets specific classes to increment and display the counter value via the ::before pseudo-element. ```css body { counter-reset: example figure issue; } .issue { counter-increment: issue; } .issue:not(.no-marker)::before { content: "Issue " counter(issue); } .example { counter-increment: example; } .example:not(.no-marker)::before { content: "Example " counter(example); } ``` -------------------------------- ### Generate PDF/A and PDF/UA Output with Java Source: https://context7.com/zxfr/pd4ml-examples/llms.txt Outputs PDF documents compliant with archival (PDF/A) and accessibility (PDF/UA) standards. This Java example demonstrates how to set the output format using PD4ML constants and retrieve rendering status information, including PDF/A compliance checks. ```java import java.io.ByteArrayInputStream; import java.io.FileOutputStream; import com.pd4ml.Constants; import com.pd4ml.PD4ML; import com.pd4ml.StatusMessage; public class PdfAOutputExample { public static void main(String[] args) throws Exception { PD4ML pd4ml = new PD4ML(); String html = "TESTHello, World!"; ByteArrayInputStream bais = new ByteArrayInputStream(html.getBytes()); pd4ml.readHTML(bais); // Write as PDF/A format pd4ml.writePDF(new FileOutputStream("output.pdf"), Constants.PDFA); // Check rendering status information System.out.println("pages: " + pd4ml.getLastRenderInfo(Constants.PD4ML_TOTAL_PAGES)); System.out.println("height: " + pd4ml.getLastRenderInfo(Constants.PD4ML_DOCUMENT_HEIGHT_PX)); System.out.println("right edge: " + pd4ml.getLastRenderInfo(Constants.PD4ML_RIGHT_EDGE_PX)); // Check PDF/A compliance status StatusMessage[] msgs = (StatusMessage[])pd4ml.getLastRenderInfo(Constants.PD4ML_PDFA_STATUS); for (StatusMessage msg : msgs) { System.out.println((msg.isError() ? "ERROR: " : "WARNING: ") + msg.getMessage()); } } } ``` -------------------------------- ### General Table Styling (CSS) Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm Basic CSS rules for table cells, ensuring text alignment is consistent across different browsers and contexts. It sets text alignment to left and start. ```css th, td { text-align: left; text-align: start; } ``` -------------------------------- ### Configuring Page Sizes and Margins Source: https://context7.com/zxfr/pd4ml-examples/llms.txt Shows how to apply specific page sizes and margin configurations to document segments using page range patterns. This allows for granular control over layout, such as rotating pages or removing margins for specific sections. ```java import java.io.ByteArrayInputStream; import java.io.FileOutputStream; import com.pd4ml.PD4ML; import com.pd4ml.PageMargins; import com.pd4ml.PageSize; public class PageFormatExample { public static void main(String[] args) throws Exception { String html = "First PageSecond PageThird Page"; PD4ML pd4ml = new PD4ML(); // A5 format for first page only pd4ml.setPageSize(PageSize.A5, "1"); // A4 landscape for second and following pages pd4ml.setPageSize(PageSize.A4.rotate(), "2+"); // Zero margins for pages 1-2 pd4ml.setPageMargins(new PageMargins(0, 0, 0, 0), "1-2"); // Custom margins for page 3 onwards pd4ml.setPageMargins(new PageMargins(0, 0, 0, 0), "3+"); ByteArrayInputStream bais = new ByteArrayInputStream(html.getBytes()); pd4ml.readHTML(bais); pd4ml.writePDF(new FileOutputStream("output.pdf")); } } ``` -------------------------------- ### Implementing Dynamic Headers and Footers Source: https://context7.com/zxfr/pd4ml-examples/llms.txt Illustrates the use of the PD4ML API to inject dynamic headers and footers into a document. It demonstrates the use of placeholders like $[title], $[page], and $[total] to create context-aware document metadata. ```java import java.io.ByteArrayInputStream; import java.io.FileOutputStream; import com.pd4ml.PD4ML; public class HeaderFooterExample { public static void main(String[] args) throws Exception { String html = "Header/Footer example" + "" + "First PageSecond Page"; PD4ML pd4ml = new PD4ML(); // Header for first page only (height: 30pt) pd4ml.setPageHeader("$[title]", 30, "1"); // Footer for first page pd4ml.setPageFooter("Total pages: $[total]", 30, "1"); // Different header for page 2 onwards pd4ml.setPageHeader("$[title] $[page]/$[total]", 30, "2+"); // Right-aligned footer for page 2 onwards pd4ml.setPageFooter( "
Page: $[page]
", 30, "2+" ); ByteArrayInputStream bais = new ByteArrayInputStream(html.getBytes()); pd4ml.readHTML(bais); pd4ml.writePDF(new FileOutputStream("output.pdf")); } } ``` -------------------------------- ### Embed PDF Attachments using PD4ML Tag in Java Source: https://context7.com/zxfr/pd4ml-examples/llms.txt Embeds files as attachments within a PDF document using the `` tag. This Java example demonstrates how to inject an attachment icon and specify the source file to be attached to the PDF. ```java import java.io.FileOutputStream; import java.net.URL; import com.pd4ml.PD4ML; public class AttachmentExample { public static void main(String[] args) throws Exception { PD4ML pd4ml = new PD4ML(); pd4ml.setHtmlWidth(900); // Inject attachment icon at the top of the document pd4ml.injectHtml( "
" + "" + "
", true ); pd4ml.readHTML(new URL("java:/html/H001.htm")); pd4ml.writePDF(new FileOutputStream("with-attachment.pdf")); } } ``` -------------------------------- ### Basic HTML Document Structure Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm Demonstrates the fundamental structure of an HTML document, including doctype, html, head, and body elements. ```html Sample page

Sample page

This is a simple sample.

``` -------------------------------- ### Custom HTML Tag Rendering with Java Graphics2D (Java) Source: https://context7.com/zxfr/pd4ml-examples/llms.txt Enables rendering custom HTML tags by extending PD4ML's CustomTag class and registering a handler. This example demonstrates drawing a star shape. Requires PD4ML library and Java AWT. ```java import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.GeneralPath; import java.io.ByteArrayInputStream; import java.io.FileOutputStream; import com.pd4ml.Constants; import com.pd4ml.CustomTag; import com.pd4ml.PD4ML; import com.pd4ml.fonts.FontCache; public class CustomTagExample { public static class StarTag extends CustomTag { public StarTag() {} public StarTag(String code, FontCache fontCache, CustomTag prime) { super(code, fontCache, prime); } @Override public CustomTag getInstance(String code, FontCache fontCache) { return new StarTag(code, fontCache, this); } @Override public void paint(float x, float y, float width, float height, float containerWidth, float containerHeight, Graphics2D g) { g.setColor(Color.red); float min = Math.min(width, height); float base = min * 0.5f; y += min * 0.07f; GeneralPath path = new GeneralPath(); path.moveTo(x + base * 0.1f, y + base * 0.65f); path.lineTo(x + base * 1.9f, y + base * 0.65f); path.lineTo(x + base * 0.40, y + base * 1.65f); path.lineTo(x + base, y); path.lineTo(x + base * 1.60f, y + base * 1.65f); path.closePath(); g.fill(path); } @Override public boolean isEmptyTag() { return true; } } public static void main(String[] args) throws Exception { PD4ML pd4ml = new PD4ML(); // Register custom tag handler pd4ml.addCustomTagHandler("star", new StarTag()); // Use custom tag in HTML String html = "TEST STAR []"; ByteArrayInputStream bais = new ByteArrayInputStream(html.getBytes()); pd4ml.readHTML(bais); pd4ml.writePDF(new FileOutputStream("custom-tag.pdf"), Constants.PDFA); } } ``` -------------------------------- ### Obnoxious Obsoletion Notice Styling (CSS) Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm Styles for displaying an 'obnoxious obsoletion notice' using the `
` and `` HTML elements. It includes styling for warnings, especially when the details are open or closed, and ensures visibility on non-print media. ```css details { display: block; } summary { font-weight: bolder; } .annoying-warning:not(details), details.annoying-warning:not([open]) > summary, details.annoying-warning[open] { background: #fdd; color: red; font-weight: bold; padding: .75em 1em; border: thick red; border-style: solid; border-radius: 1em; } .annoying-warning :last-child { margin-bottom: 0; } @media not print { details.annoying-warning[open] { position: fixed; left: 1em; right: 1em; bottom: 1em; z-index: 1000; } } details.annoying-warning:not([open]) > summary { text-align: center; } ``` -------------------------------- ### HTML Named Character Reference in Attribute Error Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm Shows a fragile syntax construct involving named character references within HTML attributes. Omitting the closing semicolon for a named character reference can lead to incorrect interpretation, as demonstrated with '©'. The example highlights the correct usage requiring a semicolon. ```html Bill and Ted Art and Copy Bill and Ted Art and Copy ``` -------------------------------- ### Configure PDF Watermarks Source: https://context7.com/zxfr/pd4ml-examples/llms.txt Illustrates how to apply customizable watermarks to PDF pages, including settings for opacity, rotation, scale, and visibility in print or viewer modes. ```java import java.io.ByteArrayInputStream; import java.io.FileOutputStream; import com.pd4ml.PD4ML; public class WatermarkExample { public static void main(String[] args) throws Exception { String html = "Watermarking example" + "" + "First PageSecond Page"; PD4ML pd4ml = new PD4ML(); pd4ml.setWatermark( "WATERMARK", 20, 0, 0.3f, 30, 9, true, true, "1" ); pd4ml.setWatermark( "WATERMARK", 20, 0, 0.3f, 30, 9, true, true, "2+" ); ByteArrayInputStream bais = new ByteArrayInputStream(html.getBytes()); pd4ml.readHTML(bais); pd4ml.writePDF(new FileOutputStream("output.pdf")); } } ``` -------------------------------- ### HTML Element Nesting Rules Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm Illustrates correct and incorrect nesting of HTML elements. Elements must be completely contained within each other without overlapping. ```html

This is very wrong!

This is correct.

``` -------------------------------- ### Configure Custom TTF Fonts in PD4ML with Java Source: https://context7.com/zxfr/pd4ml-examples/llms.txt Supports TrueType fonts (TTF) via directory-based loading or pre-indexed font mapping files for improved performance. This Java example shows two methods: direct font directory usage and using a pre-generated index file for faster font resolution. ```java import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import com.pd4ml.PD4ML; import com.pd4ml.fonts.FontCache; public class FontConfigurationExample { public static void main(String[] args) throws Exception { // Option 1: Direct font directory usage (slower, indexes on the fly) PD4ML pd4ml1 = new PD4ML(); pd4ml1.useTTF("c:/windows/fonts", true); // true = force re-index // Option 2: Pre-indexed font file (faster for repeated use) // First, generate the index file once: File index = File.createTempFile("pd4fonts", ".properties"); FontCache.generateFontPropertiesFile("c:/windows/fonts", index.getAbsolutePath(), (short)0); // Then use the index file: PD4ML pd4ml2 = new PD4ML(); pd4ml2.useTTF(index.getAbsolutePath()); // Command line alternative: // java -jar pd4ml.jar -configure.fonts [index.file.location] String html = "TESTHello, World!"; ByteArrayInputStream bais = new ByteArrayInputStream(html.getBytes()); pd4ml2.readHTML(bais); pd4ml2.writePDF(new FileOutputStream("custom-fonts.pdf")); } } ``` -------------------------------- ### Data and Index Table Styling (CSS) Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm Comprehensive CSS for data and index tables, including styling for captions, cells, headers, and specific classes like 'complex', 'long', and 'longlastcol'. It handles borders, alignment, and image display within tables. ```css table { word-wrap: normal; overflow-wrap: normal; hyphens: manual; } table.data, table.index { margin: 1em auto; border-collapse: collapse; border: hidden; width: 100%; } table.data caption, table.index caption { max-width: 50em; margin: 0 auto 1em; } table.data td, table.data th, table.index td, table.index th { padding: 0.5em 1em; border-width: 1px; border-color: silver; border-top-style: solid; } table.data thead td:empty { padding: 0; border: 0; } table.data thead, table.index thead, table.data tbody, table.index tbody { border-bottom: 2px solid; } table.data colgroup, table.index colgroup { border-left: 2px solid; } table.data tbody th:first-child, table.index tbody th:first-child { border-right: 2px solid; border-top: 1px solid silver; padding-right: 1em; } table.data th[colspan], table.data td[colspan] { text-align: center; } table.complex.data th, table.complex.data td { border: 1px solid silver; text-align: center; } table.data.longlastcol td:last-child, table.data td.long { vertical-align: baseline; text-align: left; } table.data img { vertical-align: middle; } /* Alternate table alignment rules */ table.data, table.index { text-align: center; } table.data thead th[scope="row"], table.index thead th[scope="row"] { text-align: right; } table.data tbody th:first-child, table.index tbody th:first-child { text-align: right; } /* Possible extra rowspan handling */ table.data tbody th[rowspan]:not([rowspan='1']), table.index tbody th[rowspan]:not([rowspan='1']), table.data tbody td[rowspan]:not([rowspan='1']), table.index tbody td[rowspan]:not([rowspan='1']) { border-left: 1px solid silver; } table.data tbody th[rowspan]:first-child, table.index tbody th[rowspan]:first-child, table.data tbody td[rowspan]:first-child, table.index tbody td[rowspan]:first-child{ border-left: 0; border-right: 1px solid silver; } ``` -------------------------------- ### Define Inline Headers and Footers with PD4ML Tags Source: https://context7.com/zxfr/pd4ml-examples/llms.txt Demonstrates how to use proprietary and tags within HTML source to dynamically control document headers and footers across different pages. ```java import java.io.ByteArrayInputStream; import java.io.FileOutputStream; import com.pd4ml.PD4ML; public class InlineHeaderFooterExample { public static void main(String[] args) throws Exception { String html = "Header/Footer example" + "" + "" + "$[title]" + "Total pages: $[total]" + "First Page" + "" + "$[title] $[page]/$[total]" + "" + "
Page: $[page]
" + "
" + "Second Page" + ""; PD4ML pd4ml = new PD4ML(); ByteArrayInputStream bais = new ByteArrayInputStream(html.getBytes()); pd4ml.readHTML(bais); pd4ml.writePDF(new FileOutputStream("output.pdf")); } } ``` -------------------------------- ### Modify link attributes with JavaScript Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm Shows various methods to update link properties, including direct property assignment and the setAttribute method. ```javascript var a = document.links[0]; // obtain the first link in the document a.href = 'sample.html'; // change the destination URL of the link a.protocol = 'https'; // change just the scheme part of the URL a.setAttribute('href', 'http://example.com/'); // change the content attribute directly ``` -------------------------------- ### CSS Styling for W3C Specifications Source: https://github.com/zxfr/pd4ml-examples/blob/master/src/main/java/html/H001.htm This CSS stylesheet is designed for W3C specifications, providing styles for various structural elements, special sections, and numbering. It handles elements like tables, lists, figures, and notes to ensure consistent presentation. ```css /* * Style sheet for the W3C specifications * * Special classes handled by this style sheet include: * * Indices * - .toc for the Table of Contents (
    ) * + for the section numbers * - #toc for the Table of Contents (