Export pdf document with php using dompdf - php

I have a question for you, so I tried to export pdf document with php using dompdf,all goes well but when I send php variables to display it's add to the end and the beginning .%27
public function generateTitlePage($number_cadastral='')
{
$this->load->library('dompdf_gen');
$dompdf = new DOMPDF();
$html = <<<HTML
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="TitlePage.css" />
</head>
<body>
<div style="margin-top: 100px; text-align: right; padding-right:100px;">
Number:$number_cadastral
<div style="width: 150px;margin-left: 535px;size:1;"><hr style="margin:0px;"></div>
</div>
<div>
</body>
</html>
HTML;
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("welcome.pdf");
In this case variable $number_cadastral is preceded .%27, so the result will be: %27.787883434.%27.Why add this %27??Help me please

<?php
$number_cadastral = ($number_cadastral != "")?preg_replace('/[%]+/','', $number_cadastral):"";
public function generateTitlePage($number_cadastral){
$this->load->library('dompdf_gen');
$dompdf = new DOMPDF();
$html = '
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="TitlePage.css" />
</head>
<body>
<div style="margin-top: 100px; text-align: right; padding-right:100px;">
Number:'.$number_cadastral.'
<div style="width: 150px;margin-left: 535px;size:1;"><hr style="margin:0px;"></div>
</div>
<div>
</body>
</html>
';
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("welcome.pdf");
}
?>
Try this code.

Related

How do I parse GitHub markdown to PHP from a URL?

I can already parse a Markdown file to HTML but my problem is getting that markdown file from a URL instead of a local file.
Below is the code I have:
<?php
include('./includes/Parsedown.php');
$Parsedown = new Parsedown();
$text = 'https://raw.githubusercontent.com/dylanwe/How-to-make-a-discord-bot/master/README.md';
$slug = 'How-to-make-a-discord-bot';
$text = str_replace('img', "https://raw.githubusercontent.com/dylanwe/$slug/master/img", $text);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/themes/prism-coy.min.css">
<link rel="stylesheet" href="css/prism_github.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css">
<style>
.markdown-body {
max-width: 780px;
margin: 0 auto;
padding: 15px;
}
pre[class*=language-]>code {
border: none;
box-shadow: none;
}
</style>
<title>Document</title>
</head>
<body>
<div class="markdown-body">
<?php echo $Parsedown->text($text); ?>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/prism.min.js"></script>
</body>
</html>
It's not very clear what isn't working as expected, but it looks like you just need to retrieve the contents of the Markdown file, e.g. using file_get_contents():
$text = file_get_contents('https://raw.githubusercontent.com/dylanwe/How-to-make-a-discord-bot/master/README.md');

Upload system, similar to youtube

I'm trying to create an upload system similar to YouTube.
But in PDF. When you upload a video to YouTube, you create a page.
I already have a code for the page that would be the pdf. But I needed to know how I could create a page that does the upload and modify the html by changing the pdf link
* pdfListView.loadPdf ("/ upload / ebooks / 1.pdf"); *
Follow the code below
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Demo of pdfListView</title>
<style>
.page-container {
margin: 10px auto;
}
.page-view canvas {
box-shadow: black 0px 0px 10px;
}
</style>
<!-- File from the PDF.JS Library -->
<script type="text/javascript" src="external/compatibility.js"></script>
<script type="text/javascript" src="external/pdf.js"></script>
<script type="text/javascript">PDFJS.workerSrc = 'external/pdf.worker.js';</script>
<!-- Leave out the following two files if you don't need a textLayer -->
<link rel="stylesheet" href="src/TextLayer.css">
<script src="src/TextLayerBuilder.js"></script>
<!-- Leave out the following two files if you don't need an annotations layer -->
<link rel="stylesheet" href="src/AnnotationsLayer.css">
<script src="src/AnnotationsLayerBuilder.js"></script>
<!-- Core pdfListView file -->
<script src="src/PdfListView.js"></script>
</head>
<body>
<div id="main" style="position: absolute; top:0px; bottom:0px; left: 0; right: 0; overflow:scroll">
<!-- The pageContainers go here !-->
</div>
<script type="text/javascript">
window.pdfListView = new PDFListView(
document.getElementById("main"),
{
// Comment out the next line to get a listView without textLayer.
textLayerBuilder: TextLayerBuilder,
annotationsLayerBuilder: AnnotationsLayerBuilder,
logLevel: PDFListView.Logger.DEBUG
}
);
pdfListView.loadPdf("http://playofthegame.me/ebooks/A_HIST%c3%93RIA_SECRETA_DA_MA%c3%87ONARIA_E_ORDEM_ROSACRUZ_-_por_Jakim_Booz.pdf");
</script>
</body>
</html>

How to set css at time of PDF creation in yii2?

Pdf fuction*
This function is call from ajax after getting data from this function it's call anothe file here I am display data which is coming from data base.That file all css part in style tag using then as it is style tag prind in pdf as a text and if this all css file include in css folder then pdf is not create in proper format
public function actionInvoicespacking(){
$pdf = Yii::$app->pdf;
$modelShipment = Shipment::find()->orderBy('ship_id DESC')->one();
if(count($modelShipment) == 0) {
$shipid= 1;
} else
{
$shipid= $modelShipment->ship_id;
}
$htmlContent = file_get_contents('http://localhost/shepherdlogistics_v1.0/backend/views/shipment/invoicespackingdata.php');
$pdf->content = $htmlContent;
return $pdf->render();
}
invoicespackingdata.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>Invoice</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.fontawesome.min.css">
<link rel="stylesheet" href="css/stylepdf.css">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<style type="text/css">
body {
font-size: 18px;
font-family: cambria;
}
.nopadd {
padding: 0px;
}
</style>
</head>
<body>
<div class="container">
<br>
<br>
<div class="">
<div class="col-lg-2 nopadd">
<img src="logopdf.png" alt="logo" width="100%">
</div>
<div class="col-lg-10">
<h1 style="font-size: 55px;font-weight: bold; padding: 23px 0px;">
SHEPHERD LOGISTICS CO. W.L.L.</h1>
</div>
</div>
</div>
</div>
As the demo states:
Any <style> tag will be skipped (you must use cssInline property for this)
If you have just a few styles to add to the pdf, you can pass it like this:
$pdf->content = $htmlContent;
$pdf->cssInline = '.class1 {color: red} .class2 {color:blue}';
But if you have alot of styles, you can also consider change the default cssFile to any file you want with the correct css. (by default, this property is #vendor/kartik-v/yii2-mpdf/assets/bootstrap.min.css

why dompdf doesn't allow to assign a color to a string?

I want to give a color to my string ,but dompdf doesn't allow me. this is my html code :
<style type="text/css">
.red{
color:#574595;
}
</style>
<div style="color:#574595;">asdfsdfsd</div><br>
<font color="red">TRALALAL</font><br>
<div class="red">TRALALAL</div><br>
I tried 3 possible way, but neither don't work. How can I manage that ?
this is my full code :
<?php
ini_set("gd.jpeg_ignore_warning", 1);
set_include_path(get_include_path() . PATH_SEPARATOR . "dompdf");
require_once('dompdf/dompdf_config.inc.php');
$category = $_GET['c'];
$dompdf = new DOMPDF();
$html =
'<html>
<head>
<style type="text/css">
.red{
color:#574595;
}
</style>
</head>
<body>
<div style="color:#574595;">asdfsdfsd</div><br>
<font color="red">TRALALAL</font><br>
<div class="red">TRALALAL</div><br>
</body>
</html>';
$dompdf->load_html($html);
$dompdf->render();
$output = $dompdf->output();
file_put_contents("pdf_generated/file.pdf", $output);
header("Location: http://acros.netlogiq.info/pdf_generated/file.pdf");
?>
and this is the result:
Check it out this is an example:
http://jsfiddle.net/C6bQf/
Code:
<style>
.red{
color: red;
}
</style>
<div style="color: red;">asdfsdfsd</div><br>
<font color="red">TRALALAL</font><br>
<div class="red">TRALALAL</div><br>
Save your file as HTML.
Just tried your code here: http://www.digitaljunkies.ca/dompdf/examples.php
HTML:
<html>
<head>
<style type="text/css">
.red{
color:#574595;
}
</style>
</head>
<body>
<div style="color:#574595;">asdfsdfsd</div><br>
<font color="red">TRALALAL</font><br>
<div class="red">TRALALAL</div><br>
</body>
</html>
And its working, I got red color font. Check your configuration settings once.
EDIT:
DOMPDF PHP CODE:
<?php
require_once "../dompdf_config.inc.php";
ini_set("gd.jpeg_ignore_warning", 1);
$dompdf = new DOMPDF();
$html =
'<html>
<head>
<style type="text/css">
.red{
color:#574595;
}
</style>
</head>
<body>
<div style="color:#574595;">asdfsdfsd</div><br>
<font color="red">TRALALAL</font><br>
<div class="red">TRALALAL</div><br>
</body>
</html>';
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
exit(0);
?>
I tried this and I am getting font color. Check your configuration. Configuration UI can be displayed here: localhost/dompdf/www/setup.php
(I hope you have the same folder structure available)

PHP CSS :: inline work but not internal and external stylesheet

I have created PHP files which accept data from $_GET method.
After that I use all the data I get to create HTML pages. Nothing is wrong with the data but in CSS I cannot style HTML elements. Except when it comes to inline styling, that works but it is not good to maintain.
I try to use like this but it doesn't work , Please Help
THANK IN ADVANCE
Example.php
<?php
$dataCover = $_GET['dataCover'];
$dataTitle = $_GET['dataTitle'];
$dataTag = $_GET['dataTag'];
$dataDir = $_GET['dataDir'];
$dataYear = $_GET['dataYear'];
$dataCreated = $_GET['dataCreated'];
$dataModified = $_GET['dataModified'];
$userAUID = $_GET['userAUID'];
$galleryID = $_GET['galleryID'];
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css" media="all">
#container img{
height: 230px;
width: 200px;
}
#container .center{
display: block;
margin: 0 auto;
}
</style>
<script src="../lib/jquery-1.10.2.min.js"></script>
<script src="../lib/jquery.mobile-1.3.1.min.js"></script>
<script src="../lib/se.js"></script>
</head>
<body>
<div data-role ="page" id ="page1">
<div data-role ="header">
<h1> header </h1>
</div>
<div data-role="content">
<div id="container">
<img class="center" src="<?echo $dataCover?>" alt=""/>
<p id="title"><?echo $dataTitle;?></p>
<p id="tag"><?echo $dataTag;?></p>
<p id="created">Created : <?echo $dataCreated?></p>
<p id="modified">modified : <?echo $dataModified?></p>
View Ebook-Gallery
Bookmark
</div>
</div>
</div>
</body>
</html>
When you move your css from inline to style sheet file, you have to refresh your page with Ctrl+F5. Maybe it's coming from the cache.
Also you can assign your css to the image by jquery.
I dont see any reference to any external stylesheet, so it seems like you have forgotten to do this.
Put this line
<link rel="stylesheet" type="text/css" href="/css/style.css" />
Somewhere in the head. Maybe before the script tags.
Make sure you adjust the path to your stylesheet.
Yes When you want to apply external css you have to give the path after the <title> tags within the <head> tags .just follow the html code
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<!--Here css is the folder name where you have keep the style.css file -->
<script src="../lib/jquery-1.10.2.min.js"></script>
<script src="../lib/jquery.mobile-1.3.1.min.js"></script>
<script src="../lib/se.js"></script>
</head>

Categories