Как преобразовать код html в изображение, а затем загрузить его в формате JPEG с помощью codeigniter - PullRequest
0 голосов
/ 27 апреля 2020

<div id="content" class="content">
	<!-- begin profile-container -->
	<div class="profile-container">
		<!-- begin profile-section -->
		<div class="profile-section">
			<div class="col-md-3">
				<div class="profile-left" style="margin-top: -50px;">
					<div class="profile-image" id="croppic">
						<?
							if(QR_CODE == 1)
							$content =  $ast_status_lead;
							else
							$content = "In this plan you don't have permission to access this QR code. Please upgrade your plan.";
						?>
						<a href="javascript:void(0);" data-toggle="tooltip" data-title="Scan to make a quick note">  
							<img src="https://chart.googleapis.com/chart?cht=qr&chl=<?=$content?>&chs=140x140&chld=L|0" 
							class="qr-code img-thumbnail img-responsive">
						</a>
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<!-- begin profile-left -->
				<div class="profile-left" style="width:100%">
					<!-- begin profile-info -->
					<div class="profile-info">
						<!-- begin table -->
						<div class="row">
							<!-- begin col-4 -->		
							<div class="table-responsive">
								<?
									if(count($astdetails)>0)
									{
										foreach($astdetails as $rows)
										{ ?>
											<table class="table table-profile">
												<thead>
													<tr>
														<th colspan="3">
															<h4><?=$rows['title']?></h4>
														</th>
														<th>
															<span class="pull-right hidden-print">			
																<a href="<?php echo base_url(); ?>index.php/asset/asset_export_pdf/<?=$rows['id']?>" class="btn btn-xs btn-info m-b-10">
																	<i class="fa fa-file-pdf-o m-r-5"></i> Export as PDF
																</a>
																<a href="javascript:;" class="btn btn-xs btn-warning m-b-10">
																	<i class="fa fa-download m-r-5"></i> Download
																</a>
															</span>
														</th>
													</tr>
												</thead>
												<tbody>
													<tr>
														<td class="field" width="25%">Title</td>
														<td width="75%">
															<?=$rows['title']?>
														</td>
													</tr>
													<tr>
														<td class="field" width="25%">Description</td>
														<td width="75%">
															<?=$rows['description']?>
														</td>
													</tr>
													<tr>
														<td class="field" width="25%">Serial No</td>
														<td width="75%">
															<?=$rows['serial_number']?>
														</td>
													</tr>
													<tr>
														<td class="field" width="25%">Status</td>
														<td width="75%">
															<?php
																foreach($status_options as $status_id => $status)
																{
																	if($status_id == $rows['asset_status'])
																	{
																		echo $status;
																	}
																}
															?>
														</td>
													</tr>
													<tr>
														<td class="field" width="25%">Category</td>
														<td width="75%">
															<?php
																foreach($category as $category_id => $category_name)
																{
																	if($category_id == $rows['category_id'])
																	{
																		echo $category_name;
																	}
																}
															?>
														</td>
													</tr>
													<tr>
														<td class="field" width="25%">Created Date</td>
														<td width="75%">
															<?=date('d-m-Y g:i A',$rows['created_date'])?>
														</td>
													</tr>
													<tr>
														<td class="field" width="25%">Created By</td>
														<td width="75%">
															<?
																foreach($rep_options as $rep_id=>$rep_name){
																	if($rep_id == $rows['created_by']){
																		echo $rep_name;
																	}
																}
															?>
														</td>
													</tr>
													<tr>
														<td class="field" width="25%">Owner</td>
														<td width="75%">
														<?
															if($rows['owner'] == 0)
															{
																echo "N/A";
															}
															else
															{
																foreach($rep_options as $rep_id=>$rep_name)
																{
																	if($rep_id == $rows['owner'])
																	{
																		echo $rep_name;
																	}
																}
															}
														?>
														</td>
													</tr>
												</tbody>
											</table>
										<? }
									}
								?>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="col-md-2">
			</div>
		</div>
	</div>
</div>

````

````

<html>
<title></title>
<body>
	<div id="content" class="content">	
		<table class="table">
			<tr>
				<td align="left">
					<span class="">
						<img src="<?=base_url()?>images/lotus.png">
					</span>
				</td>
				<td align="right">
					<span class="">														 
					</span>
				</td>
			</tr>
			
			<tr>
				<td width="60%;">
					<table class="table">
						<thead>
							<tr>
								<th colspan="2" style="text-align:center;">
									<span class="text-center">
										<h4 class="text-primary"><?=$astdetails[0]['title']?></h4>
									</span>
								</th>
								<th></th>
							</tr>
						</thead>
						<tbody>
							<!-- <tr class="highlight">
								<td class="field" >Company</td>
								<td><?=$astdetails[0]['title']?></td>
							</tr> -->
							<tr>
								<td class="field">Title: </td>
								<td>
									<?=$astdetails[0]['title']?>
								</td>
							</tr>
							
							<tr>
								<td class="field">Description: </td>
								<td>
									<?=$astdetails[0]['description']?>
								</td>
							</tr>
							
							<tr>
								<td class="field">Serial No: </td>
								<td>
									<?=$astdetails[0]['serial_number']?>
								</td>
							</tr>
							
							<tr>
								<td class="field" >Status: </td>
								<td>
									<?php
										foreach($status_options as $status_id => $status)
										{
											if($status_id == $astdetails[0]['asset_status'])
											{
												echo $status;
											}
										}
									?>										
								</td>
							</tr>
							
							<tr>
								<td class="field">Category: </td>
								<td>
									<?php
										foreach($category as $category_id => $category_name)
										{
											if($category_id == $astdetails[0]['category_id'])
											{
												echo $category_name;
											}
										}
									?>						
								</td>
							</tr>
							
							<tr>
								<td class="field">Created Date: </td>
								<td>
									<?=date('d-m-Y g:i A',$astdetails[0]['created_date'])?>													
								</td>
							</tr>	
							
							<tr>
								<td class="field">Created By: </td>
								<td>
									<?
										foreach($rep_options as $rep_id=>$rep_name){
											if($rep_id == $astdetails[0]['created_by']){
												echo $rep_name;
											}
										}
									?>									
								</td>
							</tr>
							
							<tr>
								<td class="field">Owner: </td>
								<td>
									<?
										if($astdetails[0]['owner'] == 0)
										{
											echo "N/A";
										}
										else
										{
											foreach($rep_options as $rep_id=>$rep_name)
											{
												if($rep_id == $astdetails[0]['owner'])
												{
													echo $rep_name;
												}
											}
										}
									?>								
								</td>
							</tr>													
						</tbody>
					</table>
				</td>
				<td>
					<!-- <div class="table-image">
					</div>
					<div class="table-highlight">
					</div> -->
				</td>
			</tr>
		</table>			
		<!-- begin profile-container -->
	</div>	
</body>
<head>
	<style>
		.table{
			width:100%;
			max-width:100%;
			margin-bottom:20px;			
		}
		.table>tbody>tr>td,
		.table>tr>th,
		.table>tfoot>tr>td,
		.table>tfoot>tr>th,
		.table>thead>tr>td,
		.table>thead>tr>th
		{border-color:#e2e7eb;padding:0px 15px}
		.table>tbody>tr.divider>td
		{
			padding:0!important;
			height:10px; 
			border-top:1px solid #e2e7eb;
		}
		
		
		
		.table-borderd>tbody>tr>td,
		.table-borderd>tbody>tr>th,
		.table-borderd>tfoot>tr>td,
		.table-borderd>tfoot>tr>th,
		.table-borderd>thead>tr>td,
		.table-borderd>thead>tr>th{
			padding:8px;
			line-height:1.42857143;
			vertical-align:top;
			border-top:1px solid #ddd
		}		
		.no-border	{ 
			padding:8px !important;
			border-top:none !important;
			line-height:2 !important; 
		}
		.table-image{
			height:175px;
			line-height:175px;
			text-align:center;
			font-size:72px;
			margin-bottom:10px;
			/*border:1px solid #E2E7EB;*/
			overflow:hidden;
			-webkit-border-radius:4px;
			-moz-border-radius:4px;
			border-radius:4px;
			width: fit-content;
			width: intrinsic;           /* Safari/WebKit uses a non-standard name */
			width: -moz-max-content;    /* Firefox/Gecko */
			width: -webkit-max-content; /* Chrome */
		}
		.field {
			padding:10px 15px !important;				
		}
		.table-image img{display:block;max-width:100%}
		.text-primary{color:#348fe2!important}
		.text-warning{color:#f59c1a!important}
		.text-success{color:#00acac!important}
		.text-danger{color:#ff5b57!important}
		.text-white{color:#fff!important}
	</style>
</head>
</html>

 ````

````
public function asset_export_pdf($astdt_id)
	{
		$data['rep_options']=array_column($this->data['rep_logo'],'f_name','id' );
		$data['status_options']=$this->data['status_options'];
		$data['category']= $this->data['category'];
		
		$status_options = $data['status_options'];	
		foreach ($status_options as $status_id => $status_display)
		{
			if($status_id !='')
			{
				$data['rows'][$status_display] = $this->asset_model->data_astvsstatus_qr_scan($astdt_id,$status_id);				
				$ast_total = $ast_total + $data['rows'][$status_display];
			}
		}
		$data['rows']['Total'] = $ast_total;
		
		foreach($data['rows'] as $key=> $value)
		{
		   $final_val[] = $key."-".$value;
		}
		
		
		$data['ast_status_lead'] = implode('%0A%0A',$final_val);
		
		$data['astdetails']=$this->asset_model->view_assedetails($astdt_id);
		$this->load->library('pdf');
		$this->pdf->load_view('asset/astHistory_pdf',$data);
		$this->pdf->render();
		$file=$this->pdf->stream("asset_details.pdf");
	}
  
  ````

Здесь я написал код для преобразования HTML в формат PDF при нажатии кнопки «Экспорт в формат PDF», так же, как я хочу преобразовать HTML в изображение JPEG, когда я нажимаю на ссылку для скачивания, «Экспорт в формат PDF» работает нормально, но я не знаю, как преобразовать html в формат JPEG. Кто-нибудь может мне помочь?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...