I need to create a pdf with four equal length columns across the page using dompdf.
I have tried to do this however I can't work out how to correctly set the widths of the columns. It always ends up cutting the last column off.
How can I render a table with a fixed width across the entire PDF page with four equally wide columns?
Dompdf has issues with tables, page breaks and image display..you can see on their own issues website..Here
I use fpdf, and its really simple to use and consistence in design Check here for simplicity in table display in fpdf
Ok it looks like all I need to do is set the table width to auto or 100% and let the columns scale across the page automatically without setting their widths.
Related
I am stuck with this issue. I am using spipu/html2pdf for generating pdf files. So I have my total width of the page known. But the pdf I am generating will have dynamic tables (meaning I am not aware of how many column / what the size of each column would be while generating) so I want to implement the standard html like behaviour.
ie.
If I put width of the table 100% the table should take 100% of the available space and the table cells should be distributed sensibly. How can I do that?
I have tried flex but spipu/html2pdf does'nt have support for it (and it make sense considering the static nature of pdf).
Can anybody help me with a good way to make this possible?
literally I want to implement how the css display:table; and display:table-cell; is implementd - but manually. because spipu/html2pdf requires you to specify the width in td not on tr or table
Update
A little background - The thing is I am presenting a rich text box to the user for adding extra details. which result in half of the pdf's contents known, but the other half completly unknown. As for the security, I am only allowing a subset of tags like h1 - h6, p, ul, li and table and some of their respective attributes. here is where the issue. The rich text box behave exactly like i want (because its html is rendered in browser).
The only issue is when the user specify the width on the table instead of table-cell and so I want to implement the table's width calculating mechanism so that the report have the same styling. If the user provides a fixed width to table-cell. This is perfectly fine. But if the user provides a 100% width (or any % value) on the table the browser renders this correctly. But the html2pdf just calculate the width from the column.
How I am doing things now:
There is no heavy processing involved here anywhere just some for compatibility issues. The html is sanitized before storing it in the database.
while generating the report,
I just put the contents like
$data = preg_replace('some unkown tag to html2pdf', 'replaced with compatible tags and proper stying', $users_data);
$html2Pdf->writeHtml($data)
If I want the tables data I can do
$data = preg_match('/.*?<table(.*?)>(.*?)<\/table>.*?/', $match)
// so $match have the tables attributes and elments inside
What do I do from here?
So I have a report that generates multiple tables from a database, and grouping them by 'owner' creating a new table for each 'owner'. It does this dynamically using Angular/PHP/Js.
In the print preview I want each table to have it's own page(tables shouldn't really go beyond the length of a page) so I added the page-break-after value to each table.
My issue now is that the tables are cut off. I have the option for landscape, but unfortunately they are long tables, and still get cut off.
I am looking for a solution for the tables to be re-sized when
printed out.
Here is a sample of the table being cut off
I have searched both here, google and w3 for a method that re-sizes the tables to fit the print preview but so far have had no luck.
Suggestions?
You can use a media query for this. Target #print and do some trial and error to get it to look correctly when viewing in print preview. I'm assuming you haven't already done this.
https://css-tricks.com/css-media-queries/
I am using dhtmlxgrid for displaying data for my reports. I have embedded two export buttons i.e. pdf and excel. But there are some number fields which are left aligned in exported file. I want to change the alignment of the number fields to the right as well as I want to set the width of the columns(if possible).
You can change column types to number based ones ( edn or ron ), it will change align of data in those columns in case of export to Excel
I had to do a lot of debugging and a little customization to get column alignment and widths to work how I wanted them do. I have this working in production, but not sure if it will fit your case. This is with dhtmlxgrid v4.1 and I'm using the Java back-end Excel writer classes.
On the front end
You should debug through dhtmlxgrid_export.js in this function:
dhtmlXGridObject.prototype._serialiseExportConfig
Make sure your alignments are correct in this array:
this.cellAlign[i]
If they aren't, you probably need to explicitly set them when you create your grid (but before you load it):
grid.setColAlign(myColAligns.join('|'));
For widths, the same applies:
grid.setInitWidths(myColWidths.join('|'));
On the back-end
In ExcelWriter.java, debug through
headerPrint(ExcelXmlParser parser)
and make sure the your alignments are coming through here:
String al = cells[j].getAlign();
The col widths are also set in this same function. I did a little customization because it didn't seem like the sizes were comparable:
sheet.setColumnView(j, (int)(widths[j]/6.53)); // I replaced "*scale/sumWidth" with /6.53, which is a strange num, but it works! ;
I spent the last day searching for a simple way of converting a csv file to pdf. I found tcpdf and an example of creating a 4-column fixed width table, (and hence can create tables with a low number of columns) but no solution deals with an oversized table spanning multiple landscape pages.
I assume I am not the first one facing this task, so any imput is welcome.
I'm using DomPDF to generate invoices in a project I'm working on.
I've done so several times before and never had any trouble but since today however It got so slow that the maximum execution time gets reached.
I've confirmed that this happens because of: $dompdf->render()
I'm generating some tables to display the data in. but is seems to find this table quite difficult. Does anyone know what could be the problem?
dompdf and my table can be found: http://pastebin.com/G585VQma
(figured I'd put it on pastebin to save some space)
dompdf doesn't support splitting table cells through pages, so you need to change the tables with cellspacing="10" into block elements like divs with the same styling, or at least not put the tables with many lines inside of these tables.