How do I insert content after new page (automatically generated) or forced page break with dompdf using Twig? - dompdf

I have created a PDF template that consists simply on a table with a header and multiple rows using Twig to create a PDF through dompdf library.
My problem is that I'm required to insert always another content, specifically a table, after each page with the purpose of having this another table always on the back page when doing duplex printing (in other words, at the end there should be an even number of pages, with the odd ones corresponding to the first table and the even ones corresponding to the inserted table). Do you know if there is a way to achieve this using dompfd or another PDF generation library compatible with Symfony/Twig?
Update: After thinking about other approaches to solve the problem, finally I discovered a library named php-pdftk, that allowed me to create the PDF that I wanted by separating each table into separated PDF's (with dompdf) and then merging both files with the function named "shuffle" (from pdftk), that inserts one page of the first PDF and then one page of the second PDF and so on.

Dompdf can handle the CSS property page-break-*:
.page_break {
page-break-after:always;
}
<h1>Page 1</h1>
...
...
<div class="page_break"></div>
<h1>Page 2</h1>
...
...

Related

Select yaml with drop down

I'm using Github pages to build some pages with text I want to get from yaml files. At present I have two yaml files one each for a different car type. I want to use a drop down in the header to select a car type which will then inform which yaml file to get to repopulate the page with text specific to that car.
I can create the drop down which adds a query string param to the page. I can also iterate through the two yaml files and output specific variables. What I can't figure out is how to use the two together so that the yaml file for the page is informed by the user selection from the dropdown.
Or maybe there is a much better way of doing this??
Github pages uses Jekyll, a static site generator. Your site is built once when you push to your gh-pages branch. After that, your browser is just served the generated HTML pages. All the iterating over your YAML files is done at generation time, not when you request the pages. Since you have no server-side code that is executed when you change your dropdown, you cannot process a query parameter.
Since you cannot process query parameters, you need to place your cars on different URLs. Here's a simple example how to change URLs with a <select> and JavaScript, using the code from this answer:
<select name="" onchange="javascript:location.href = this.value;">
<option value="/mypage/car1/" selected>Car1</option>
<option value="/mypage/car2/">Car2</option>
</select>
Then you just need to generate the HTML pages for each car, located at /mypage/car1/ and /mypage/car2/ respectively. That can be done by using your YAML data as part of the YAML front matter. For example, this could be car1.md:
---
layout: car
permalink: /mypage/car1/
data: # data of your car here
name: my very awesome car
---
Markdown content here (leave empty if you don't need it)
You then create the layout _layouts/car.html and in it, generate the appropriate HTML page. For example, to show the car's name, do something like:
<label>Name:</label> {{page.data.name}}
To avoid JavaScript, you can also create a dropdown menu containing <a> links with pure HTML+CSS.

ABCpdf AddImageHtml two html in one page

Is it possible to add two html string in one page ?
When the pdf is rendered, I can only see the second html. It seems that the first one is overwritten
The only way I have found that you can do this is to add each HTML to its own document then merge both documents together
theDoc.AddImageUrl(Url1);
theDoc2.AddImageUrl(Url2);
theDoc.Append(theDoc2);

Automatically assign profile pics to pages in phpfox

Followed by my last question: Automatically create pages in phpfox
Now I'm trying to assign a list of pre-uploaded images to some pages as their profile picture in phpfox.
After checking data changes in the database, I only realized changes in these two fields:
image_path in table of phpfox_pages (which take a an address to the image file)
user_image in table of phpfox_user (which take a string of "user_id+%s".file_extension)
But by inserting data in these two fields in records for a page that has a default profile pic, it's profile pic would not change.
Is there any other fields or options that I should change?
Look at the file /module/pages/include/service/process.class.php In there look for the function update and around line 442 find this
if ($this->_bHasImage)
This piece of code handles setting an image for the page, notice how it creates three thumbnails, maybe the problem you're having is that you didn't create all the needed thumbs. You also need to update the column image_server_id.
Hope it helps
look phpfox_photo table in that you will find is_profile_photo attribute that is always 1 for the profile picture

Force a Content to in new page when generating a PDF

Im using play framework and rendering PDF usin rednerPDF() method.
I would like to display some part of content always be in new page.
For Example I have two tables, One table should be in first page and another table should in next page instead of continue from first page. The first table contents are dynamic and we can't sure the height of the table.
Is it possible?
Is it possible?Yes.
You said one table(first one) should be in first page,and again you said its content is dynamic.Now my question is it span over pages and in the next page you want to write second table?This is a generic scenario and what you mentioned is specific one.
You can start trying using two properties of PdfPTable setSplitLate() and setSplitRows()(just google it out for details read Itext In Action).Just keep Two table as two Rows of outer table.set those two property for inner as well as outer in some way as you want(i.e generic case/Specific case).
Another alternative way is use writeSelectedRows() method over PdfContentByte(I don't konw which Object you gonna use for manipulating pdf but you can get it from PdfWriter,*PdfStamper* by using getDirectContent/*UnderContent*/OverContent) after generating table.To use this method you have to set total width of the table so the height can be calculated by method getTotalHeight of PdfPTable.If You use this height properly you absolutely know where your table ends.But all these specific part you have to read & understand first.
With yahp you can use a special html tag to force a page break
<yahp:pb />
we can achieve this by page-break-after:always
Please refer
Alternate to PDF for dynamically generated document with page breaks

create a simple pdf report from html

I'm looking for a way to generate pdf files from html
In order to make simple tabular reports I would need the following features
table rendering
variable page size
repeating headers / footers on every page
calculated page number / total page
css support would be nice
I know there have been many similar questions in stackoverflow, but I don't know if there's a product that supports the aforementioned features...
Ideally, the source would be a plain and simple well built html with css, (I'm building the html files, so I can adapt to the products needs, that is, it won't have to render every piece of html crap you can throw at a browser) and with some custom tags to configure headings, footer, page size, etc...
then I would run a command line to convert it from html to pdf.
I think http://www.allcolor.org/YaHPConverter/ does something like that
Take a look at TCPDF
Check out the examples.

Resources