dompdf - just getting two pages in pdf - html

i want to print a html to a pdf. In the project i use symfony and twig to render the template. When i return the html to browser it's looking good.
And it should be about 10 pages.
But when i try to create the PDF, i just get two pages.
$html = $this->render('offer/print.html.twig', array('offer' => $Offer ));
$options = new Options();
$options->setIsRemoteEnabled( false );
// instantiate and use the dompdf class
$dompdf = new Dompdf( $options );
$dompdf->setPaper('A4');
// Render the HTML as PDF
$dompdf->loadHtml( $html );
$dompdf->render();
$dompdf->stream();
PHP 7
Symfony 3.0.9
dompdf 0.7.0
It doesn't looks like the html in the browser. I have to debug the css later.
Can anyone tell me why i just getting two pages in the pdf?

interesting it seems the problem is the render() function.
When i use renderView() instead i got my output over multiple pages.
render() also returns the HTTP Headers. Out of this reason i got a broken pdf with the header information on the first side and all content on the second.
Just the CSS isn't working but this is another issue :)

Please upload you twig file. I think the issues with you twig css.

Related

Simple HTML DOM parser Wordpress

I am using Simple Html dom parser to get simple data from other websites and then be able to paste it into my wordpress pages via shortcode using elementor.
I created a simple plugin which I uploaded together with 'simple_html_dom.php' libary.
The plugin is this:
<?php
include('simple_html_dom.php');
function web_name(){
$html=file_get_html("https://www.google.com/");
return $html->find('title', 0);
}
add_shortcode( 'name2' ,'web_name' );
?>
It works properly in local through XAMMP and VScode but when I include this [name2] shortcode in Elementor I only get blank, not even error.
If I modify the plugin function with:
return "Hello";
The shortcode works fine.
Thanks

Wordpress Headless to reactJS with wp-api

I want to make an app with a wordpress headless server and a react app for the front end with the wp-api.
I can get my data but with html tags. I want to build my html into react, not into wordpress.
I don't know how to do this, I tried to trim the html with wpautop who makes content as plain text (https://codex.wordpress.org/Function_Reference/wpautop), but now I'm stuck because, what if I need to put a picture or a list in the middle of my content with this plaintext :D ?
I don't know if there are solutions for this, that's why I'm asking here.
Regards !
Create one common function for removing HTML tags in the react side like.
removeTags = (str) => {
if ((str===null) || (str===''))
return false;
else
str = str.toString();
return str.replace( /(<([^>]+)>)/ig, '');
}
and call it whenever you get data from Wordpress API like:
this.removeTags(post.excerpt.rendered)
You can check my repo for more information:
https://github.com/BRdhanani/headless-wordpress-with-react

How to make default layout in cakephp3

Actually I work on cakephp3 project.
I want to change the style of the website and put an existing template.
I found a tutorial on how to do that, but I think it was for cakephp2, because I didn't find any file called Dafault.ctp in View folder.
And I tried to put the html code of my template in the home.ctp, but I saw the top-bar navigation which contains Documentation API ...
So where is the Default Layout in cakephp3?
cakephp3 Layouts are in src/Template/Layout/. your view file always use default.ctp file, but you can use other layouts.
// From a controller
public function admin_view()
{
// Set the layout.
$this->viewBuilder()->layout('admin');
// Before 3.1
$this->layout = 'admin';
}
// From a view file
$this->layout = 'loggedin';
a better definition in cakephp3 doc here.
Hi I solved my problem..
I found the Default.ctp
He is in Template->Layout->Default.ctp
contrary to cakephp2 View->Layouts-Default.ctp

Assigning tags for uploaded HTML files in Concrete5

We are planning to load a number of HTML files as they are in the site using Concrete5.
We had to do this since the number of files is too big to load them via editor.
(We are going to generate the html files with madcap flare)
However, I need to use the tag feature of concrete5 for the contents loaded by this method.
I am told by my developers that this is impossible.
Does anyone know how to use tags for files loaded without going through the C5 editor?
i.e. I want the contents in the manually linked html files to be searched and filtered within the site with the search feature and filter feature provided by C5
HELP!!
I recommend creating a very simple template consisting of the standard C5 header/footer code, with one big block as the contents of the body tag.
You can then import the pages by something along the lines of (pseudo-code):
$parent = Page::getByCollectionPath('/');
$ct = CollectionType::getByHandle('template_name');
$data = array(
'cName' => 'The page title',
'cHandle' => 'The trailing path component'
);
$page = $parent->add($ct, $data);
$blocks = $page->getBlocks('Main');
// Gross hack because the template has one block, and that a 'content' block
$blocks[0]->update('content', 'IMPORTED HTML BODY CONTENT');
After that, you can add tags either via the API or the Dashboard.

Render Html as Image

I have a page with a form and button called preview. I need a method to generate a preview, converting the generated HTML to an image.
Clicking on the preview button starts an ajax call to a controller action (I'm using Yii Framework), so I collected all the data from the form and generated a preview with the filled data.
I need to convert the generated HTML to an image; in this way I'm able to re-size to my needed dimension.
I've tried generating a .pdf on the fly and then generate the image from the pdf, and using mpdf extension and imagick. But imagick requires the pdf to be an existing file, while I prefer to generate a .pdf string with mpdf (I can't generate and delete a pdf for each click on preview button).
What is a good method to generate an image from html or from pdf string generated "on the fly"?
This is the code that I've used, but it return an error from imagick, saying image without dimension:
$html2pdf = Yii::app()->ePdf->mpdf('','A4');
$html2pdf->WriteHTML($this->render('preview', array("data" => $data, "imageProvider" => $arrayImage),true));
$content_PDF = $html2pdf->Output('', EYiiPdf::OUTPUT_TO_STRING);
$im = new Imagick();
$im->readImageBlob( $content_pdf );
//$im->setIteratorIndex(0);
$im->setResolution( 800, 600 );
$im->setImageFormat( "jpeg" );
header( "Content-Type: image/jpeg" );
echo $im->getImage();
You need to rethink the requirement to take HTML and generate an image file of it.
I need to convert the generated HTML to an image; in this way I'm able
to re-size to my needed dimension.
You can easily resize the dimension and all elements within a form using proper CSS. This is the route I would take.
Generating an image seems like overkill.
In order to use Imagick, you need to set the SIZE of the picture, not only the solutions:
Can you try something like this first and see what happens?
$thumb = new imagick("/path/".$filename);
$thumb->setImageFormat( "png" );
$thumb->thumbnailImage( 128, 128);