Coder Social home page Coder Social logo

ctrl-p's Introduction

Ctrl P

Latest Version on Packagist Pest Action Pint action Total Downloads

Setup

composer require medilies/ctrl-p

Requirements

  • PHP 8.1

Usage

Set the HTML

  • Use CtrlP::html('foo') or $ctrlP->setHtml('foo') to set the HTML.
  • Use CtrlP::template('<?php echo "foo";', []) or $ctrlP->template('<?php echo "foo";', []) to set the HTML from a PHP template.

Set page size and orientation

  • Use format($paperFormat) to set a standard paper format.
  • Use landscape() or portrait() to direct the chosen paper format.
  • Use paperSize($width, $height) to set an explicit size.

Margin

Use margins($margins) to set the margins.

Margins (header and footer) content cannot be be edited as of december 2023 because no browser supports it (see)

Control

  • Use printButton($bool) to add/remove a print button.
  • Use backUrl($url) to add/remove a button with a link to a page of your choice.
  • Use autoPrint() to automatically print the page after rendering it.

Overrides

  • Use title($title) to override the title.
  • Use urlPath($url) to override the url path.

Example

<?php

// php -S 0.0.0.0:8080 .\this_file.php
// Visit http://127.0.0.1:8080/

use Medilies\CtrlP\CtrlP;

require_once __DIR__.'/../vendor/autoload.php';

echo CtrlP::html('
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Flex and Grid HTML Page</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 0;
    }

    .container {
      display: flex;
      height: 100vh;
    }

    .sidebar {
      background-color: #f2f2f2;
      width: 250px;
      padding: 20px;
    }

    .main-content {
      flex: 1;
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      gap: 20px;
      padding: 20px;
      background-color: #e0e0e0;
    }

    .box {
      background-color: #fff;
      padding: 20px;
      border-radius: 5px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
      text-align: center;
    }
  </style>
</head>
<body>

  <div class="container">
    <div class="sidebar">
      <h2>Sidebar</h2>
      <p>Some sidebar content goes here.</p>
    </div>

    <div class="main-content">
      <div class="box">Box 1</div>
      <div class="box">Box 2</div>
      <div class="box">Box 3</div>
      <div class="box">Box 4</div>
      <div class="box">Box 5</div>
      <div class="box">Box 6</div>
    </div>
  </div>

</body>
</html>
    ')
    ->margins('1cm')
    // ->paperSize('130mm', '130mm')
    ->format('A4')
    ->landscape()
    ->title('Chad PDF')
    ->urlPath('/drip-url')
    ->autoPrint()
    ->printButton()
    ->backUrl('/some-path')
    ->get();

screenshot

ctrl-p's People

Contributors

medilies avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.