### Initialize and Configure PlotPDF Source: https://context7.com/plot4ai/plot4ai-library/llms.txt Instantiates the PlotPDF class with paper size and sets the print mode. Requires paper size ('A4' or 'A6') as an argument. ```php size = new PDF_Size_A4(); } elseif ($size == "A6") { $this->size = new PDF_Size_A6(); } else { throw new Exception("invalid size"); } $this->setPrintMode(self::PRINT_MODE_BOTH); $this->md = new Markdown(); $this->pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, $this->size->format, true, 'UTF-8', false); } // Set categories from parsed JSON data public function setCategories($arr) { $this->categories = $arr; } // Output PDF to browser public function getContents() { $this->pdf->Output(self::FILENAME, 'I'); } // Write PDF to file public function writeContents($fullPath) { $this->pdf->Output($fullPath, 'F'); } } ``` -------------------------------- ### Docker-based PDF Generation Source: https://context7.com/plot4ai/plot4ai-library/llms.txt Commands to build the Docker image and generate PDFs with or without URL validation. ```bash # Build the Docker image docker build -t plot4ai-pdf . # Generate all PDF formats docker run -v $(pwd)/output:/app/output plot4ai-pdf # Generate with URL validation docker run -v $(pwd)/output:/app/output plot4ai-pdf validate-urls ``` -------------------------------- ### Threat Categories and Lifecycle Configuration Source: https://context7.com/plot4ai/plot4ai-library/llms.txt PHP configuration defining color codes for threat categories, AI lifecycle phases, roles, and AI types. ```php array("main" => "83b3db", "light" => "b2cde8"), // Transparency & Accessibility (Cyan) "7fccdc" => array("main" => "7fccdc", "light" => "b2dee9"), // Privacy & Data Protection (Green) "94cfbd" => array("main" => "94cfbd", "light" => "bde0d4"), // Cybersecurity (Light Green) "bdd895" => array("main" => "bdd895", "light" => "d5e5bd"), // Safety & Environmental Impact (Yellow) "f7f09f" => array("main" => "f7f09f", "light" => "f8f6c6"), // Bias, Fairness & Discrimination (Orange) "f8d18c" => array("main" => "f8d18c", "light" => "fae0b5"), // Ethics & Human Rights (Peach) "f2bc9a" => array("main" => "f2bc9a", "light" => "f6d4bd"), // Accountability & Human Oversight (Pink) "eea4b5" => array("main" => "eea4b5", "light" => "f5c7d0"), ); // AI Lifecycle phases for threat classification $phases = ["Design", "Input", "Model", "Output", "Deploy", "Monitor"]; // Roles applicable to threats $roles = ["Provider", "Deployer"]; // AI types for filtering threats $aiTypes = ["Traditional", "Generative"]; ``` -------------------------------- ### Automate PDF Generation and URL Validation Source: https://context7.com/plot4ai/plot4ai-library/llms.txt Shell script to automate the generation of all PDF formats. Optionally validates all URLs in the threat library when 'validate-urls' argument is provided. ```bash #!/bin/bash # scripts/generate-all-pdfs.sh - Generate all PDF formats # Optional URL validation VALIDATE_URLS=false for arg in "$@"; do if [[ "$arg" == "validate-urls" ]]; then VALIDATE_URLS=true fi done if [[ "$VALIDATE_URLS" == true ]]; then echo "Running url validation..." bash scripts/url_validator.sh -f deck.json -s fi ``` -------------------------------- ### Validate JSON and Generate PDFs Source: https://context7.com/plot4ai/plot4ai-library/llms.txt Uses jq to validate the deck.json file before executing PHP scripts to generate various PDF formats. ```bash if jq empty deck.json; then php scripts/generate-pdf.php plot4ai-A4.pdf A4 FrontAndBack php scripts/generate-pdf.php plot4ai-A6.pdf A6 FrontAndBack php scripts/generate-pdf.php plot4ai-A6-frontsides.pdf A6 Fronts php scripts/generate-pdf.php plot4ai-A6-backsides.pdf A6 Backs echo "Done" else echo "Error: deck.json contains invalid JSON; please check the contents." exit 1 fi ``` -------------------------------- ### Generate QR Code for Threat Cards Source: https://context7.com/plot4ai/plot4ai-library/llms.txt Generates QR codes for threat cards, linking to the PLOT4ai website. Supports PNG and SVG output. Requires threat object with category and question. ```php createPathHash($path); $qrPath = self::QR_IMG_DIR."/" . $hash . "." . $this->getFileExtension(); if (!file_exists($qrPath)) { $url = "https://plot4.ai/" . $path; $this->generateQRCode($url, $qrPath, null); } return $qrPath; } // Generate QR for a specific threat card public function getQrPath($threat) { $hash = $this->createCardId($threat->categories[0], $threat->question); $qrPath = self::QR_IMG_DIR."/" . $hash . "." . $this->getFileExtension(); if (!file_exists($qrPath)) { $url = "https://plot4.ai/library/card/" . $hash; $this->generateQRCode($url, $qrPath, null); } return $qrPath; } protected function generateQRCode(string $url, string $path, ?int $color = null) { $qrcode = new QRCode($this->options); $qrcode->render($url, $path); } } ``` -------------------------------- ### Generate PDF Card Decks with PlotPDF Source: https://context7.com/plot4ai/plot4ai-library/llms.txt The PlotPDF class converts threat card JSON data into printable PDF files. It supports configuration for paper size and print modes. ```php setPrintMode("FrontAndBack"); // Generate PDF from JSON file and write to output $plotPdf->generatePDFFromJsonFile(realpath(__DIR__."/../deck.json")); $plotPdf->writeContents("/app/output/plot4ai-A6.pdf"); // Alternative: Generate from JSON string $jsonData = file_get_contents("deck.json"); $plotPdf->generatePDFFromJsonString($jsonData); ``` -------------------------------- ### Threat Card JSON Structure Source: https://context7.com/plot4ai/plot4ai-library/llms.txt The deck.json file stores threat cards organized by category, containing metadata, questions, and recommendations for AI risk assessment. ```json // deck.json structure - Array of categories with nested cards [ { "category": "Data & Data Governance", "id": 1, "colour": "83b3db", "cards": [ { "question": "Is our data complete, up-to-date, and trustworthy?", "threatif": "No", "label": "Data Quality", "aitypes": ["Traditional", "Generative"], "roles": ["Provider", "Deployer"], "explanation": "Can you avoid the known principle of 'garbage in, garbage out'? Your AI system is only as reliable as the data it works with.", "recommendation": "* Verify the data sources:\n * Is there information missing within the dataset?\n * Can we verify that our training and input data hasn't been tampered with or corrupted?", "sources": "", "qr": "", "categories": ["Data & Data Governance"], "phases": ["Design", "Input", "Monitor"], "cia": ["i"] } ] }, { "category": "Transparency & Accessibility", "id": 2, "colour": "7fccdc", "cards": [ { "question": "Does the AI system need to be explainable for users or affected persons?", "threatif": "Yes", "label": "Explainability", "aitypes": ["Traditional", "Generative"], "roles": ["Provider", "Deployer"], "explanation": "Is the algorithm transparent, or is it a 'black box' that users cannot interpret?", "recommendation": "* Evaluate the type of models that you could use to solve the problem as specified in your task.\n* Consider what the impact is if certain black box models cannot be used.", "sources": "[Explainable Artificial Intelligence (XAI)](https://www.darpa.mil/program/explainable-artificial-intelligence)", "categories": ["Transparency & Accessibility", "Accountability & Human Oversight"], "phases": ["Design", "Input", "Model", "Output", "Deploy"] } ] } ] ``` -------------------------------- ### Configure PDF Size for A4 Source: https://context7.com/plot4ai/plot4ai-library/llms.txt Defines dimensional properties for A4 paper, including margins and font sizes. Used by the PlotPDF constructor. ```php sizeStr = "A4"; $this->format = "A4"; $this->widthMm = 210; $this->heightMm = 297; // Margins $this->marginLeft = 15; $this->marginRight = 15; $this->marginTop = 27; $this->marginBottom = 25; // Font sizes $this->fontNormal = 12; $this->fontNormalPlus = 14; $this->fontH1 = 16; $this->fontCategory = 13; $this->fontFrontQuestionInit = 21; $this->fontExplanation = 18; $this->fontThreatIf = 18; // Card layout positions $this->frontHeaderHeight = 30; $this->frontExplanationYPos = 76; $this->frontDarkYPos1 = 256; $this->frontDarkYPos2 = 280; } } ``` -------------------------------- ### Configure PDF Size for A6 Source: https://context7.com/plot4ai/plot4ai-library/llms.txt Defines dimensional properties for A6 paper, including smaller margins and font sizes. Used by the PlotPDF constructor. ```php sizeStr = "A6"; $this->format = array(111, 154); // Custom format with 3mm excess $this->widthMm = 105; $this->heightMm = 148; // Smaller margins for A6 $this->marginLeft = 7.5; $this->marginRight = 7.5; $this->marginTop = 6; // Smaller font sizes $this->fontNormal = 7; $this->fontH1 = 9; $this->fontFrontQuestionInit = 9; } } ``` -------------------------------- ### URL Validator Script Usage Source: https://context7.com/plot4ai/plot4ai-library/llms.txt Validates URLs in a JSON file and provides options for verbose output and CSV reporting. ```bash #!/bin/bash # scripts/url_validator.sh - Validate URLs in JSON file # Usage: url_validator.sh -f [-w ] [-o ] [-v] [-s] # -f File containing plain text with URLs # -w Comma-separated list of valid HTTP status codes (default: 200,301,302) # -o File to write the output in CSV format # -v Verbose mode: print progress output # -s Summary mode: output totals per HTTP status code # Example usage: bash scripts/url_validator.sh -f deck.json -s # Output: # Checking URLs... # Summary of HTTP Status Codes: # HTTP 200: 85 occurrences # HTTP 301: 12 occurrences # HTTP 404: 3 occurrences # With verbose output and CSV export: bash scripts/url_validator.sh -f deck.json -v -o url-report.csv # Output: # https://example.com/paper.pdf - VALID (200) # https://broken-link.com - INVALID (404) # Output written to url-report.csv ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.