I'm trying to hide the header page number on the first page using this example I found here. Which only works if I use it with footer-html and doesn't show/hide anything if I use it with header-html. Originally I was trying to augment this solution which also worked using footer-html, but since I couldn't get it to work in the header I kept on searching. I've tried it with and without 'header-center' => '[[page]]' in case using this with header-html caused conflicts. Anyone been able to get this to work in the headers recently? I'm using PHPWKHTMLtoPDF wrapper version 1.2.6-dev if that helps with a up to date version of WKHTMLtoPDF, since the newest version of PHPWKHTMLtoPDF uses namespaces and we're using CodeIgniter 2.x-dev, which doesn't support them (or play well can't remember).
// Create document PDF
$pdf = new $this->wkhtmltopdf;
// Locate WkHtmlToPdf executable for Windows
if( $pdf->getIsWindows() )
{
$pdf->setOptions( array( 'binPath' => 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe',
'no-outline',
'encoding' => 'UTF-8',
'margin-top' => 30,
'margin-right' => 20,
'margin-bottom' => 30,
'margin-left' => 20,
// Default page options
'disable-smart-shrinking',
'user-style-sheet' => 'pdf.css',
'header-html' => dirname(__FILE__) . '\..\views\wkhtmltopdf\header.html'
) );
}
// Generate document fields
$docInputs = $this->generate_inputs( $inputs, json_decode( $this->load->file( APPPATH . '/mapping/' . $document['mapping'], TRUE ), TRUE ) );
// Merge document fields into HTML exported Word files
$docHTML = $this->parser->parse( 'docs/' . $document['html'], $docInputs, TRUE );
// Add HTML as page, along with option for page header
$pdf->addPage( $docHTML, array( 'header-center' => '[[page]]',
'header-spacing' => '10',
'header-font-name' => 'Times New Roman'
) );
You need to add the <!DOCTYPE html> to the header file, WKHTMLtoPDF issue #46 for version 0.12
I'm posting this answer because this happened to me and this might also be a reason.
I'v also noticed if you set the header css to this. It will not show the header.
html{
width: 100%;
height: 100%;
}
Make sure you have version with patched qt
Related
I had added a dynamic footer text in ten pages single PDF file but now I am stuck in adding two different footers for different pages in the barryvdh/laravel-dompdf composer package in laravel.
I have to add two different footer texts for two different pages in a ten pages single pdf file generated by the above package.
For example:-
Page_1 => footer_text_1 with page_number_1
Page_2 => footer_text_1 with page_number_2
Page_3 => footer_text_1 with page_number_3
Page_4 => footer_text_2 with page_number_1 (again)
Page_5 => footer_text_2 with page_number_2
Please help me out as it's my client's requirement.
Below I am sharing my pdf-generating code.
Here is my controller code:-
$pdf = PDF::loadView($viewPath, [
'pdf' => true,
'key1' => 'value1',
'key2' => 'value2'
])->setOptions(['defaultFont' => 'sans-serif', 'enable_php' => true])->setPaper('a4', 'landscape')->save('' . $path . '/' . $fileName . '.pdf');
return $pdf->download($fileName . '.pdf');
Here is my blade file code for generating one footer text with dynamic page numbers for every single page:-
At the top of the body tag-
<footer>
Footer text here
</footer>
At the bottom of the body tag-
<script type="text/php">
if ( isset($pdf) ) {
$font = null;
$pdf->page_text(295, 810, "{PAGE_NUM}", $font, 10, array(0,0,0));
}
</script>
Any help would be appreciable.
Thank you in advance!!
I am using Headless Chrome to render HTML into PDFs, but
background color rendering in PDFs only seems to work on certain webpages.
This is the library I am using: https://github.com/chrome-php/headless-chromium-php
For the following code, if I change $url to https://www.hovec.co.uk/ then it does not render any background colors or images, and yet it works for the BBC site.
$browserFactory = new BrowserFactory("/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"); //thats my local Chrome
$browser = $browserFactory->createBrowser([
'windowSize' => [794, 1122]
]);
$url='https://www.bbc.co.uk/';
//$url='https://www.hovec.co.uk/';
// creates a new page and navigate to $url
$page = $browser->createPage();
$page->navigate($url)->waitForNavigation();
$page->pdf(['printBackground'=>true, 'marginTop' => 0.0, 'marginBottom' => 0.0, 'marginLeft' => 0.0, 'marginRight' => 0.0])->saveToFile($filepath);
$browser->close();
Any help with this would be much appreciated!
Add this style to HTML page:
<style>
html { -webkit-print-color-adjust: exact; }
</style>
Credits: https://stackoverflow.com/a/60736572/3013633
i have a mPDF report on my system and in the report, it has a header and footer where i use $mpdf->setHeader(); & $mpdf->setFooter(); to set the header and footer. but it displays a bottom border for header and top border for footer. can anyone help me how to remove this?
heres the image:
Here's my Code:
$mpdf=new mPDF('','LETTER-L','','',35,35,60,25,10,10);
//left margin, right margin, body, top margin,top margin,bottom margin,
/*HEADER Monthly Accomplishment Report*/
$mpdf->SetHeader('Sample');
/*FOOTER xMonthly Accomplishment Report*/
$mpdf->SetFooter('Sample');
//==============================================================
//=====================FILE DESCRIPTION=========================
//==============================================================
$mpdf->SetTitle('Monthly Accomplishment Report');
$mpdf->SetSubject('Report');
$mpdf->SetAuthor('sample');
$mpdf->Output('sample.pdf','I');
exit;
//==============================================================
//==============================================================
//==============================================================
You could use those two mpdf properties instead:
$mpdf->defaultheaderline = 0;
$mpdf->defaultfooterline = 0;
I had a look at the documentation of the method setHeader and found that exists a line parameter :
$line: specify whether to draw a line under the Header
You passed a string to the method but it also accept an array of options.
$line mentionned in the doc is not exactly a parameter of the method, rather a key of the configuration array.
So this code should accomplish what you look for, based on the documentation:
$mpdf = new mPDF('','LETTER-L','','',35,35,60,25,10,10);
$headerFooterContent = 'Sample';
$oddEvenConfiguration =
[
'L' => [ // L for Left part of the header
'content' => '',
],
'C' => [ // C for Center part of the header
'content' => '',
],
'R' => [
'content' => $headerFooterContent,
],
'line' => 0, // That's the relevant parameter
];
$headerFooterConfiguration = [
'odd' => $oddEvenConfiguration,
'even' => $oddEvenConfiguration
];
$mpdf->SetHeader($headerFooterConfiguration);
$mpdf->SetFooter($headerFooterConfiguration);
The setHeader and setFooter methods accept the same arguments (they are almost copy/pasted in the library).
I let you look further at the specific part of the examples related to complex header configuration of mPDF.
Let me know if it solves your issue.
Depending on the version of mpdf, you can use this:
$pdf->options['defaultheaderline'] = 0;
$pdf->options['defaultfooterline'] = 0;
I am using mPDF in generating payslips. However, the icons in the payslip aren't showing once it is generated. It only leaves a blank space just like this:
Icons should show on those highlighted spots.
So far, here's what I've done:
I am using Yii2 PHP framework and here's my action controller:
public function actionPdf($id)
{
$model = $this->findModel($id);
$earnings = EarningDetails::find()->where(['payslip_id' => $model->_id, 'status' => 1])->all();
$deductions = DeductionDetails::find()->where(['payslip_id' => $model->_id, 'status' => 1])->all();
$html = $this->render('view', [
'model' => $model,
'earnings' => $earnings,
'deductions' => $deductions,
]);
$mpdf = new mPDF('c','A5-L','0','',0,4,1,1,0,0);
$mpdf->allow_charset_conversion = true;
$mpdf->charset_in = 'windows-1252';
$mpdf->SetTopMargin(0);
$user_password = User::find()->where(['_id' => $model->user_id ])->one();
$password = $user_password->fname.$user_password->lname;
$mpdf->SetProtection(array(), $password, $password);
$mpdf->WriteHTML($html);
$mpdf->Output('Payslip.pdf', 'D');
exit;
}
Am I missing something? Please let me know.
Encoding issues aside, this could be a couple of things. Firstly, you need to integrate FontAwesome with your MPDF installation. Secondly, you need to consider how you're speficiying the glyph in HTML.
Installing FontAwesome in mPDF
Download or clone FontAwesome from https://github.com/FortAwesome/Font-Awesome and copy fonts/fontawesome-webfont.ttf into your MPDF ttfonts/ directory.
In your MDPF config_fonts.php file, add the following lines to $this->fontdata:
/* FontAwesome */
"fontawesome" => array(
'R' => "fontawesome-webfont.ttf"
),
Adding the glyph in HTML
You need to keep in mind that the CSS :before pseudo-selector commonly used to add FontAwesome glyphs to HTML doesn't work in mPDF.
Bad:
<i class="fa fa-smile-o"></i>
... because this FontAwesome CSS rule doesn't work in mPDF:
.fa-smile-o:before {
content: "\f118";
}
Good:
<i class="fa"></i>
You can get the unicode code point for each glyph by clicking on it on the FontAwesome Icon List, but the Cheatsheet is more convenient for this.
You can try to use the re-mapped fontawesome 4.7 (free) font to #0021-#02E5 characters,
and use it as it was regular FONT (ascii).
You can download the ready-to-use font here:
http://mdb-blog.blogspot.com/2021/12/using-fontwesome-in-php-fpdf.html
Note that the example works for FPDF, but it is easly can be made for any tool :)
I want to add 3 custom tags which a MediaWiki admin will add to her templates(for example to the Userlogin.php template for the login page), and these extensions need to be processed by the extension I am building. The tags will be of the form <mytag_forXaction>, <mytag_forYaction>. When the extensions parses through this, they will be replaced with valid HTML tags to display boxes or images or whatever the desired purpose may be.
So far, I have tried doing this:
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This file is a MediaWiki extension, it is not a valid entry point' );
}
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'Test Parser Function',
'description' => 'A simple example parser function extension',
'version' => 0.1,
'author' => 'Me',
'url' => 'https://www.mediawiki.org/wiki/Manual:Parser_functions',
);
$wgHooks['ParserFirstCallInit'][] = 'buttonParserSetup';
function buttonParserSetup( ) {
global $wgParser;
//apploginbtn will be the tag to be replaced
$wgParser->setHook( 'apploginbtn', 'RenderAppLoginButton' );
return true; // Return true so that MediaWiki continues to load extensions.
}
// Render the output of the parser function.
function RenderAppLoginButton( $input, $argv ) {
$output = "SUCCESSFULLY REPLACED.";
return $output;
}
So now when I add the tag <apploginbtn />, or <apploginbtn></apploginbtn>, or {{apploginbtn}}, or {{#apploginbtn}} to the Userlogin.php file at the desired position, the tag doesn't get replaced.
Any help in achieving the desired outcome will be a lot helpful as am stuck with this since 2-3 days and the documentation isn't helpful at all.
Also, am using MediaWiki 1.9.3 as that's the lowest version I need to start supporting.
Use the UserLoginForm hook. It calls your extension function with the UserLogin template (at SVN) which is used to create the login form. It is an instance of QuickTemplate, and you will be able to edit / stuff it up from your extension code.
Do not try to build a parser extension (tag extension) if you don't target parsed wikitext.