When generating the pdf with page-break-before after 3rd rows the design is breaking down. Here is my code
<!DOCTYPE html>
<html lang="en">
<head>
<title>DOM-PDF</title>
</head>
<body>
<table style="width:100%;">
<thead>
<tr>
<th>Serial</th>
<th>Name</th>
<th>Roll</th>
<th>Info</th>
</tr>
</thead>
<tbody>
#php
$n = 0;
for($i=0;$i<10;$i++){
#endphp
<tr style="text-align:center;">
<td>1</td>
<td>Rashedul Hasan</td>
<td>1208039</td>
<td>I am an employee.</td>
</tr>
#php
if($n==3){
echo "<i style='page-break-before:always;'></i> ";
}
$n++;
}
#endphp
</tbody>
</table>
</body>
</html>
This is the pdf view of page 1
This is the pdf view of page 2
In page 2 second row is moving to the right. How to fix it?
What about using chunks instead of breaking the table?
{{-- Replace collect()->times(10) with a collection when you're getting the actual data from DB --}}
#foreach (collect()->times(10)->chunk(3) as $chunk)
<table style="width:100%;">
<thead>
<tr>
<th>Serial</th>
<th>Name</th>
<th>Roll</th>
<th>Info</th>
</tr>
</thead>
<tbody>
#foreach($chunk as $result)
<tr style="text-align:center;">
<td>{{ $result }}</td>
<td>Rashedul Hasan</td>
<td>1208039</td>
<td>I am an employee.</td>
</tr>
#endforeach
</tbody>
</table>
<i style='page-break-before:always;'></i>
#endforeach
Related
I try to convert the html file to msg file, it stopped convert when meet third table tag in html.
I searched this question but didn't get any result -- it seems like only myself meet this problem.
So this is the example html code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>This Email is using for understand outlook mail synthesis</h1>
<h2>0001</h2>
<table>
<tr>
<td>This is image001.jpg</td>
</tr>
<tr>
<td>
// stop parsing after parse this table
<table>
<tr>
<td>
<img src="cid:image001.jpg" alt="">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>This is image002.jpg</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
<img src="cid:image002.jpg" alt="">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>This is image003.jpg</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
<img src="cid:image003.jpg" alt="">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>This is image004.jpg</td>
</tr>
<tr>
<table>
<tr>
<td>
<img src="cid:image004.png" alt="">
</td>
</tr>
</table>
</tr>
</table>
<h1>No!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!</h1>
</body>
</html>
And this is my python code:
from win32com import client as win32
import os
outlook = win32.Dispatch("outlook.application")
mail = outlook.CreateItem(0)
mail.Subject = "This is a subject"
with open(".\\mix.html", "r", encoding="utf-8") as f:
html = f.read()
mail.HtmlBody = html
current_path = os.getcwd()
at = mail.Attachments.Add(current_path + "\\image001.jpg")
at.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "image001.jpg")
at = mail.Attachments.Add(current_path + "\\image002.jpg")
at.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "image002.jpg")
at = mail.Attachments.Add(current_path + "\\image003.jpg")
at.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "image003.jpg")
at = mail.Attachments.Add(current_path + "\\image004.png")
at.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "image004.png")
mail.SaveAs(current_path + "\\rst.msg")
This is what I see when I open the "rst.msg" file:
stop parsing after parse the table
I deleted the table in second tr tag and run the python script, this is what I get:
stop parsing again after parse the table
This is the html code I deleted the table in second tr tag:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>This Email is using for understand outlook mail synthesis</h1>
<h2>0001</h2>
<table>
<tr>
<td>This is image001.jpg</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>This is image002.jpg</td>
</tr>
<tr>
<td>
// stop parsing after parse this table
<table>
<tr>
<td>
<img src="cid:image002.jpg" alt="">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>This is image003.jpg</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
<img src="cid:image003.jpg" alt="">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>This is image004.jpg</td>
</tr>
<tr>
<table>
<tr>
<td>
<img src="cid:image004.png" alt="">
</td>
</tr>
</table>
</tr>
</table>
<h1>No!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!</h1>
</body>
</html>
Hope you can help me! Thank you very much!
This question was solved by upgrading outlook version. In the new version, outlook can generate email as expected, but if you add some picture to the email used for html generating and save this email, then pictures are added to the email as appendix. If you send the email after generate it and before save it, the receiver can't see those appendix. That's what you might want.
Upgrading the outlook version is a way to solve this question.
See html below. Have a series of tables that include rows with a name attribute name="laneStop". I can select those rows like this in the Chrome dev console
$x("/html[1]/body[1]//TR[#name='laneStop']")
However, I also need to get the 2nd cell of the 2nd row of the 1st table ABOVE these rows, eg. the value
abc_123_florida-45
Here is the html. Whats a way to refer to this value above - knowing that Im getting the "laneStop" rows first
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<table border="1">
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td>Date</td>
<td>11/15/2019</td>
</tr>
<tr>
<td>shipment number</td>
<td>abc_123_florida-45</td>
</tr>
<tr>
<td>Departure time:</td>
<td>0430</td>
</tr>
</tbody>
</table>
</td>
<td>
<table>
<tbody>
<tr>
<td>Time arrival</td>
<td>1715</td>
</tr>
<tr>
<td>customer</td>
<td>bob smith</td>
</tr>
<tr>
<td>box type</td>
<td>square</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table border="1">
<tbody>
<tr>
<td>
<table>
<tbody>
<tr name="laneStop">
<td>box1</td>
<td>23.45</td>
<td>lane1</td>
<td>south</td>
</tr>
<tr name="laneStop">
<td>box2</td>
<td>17.14</td>
<td>lane1</td>
<td>south</td>
</tr>
<tr name="laneStop">
<td>box3</td>
<td>17.18</td>
<td>lane1</td>
<td>north</td>
</tr>
<tr name="laneStop">
<td>box2</td>
<td>199.14</td>
<td>lane1</td>
<td>west</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
Try the following xpath.
//td[text()='shipment number']/following::td[1]
Demo:
If you want to travel from your current node (i.e., the "laneStop" rows), one way to do that is to use this xpath expression:
./preceding-sibling::*/ancestor::*[6]/preceding-sibling::table[1]//tr[1]/td[1]/table[1]//td[1]//tr[2]/td[2]
I'm curious to see if it works for you.
The error is on the view which says that
my $audio variable is not defined.
I want to show everything from the database using a foreach loop.
I tried base on paginate on the laravel documentation https://laravel.com/docs/5.7/pagination#basic-usage
My controller is below:
use Illuminate\Http\Request;
use App\Audio_lectures;
use Illuminate\Support\Facades\DB;
public function index(){
$audio = DB::table('audio_lectures')->latest()->paginate();
return view('welcome', ['audio_lectures' => $audio]);
}
The welcome view is below:
<div class="container">
<div class="row">
<table class="table table-dark">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Subject</th>
<th scope="col">Date Added</th>
<th scope="col">Download</th>
</tr>
</thead>
<tbody>
#foreach ($audio as $audio_lectures)
<tr>
<th scope="row">{{$audio_lectures->id}}</th>
<td>{{$audio_lectures->subject}}</td>
<td>{{$audio_lectures->created_at}}</td>
<td>Download</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
My route web.php is below:
Route::get('/','Audio_lecturesController#index');
I expect to show all the audio lectures from my database to my view.
try this one
#foreach ($audio_lectures as $audio)
<tr>
<td scope="row">{{$audio->id}}</td>
<td>{{$audio->subject}}</td>
<td>{{$audio->created_at}}</td>
<td>
Download
</td>
</tr>
#endforeach
you are passing from controller audio_lectures array but you
getting as in your view audio
On your view file looping try this
#foreach ($audio_lectures as $value)
<tr>
<td scope="row">{{$value->id}}</td>
<td>{{$value->subject}}</td>
<td>{{$value->created_at}}</td>
<td>Download</td>
</tr>
#endforeach
i can't load able to pass a parameter to the dompdf function LoadView.
this is my controller:
public function pst_affluiti(){
$data=DB::all('Anagrafica')->get();
$pdf = PDF::loadView('output',['data' => $data]);
return $pdf->stream('output.pdf');
}
my output.blade.php
<body>
<div class="container">
<table class="table table-sm table-bordered" >
<thead>
<tr>
<th scope="col-sm-1 col-6">Data Affl.</th>
<th scope="col-sm-2">Cron.</th>
<th scope="col-sm-2">Cognome</th>
<th scope="col-sm-2">Nome</th>
<th scope="col-sm-2">Data nac.</th>
</tr>
</thead>
<tbody>
#foreach($data as $row)
<tr>
<td>{{$row->Cron}}</td>
<td>{{$row->Surname}}</td>
<td>{{$row->Name}}</td>
<td>{{$row->Date}}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</body>
if i load a normal view of my query it works well.
Any suggest?
Thanks in advance
you can use
compact('data')
instead of
$data
I am using Laravel pagination from controller to paginate some list of data in a table. The pagination numbers are only displaying on the bottom of the table. How do i get to display the numbers on the top of the table as well?
my view:
<table>
<thead>
<tr>
<th>Make</th>
<th>Model</th>
</tr>
</thead>
<tbody>
#foreach ($cars as $car)
<tr>
<td>{{$car->make}}</td>
<td>{{$car->model}}</td>
</tr>
#endforeach
</tbody>
</table>
<div class="pull-right">
{{ $cars->links() }}
</div>
If you copy {{ $cars->links() }} at the top, it will also show you the same pagination like button. It looks like the following
<div class="pull-right">
{{ $cars->links() }}
</div>
<table>
<thead>
<tr>
<th>Make</th>
<th>Model</th>
</tr>
</thead>
<tbody>
#foreach ($cars as $car)
<tr>
<td>{{$car->make}}</td>
<td>{{$car->model}}</td>
</tr>
#endforeach
</tbody>
</table>
<div class="pull-right">
{{ $cars->links() }}
</div>
$cars->links() generates pagination button/links.
You can move it to wherever you like:
<div class="pull-right">
{{ $cars->links() }}
</div>
<table>
<thead>
<tr>
<th>Make</th>
<th>Model</th>
</tr>
</thead>
<tbody>
#foreach ($cars as $car)
<tr>
<td>{{$car->make}}</td>
<td>{{$car->model}}</td>
</tr>
#endforeach
</tbody>
</table>
use this on the top as well
<div class="pull-right">
{{ $cars->links() }}
</div>