I want created a PDF with more than one site. I have following with PHPPdf and Twig (as example):
<pdf>
<dynamic-page>
<table>
<tr>
<td>1.</td>
<td>Some header</td>
</tr>
<tr>
<td>1.1</td>
<td>Some subheader</td>
</tr>
<tr>
<td> </td>
<td>Relay long text here........</td>
</tr>
</table>
</dynamic-page>
</pdf>
Now I have the problem that the table part with the long text will write in some cases (when there is not enough place on the site) completely set on the next page in the PDF. But I want that it write as much text as possible on the current page and split than the table with the following text to the next site. Is there a way to do that?
Related
I am using "zanysoft/laravel-pdf" package in laravel to generate PDF and I am succeed to generate PDF but that PDF is display as mirror reflected PDF. How can i solve this issue ?
i want in left Marked part that is S.N and then Question and then Explanantion etc.
you can change the order of Table and means serial no should be at the last and last column should be first. and some extra CSS code for alignment.
Here is code example
<table class="table table-bordered">
<thead>
<tr >
<td <strong>Subject</strong></td>
<td <strong>Teacher</strong></td>
<td <strong>Explanation</strong></td>
<td <strong>Question</strong></td>
<td <strong>S.N</strong></td>
</tr>
</thead>
<tbody>
</tbody>
</table>
i am quite new to laravel and blade templates , and i am quite confused what should i do in this situation.
I got mutiple tables - cpus table, motherboards table, memory table etc... each table contains information about parts specifications
I'm retrieving single column from a table
$select_columns = [
'cores',
'threads',
'frequency',
'max_frequency',
'l1',
'l2',
'l3',
'thermal',
'tech',
];
$specs = \DB::table('cpus')->select($select_columns)->where('slug' , $slug)->first();
The information about specification and value should be displayed like this.
<table>
<tbody>
<tr>
<td>Specificiation</td>
<td>value</td>
</tr>
<tr>
<td>Specification</td>
<td>value</td>
</tr>
// other specifications
</tbody>
</table>
I could easily output all tables rows with foreach loop using 1 template.
#foreach ($specs as $spec => $value)
<tr>
<td>{{$spec}} </td>
<td>{{$value}} </td>
</tr>
#endforeach
but the {{spec}} - specificarions needs to be in different language, and i can't use
select(column as newvalue)
because there are letters like 'Ā Ļ Ņ Ž ' and code would loook really weird if i would do that
So i guess the question is what exactly should i do about it?
Should i make each table a new template and display data like this?
<tr>
<td>Specification</td>
<td>{{$specs->value}}</td>
</tr>
<tr>
<td>Specification1</td>
<td>{{$specs->value1}}</td>
</tr>
I'm quite lost here.
Thanks in advance.
Personally I would not make a separate template for each table. Dry, lazy developer and all those things.
I think the localization functionality from Laravel might be a good fit here. You could use the keys from your array as keys in your translation files. Perhaps something like this:
#foreach ($specs as $spec => $value)
<tr>
<td>{{trans('specs.' . $spec)}} </td>
<td>{{$value}} </td>
</tr>
#endforeach
And inside you resources/lang/fr/specs.php file you you could do something like:
return [
'cpu' => 'çpû',
// ...
];
You could even add additional texts (some sort of description or whatever) based on those keys to enrich your tables even more. And if you ever decide to translate your website to another language you're already halve way there, you just have to add a folder for your new language and copy and translate those files there.
I try to execute select * from articles where category_id=1 in laravel eloquent model as below.
$articles = Article::where('category_id', '=', $id)->get();
And i pass this to my view file by using compact method as below.
return view('homeview.index', compact('articles'));
And i use this $articles variable in foreach loop and print each article's title in view file. But the thing is when i try to execute this, my view file is refreshing continuously and incrementing the same div class which i used to print the article titles. I tried to use above code as raw query also. It also generates the same issue.
below is my view file.
<tbody>
#foreach($articles as $article)
<tr>
<td><img src="{{asset('/img_thumbs/'.$article->img_thumb)}}"></td>
<td class="-align-center">
<h4>{{$article->title}}</h4>
<p>{{$article->sub_paragraph}}</p>
</td>
<tr>
#endforeach
</tbody>
Please help me to solve this.
The bottom line is, THere's an error in your HTML.
You are opening <tr> but not closing it.
<tbody>
#foreach($articles as $article)
<tr>
<td><img src="{{asset('/img_thumbs/'.$article->img_thumb)}}"></td>
<td class="-align-center">
<h4>{{$article->title}}</h4>
<p>{{$article->sub_paragraph}}</p>
</td>
</tr> <!-- HERE -->
#endforeach
</tbody>
i used some java scripts for my application. That repeating thing happening because one script file. After i comment it, my page is working fine. I used some template called inspinia and it is happening because inspinia.js file.
On my site: www.metallica-gr.net you can see that the main table has 3 columns.
1st column(left): Vertical image
2nd column(middle): Main content
3d column(right): Vertical image
Problem is, because the right image is on the bottom of the code(since it's the tables last column) it waits for main conent to load before appearing. So before the site loads it looks messy, since only one border of the layout appears.
I can't use the divs for this since I have a lot html pages made already, and also when I tried it didn' went good. Is there any way to fix this? Here's the code:
index.html:
<table border="0" cellspacing="0" cellpadding="0" id="main" align="center">
<tr>
<td width="2" valign="top"><?php include "vertical.php"?></td>
<td valign="top" style="vertical-align:top;">
<div><?php include "main.html"?></div></td>
<td width="2" valign="top"><?php include "vertical.php"?></td>
</tr>
</table>
vertical.php:
<div style="background-image:url(images/vertical.jpg); width:2px; height:100%; background-repeat:repeat-y; vertical-align:top; position:fixed; top:0;"></div>
While I would recommend exploring a more modern HTML structure (like the use of divs), I understand that sometimes a complete restructuring is not viable.
I believe the PHP output buffer may offer an interim solution.
<?php ob_start(); ?>
<table border="0" cellspacing="0" cellpadding="0" id="main" align="center">
<tr>
<td width="2" valign="top"><?php include "vertical.php" ?></td>
<td valign="top" style="vertical-align:top;">
<div><?php include "main.html" ?></div>
</td>
<td width="2" valign="top"><?php include "vertical.php" ?></td>
</tr>
</table>
<?php ob_end_flush(); ?>
What this will do is hold the page response until all the includes have been processed. You should also be aware that while this may cause less "shuffling" on the page it could also increase the perceived load time.
See the PHP Manual's documentation on ob_start for more information: http://www.php.net/manual/en/function.ob-start.php
While the above should take care of any issue caused by PHP includes it looks like you may have a few other likely culprits. The most likely being that you have tags loading from an "src". Script tags will delay all other loading while they're being loaded and processed which is why it is recommended that they be added asynchronously if possible. If they cannot be loaded asynchronously they should be included within the or directly above the closing tag.
For a little more information on your script issue see:
Does the <script> tag position in HTML affects performance of the webpage?
While sifting through the HTML I also spotted quite a few validation errors that should probably be resolved:
http://validator.w3.org/check?uri=http%3A%2F%2Fmetallica-gr.net%2F&charset=%28detect+automatically%29&doctype=Inline&group=0
Even a table based layout should validate as it makes browser rendering more predictable and bug hunting easier.
I think you should replace the table structure with div structure because that's the draw back of table structure that it'll load each TR / TD line by line while in DIV structure we make different divisions that's why browser will load different divisions simultaneously and that's why now a days designers are prefer DIV structure.
In your case it's starting to load from first TD and end with the last TD one by one so I think DIV structure is the solution for your problem.
I need some help. I am working on a backend of a website and I want to create functions where I can re-use the same code instead of duplicating it.
So I will have certain "sections" that contain information, such as:
getQuickInfo
function getQuickInfo() {
echo '
<div class="portlet">
<div class="portlet-header">
<h4>Quick Info</h4>
</div>
<div class="portlet-content">
<table cellspacing="0" class="info_table">
<tbody>
<tr>
<td class="value">'.getCount("total_users").'</td>
<td class="full">Total Users</td>
</tr>
<tr>
<td class="value">'.getCount("count_open_requests").'</td>
<td class="full">Open Support Requests</td>
</tr>
</tbody>
</table>
</div>
</div>
';
}
Now I know I am approaching this the wrong way, that's why I am posting this question. But that is just an example of a Quck Info section I would like to re-use on other pages, so I can sitck it wherever I want and just do getQuickInfo()
For this example, that function works fine. I would like suggestions on a better way to do it, and also for some other sections it won't be that easy it will have some Mysql queries and grabbing information from a database, which I can't store that within an echo.
How does everyone else accomplish stuff like this?
My main goal is to be able to output sections wherever I would like:
getQuickInfo()
getAdminNotes()
getSupportRequests()
etc.
Thanks!
Much as I am loathed to mix raw HTML with PHP code in templates, I know others disagree with me and this is one place where it might be a valid use.
So you would create a file that looks like this:
quickinfo.php
<div class="portlet">
<div class="portlet-header">
<h4>Quick Info</h4>
</div>
<div class="portlet-content">
<table cellspacing="0" class="info_table">
<tbody>
<tr>
<td class="value"><?php echo getCount("total_users"); ?></td>
<td class="full">Total Users</td>
</tr>
<tr>
<td class="value"><?php echo getCount("count_open_requests"); ?></td>
<td class="full">Open Support Requests</td>
</tr>
</tbody>
</table>
</div>
</div>
...and in you main page, you can just do:
include('quickinfo.php');
You can easily adapt this to use the result of queries. You would simply perform the query in the main page, and assign the results to a named variable. Then in the template page you use the data in the named variable to generate the page. This means that you can use the same code to generate different results based on different queries - as long as the result are held in the same named variable.
If you're using php 5 you should considered using PHP's object orientation support.
http://php.net/manual/en/language.oop5.php
This way you can create a class which has methods that print out stuff and hold values and then instantiate this class and call it's methods as needed.
I'm no php guru, but maybe you should create separate .php files for each of those sections (something like quickinfo.php, adminnotes.php, etc) put your html layout inside, and maybe even the php functions you need (or you could put them in a separate file, this depends on whether the logic you need is too complex, if it's fairly simple you can put everything in the same file)
Then you would do something like include('quickinfo.php') wherever you want to use those sections.