PHP - Archivo pdf con DOMPDF en Horizontal

 
Vista:
Imágen de perfil de francisco
Val: 93
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Archivo pdf con DOMPDF en Horizontal

Publicado por francisco (45 intervenciones) el 28/02/2018 17:56:39
Hola buen dia a todos. Espero poder ayudar y que me ayuden con este tema ya que algunos les pude servir y tambien a mi jajajaj


tengo un archivo PDF generado con la libreria de DOMPDF, y necesito ponerlo horizontal pero no me deja el motico no lo se ya tengo de varias formas que le indacan que lo ponga asi pero no se por que no lo hace tengo implementada las dos versiones de las librerias para que me deja implementar los float ya que en la version antigua no deja pero igual dejo el codigo. haber si alguien me puede ayudar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<?php ob_start();
 
	set_time_limit(0);
	require_once "../dompdf/autoload.inc.php";
	# Cargamos la librería dompdf.
	use Dompdf\Dompdf;
 
	$hostname_fox = "localhost";
	$database_fox = "tabla1";
	$username_fox = "root";
	$password_fox = "";
	$fox =mysqli_connect($hostname_fox, $username_fox, $password_fox, $database_fox);
 
	$id=$_REQUEST['id'];
 
	$query_Recordset="SELECT h40d WHERE h40d.id='$id'";
	$Recordset = mysqli_query($fox, $query_Recordset) or die(mysql_error());
	$r = mysqli_fetch_assoc($Recordset);
	$totalRows_Recordset = mysqli_num_rows($Recordset);
 
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Ejemplo de Documento en PDF.</title>
<style>
html {
		margin: 0;
	}
 
body {
		font-family: "Times New Roman", serif;
		margin: 0mm 4mm 2mm 2mm;
	}
 
	h2{
		text-align: center;
		font-size: 24px;
	}
 
	.cabecera{
		height:160px;
		width: 1000px;
		position: relative;
		left: 20px;
	}
 
	.cabeceraInicial{
		font-size: 10px;
		float: left;
		padding: 0px;
		margin-right: 200px;
		margin-bottom: 5px;
	}
 
	.cabeceraMedia{
		font-size: 10px;
		float: left;
		padding: 5px;
		margin-right: 200px;
		margin-bottom: 5px;
	}
 
	.cabeceraFinal{
		font-size: 10px;
	}
 
	.cuerpo{
	border-collapse: collapse;
	}
 
	.formato{
	 text-align: center;
	 border: 2px solid black;
	 font-size: 10px;
	}
 
	.segundo{
		text-align: center;
	  border: 1px solid black;
	  height: 250px;
	}
 
	#fondo{
		background-color: #ffff99;
	}
 
	.abajo{
		position: relative;
		left: 50px;
		font-size: 12px;
	}
 
	table{
		border-collapse: collapse;
	}
 
 
	td{
		text-align: center;
	  font-size: 12px;
	}
 
	.dimencion{
		background-color: #ffff99;
	}
 
	.pie{
		position: relative;
		left: 50px;
		background-color: #ffff99;
		font-size: 12px;
		width: 350px;
		float: none;
	}
 
 
</style>
</head>
	<body>
 
	<h2>Titulo</h2>
 
	<div class="cabecera">
		<p class="cabeceraInicial"><b>
			Ship From: <br>	Lorem ipsum dolor sit amet, 	Lorem ipsum dolor sit amet, adipisicing<br>		Lorem ipsum dolor sit amet, <br> 	Lorem ipsum dolor sit amet, <br> 	Lorem ipsum dolor sit amet, <br> Mexico <br><br> Sold to: <br> 	Lorem ipsum dolor sit amet, <br> 	Lorem ipsum dolor sit amet, <br> 2025 Gateway Place, <br> Suite 190 <br> 	Lorem ipsum dolor sit amet,
		</b></p>
 
		<p class="cabeceraMedia"><b>
			Waybill Number: <br> 	Lorem ipsum dolor sit amet,: <br> 	Lorem ipsum dolor sit amet,: <br> MOT: <br> From: <br> Shipped to: <br> 	Lorem ipsum dolor sit amet,: <br> Date Shipped:
		</b></p>
 
		<p class="cabeceraFinal"><b>
			Lorem ipsum dolor sit amet, <br><br> Order #: <br> C	Lorem ipsum dolor sit amet, <br><br> U.S. Customs Compliance contact: <br> 	Lorem ipsum dolor sit amet,<br> 	Lorem ipsum dolor sit amet,
		</b></p>
	</div>
 
<table class="cuerpo">
	<thead>
		<tr>
			<td width="50"><b>Lorem ipsum dolor</b></td>
			<td width="50"><b>Lorem ipsum dolor</b></td>
			<td width="50"><b>Lorem ipsum dolor</b></td>
			<td width="50"><b>Lorem ipsum dolor</b</td>
			<td width="120"><b>Lorem ipsum dolor</b></td>
			<td width="30"><b>COO</b></td>
			<td width="30"><b>QTY Ship</b></td>
			<td width="50"><b>Lorem ipsum dolor</b></td>
			<td width="50"><b>Lorem ipsum dolor</b></td>
			<td width="120"><b>Lorem ipsum dolor</b> </td>
		</tr>
</thead>
<tbody>
	<tr>
		<td class="formato" width="50"> <?echo $r["Invoice#"]?></td>
		<td class="formato" width="50"> <?echo $r["Invoice#"]?> </td>
		<td width="100px" class="formato" width="50"> <?echo $r["Invoice#"]?> </td>
		<td class="formato" id="fondo" width="50"> <?echo $r["Invoice#"]?> </td>
		<td class="formato" id="fondo" width="120"> <?echo $r["Invoice#"]?>	</td>
		<td class="formato" id="fondo" width="30"> MX </td>
		<td class="formato" width="30"> 1 </td>
		<td class="formato" width="50">  <?echo $r["Invoice#"]?></td>
		<td class="formato" width="50">  <?echo $r["Invoice#"]?> </td>
		<td class="formato" width="120">  <?echo $r["Invoice#"]?>
	</td>
		</tr>
		<tr>
			<td class="formato"></td>
			<td class="formato"></td>
			<td class="formato"></td>
			<td class="formato" id="fondo"></td>
			<td class="formato" id="fondo"> FREIGHT </td>
			<td class="formato" id="fondo"></td>
			<td class="formato"></td>
			<td class="formato">  243985253 </td>
			<td class="formato"></td>
			<td class="formato"></td>
			</tr>
		<tr class="segundo">
			<td height="220px" class="formato"> </td>
			<td height="220px" class="formato"> </td>
			<td height="220px" class="formato"> </td>
			<td height="220px" class="formato" id="fondo"> </td>
			<td height="220px" class="formato" id="fondo"> </td>
			<td height="220px" class="formato" id="fondo"> </td>
			<td height="220px" class="formato"> </td>
			<td height="220px" class="formato"> </td>
			<td height="220px" class="formato"> </td>
			<td height="220px" class="formato"> </td>
			</tr>
	<tbody>
 
	</table>
 
	<div class="abajo">
		<table>
			<thead>
				<tr>
					<td> <b></b> </td>
					<td width="120px"> <b>Lorem ipsum</b> </td>
					<td width="120px"> <b>Lorem ipsum</b> </td>
					<td width="120px"> <b>Lorem ipsum</b> </td>
					<td width="120px"> <b>Lorem ipsum kg/lb</b> </td>
					<td width="120px"> <b>Lorem ipsum kg/lb</b> </td>
					<td width="120px"> <b>Lorem ipsum</b> </td>
					<td> <b>Total:</b> </td>
					<td> <b>2</b> </td>
					<td> <b>PCS</b> </td>
					<td> <b>Lorem ipsum</b> </td>
				</tr>
			</thead>
			<tbody class="dimencion">
				<tr>
					<td>Case 1:</td>
					<td>160</td>
					<td>160</td>
					<td>160</td>
					<td>1205.6/2652.32</td>
					<td>1205.6/2652.32</td>
					<td>675</td>
					<td colspan="5"></td>
				</tr>
				<tr>
					<td>Case 2:</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td colspan="5">Lorem ipsum</td>
				</tr>
				<tr>
					<td>Case 3:</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td colspan="5">Lorem ipsum</td>
				</tr>
				<tr>
					<td>Case 4:</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td colspan="5">Lorem ipsum</td>
				</tr>
				<tr>
					<td>Total:</td>
					<td></td>
					<td></td>
					<td></td>
					<td>Lorem ipsum</td>
					<td>Lorem ipsum</td>
					<td></td>
					<td colspan="5">Lorem ipsum</td>
				</tr>
			</tbody>
		</table>
	</div>
	<div class="pie">
		<p>
			<b>
				Lorem ipsum <br>
				Lorem ipsum <br>
				Lorem ipsum<br>
				Lorem ipsum <br>
				Lorem ipsum
			</b>
 
		</p>
	</div>
 
	</body>
	</html>
 
	<?php
 
	require_once ('../dompdf/dompdf_config.inc.php');
 
 
 
// Instanciamos un objeto de la clase DOMPDF.
$dompdf = new DOMPDF();
// Cargamos el contenido HTML.
 
$dompdf->load_html(ob_get_clean());
$dompdf->render();
 
// Definimos el tamaño y orientación del papel que queremos.
$dompdf->set_paper('letter', 'landscape'); //esta es una forma de ponerlo horizontal
$dompdf->set_paper("A4", "landscape"); //esta es otra forma de ponerlo horizontal
 
// niguna de las dos formas me funciona espero me puedan ayudar con eso
 
// Renderizamos el documento PDF.
$pdf=$dompdf->output();
$filname= $r["Invoice#"];
 
// Enviamos el fichero PDF al navegador.
$dompdf->stream($filname, array("attachment" => 0));
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de francisco
Val: 93
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Archivo pdf con DOMPDF en Horizontal

Publicado por francisco (45 intervenciones) el 28/02/2018 22:48:14
modifique e inclui algunas cosas al codigo asi que quedo de esta forma

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
 
	require_once 'vendor/dompdf/lib/html5lib/Parser.php';
	require_once 'vendor/dompdf/lib/php-font-lib/src/FontLib/Autoloader.php';
	require_once 'vendor/dompdf/lib/php-svg-lib/src/autoload.php';
	require_once 'vendor/dompdf/src/Autoloader.php';
	Dompdf\Autoloader::register();
	// reference the Dompdf namespace
	use Dompdf\Dompdf;
		$dompdf = new Dompdf();
 
		$hostname_fox = "localhost";
	$database_fox = "tabla1";
	$username_fox = "root";
	$password_fox = "";
	$fox =mysqli_connect($hostname_fox, $username_fox, $password_fox, $database_fox);
 
	$id=$_REQUEST['id'];
 
	$query_Recordset="SELECT h40d WHERE h40d.id='$id'";
	$Recordset = mysqli_query($fox, $query_Recordset) or die(mysql_error());
	$r = mysqli_fetch_assoc($Recordset);
	$totalRows_Recordset = mysqli_num_rows($Recordset);
 
?>
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Ejemplo de Documento en PDF.</title>
<style>
html {
		margin: 0;
	}
 
body {
		font-family: "Times New Roman", serif;
		margin: 0mm 4mm 2mm 2mm;
	}
 
	h2{
		text-align: center;
		font-size: 24px;
	}
 
	.cabecera{
		height:160px;
		width: 1000px;
		position: relative;
		left: 20px;
	}
 
	.cabeceraInicial{
		font-size: 10px;
		float: left;
		padding: 0px;
		margin-right: 200px;
		margin-bottom: 5px;
	}
 
	.cabeceraMedia{
		font-size: 10px;
		float: left;
		padding: 5px;
		margin-right: 200px;
		margin-bottom: 5px;
	}
 
	.cabeceraFinal{
		font-size: 10px;
	}
 
	.cuerpo{
	border-collapse: collapse;
	}
 
	.formato{
	 text-align: center;
	 border: 2px solid black;
	 font-size: 10px;
	}
 
	.segundo{
		text-align: center;
	  border: 1px solid black;
	  height: 250px;
	}
 
	#fondo{
		background-color: #ffff99;
	}
 
	.abajo{
		position: relative;
		left: 50px;
		font-size: 12px;
	}
 
	table{
		border-collapse: collapse;
	}
 
 
	td{
		text-align: center;
	  font-size: 12px;
	}
 
	.dimencion{
		background-color: #ffff99;
	}
 
	.pie{
		position: relative;
		left: 50px;
		background-color: #ffff99;
		font-size: 12px;
		width: 350px;
		float: none;
	}
 
</style>
</head>
<body>
 
<h2>Titulo</h2>
 
<div class="cabecera">
	<p class="cabeceraInicial"><b>
		Ship From: <br>	Lorem ipsum dolor sit amet, 	Lorem ipsum dolor sit amet, adipisicing<br>		Lorem ipsum dolor sit amet, <br> 	Lorem ipsum dolor sit amet, <br> 	Lorem ipsum dolor sit amet, <br> Mexico <br><br> Sold to: <br> 	Lorem ipsum dolor sit amet, <br> 	Lorem ipsum dolor sit amet, <br> 2025 Gateway Place, <br> Suite 190 <br> 	Lorem ipsum dolor sit amet,
	</b></p>
 
	<p class="cabeceraMedia"><b>
		Waybill Number: <br> 	Lorem ipsum dolor sit amet,: <br> 	Lorem ipsum dolor sit amet,: <br> MOT: <br> From: <br> Shipped to: <br> 	Lorem ipsum dolor sit amet,: <br> Date Shipped:
	</b></p>
 
	<p class="cabeceraFinal"><b>
		Lorem ipsum dolor sit amet, <br><br> Order #: <br> C	Lorem ipsum dolor sit amet, <br><br> U.S. Customs Compliance contact: <br> 	Lorem ipsum dolor sit amet,<br> 	Lorem ipsum dolor sit amet,
	</b></p>
</div>
 
<table class="cuerpo">
	<thead>
		<tr>
			<td width="50"><b>Lorem ipsum dolor</b></td>
			<td width="50"><b>Lorem ipsum dolor</b></td>
			<td width="50"><b>Lorem ipsum dolor</b></td>
			<td width="50"><b>Lorem ipsum dolor</b</td>
			<td width="120"><b>Lorem ipsum dolor</b></td>
			<td width="30"><b>COO</b></td>
			<td width="30"><b>QTY Ship</b></td>
			<td width="50"><b>Lorem ipsum dolor</b></td>
			<td width="50"><b>Lorem ipsum dolor</b></td>
			<td width="120"><b>Lorem ipsum dolor</b> </td>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td class="formato" width="50"> <?echo $r["Invoice#"]?></td>
			<td class="formato" width="50"> <?echo $r["Invoice#"]?> </td>
			<td width="100px" class="formato" width="50"> <?echo $r["Invoice#"]?> </td>
			<td class="formato" id="fondo" width="50"> <?echo $r["Invoice#"]?> </td>
			<td class="formato" id="fondo" width="120"> <?echo $r["Invoice#"]?>	</td>
			<td class="formato" id="fondo" width="30"> MX </td>
			<td class="formato" width="30"> 1 </td>
			<td class="formato" width="50">  <?echo $r["Invoice#"]?></td>
			<td class="formato" width="50">  <?echo $r["Invoice#"]?> </td>
			<td class="formato" width="120">  <?echo $r["Invoice#"]?></td>
		</tr>
		<tr>
			<td class="formato"></td>
			<td class="formato"></td>
			<td class="formato"></td>
			<td class="formato" id="fondo"></td>
			<td class="formato" id="fondo"> FREIGHT </td>
			<td class="formato" id="fondo"></td>
			<td class="formato"></td>
			<td class="formato">  243985253 </td>
			<td class="formato"></td>
			<td class="formato"></td>
		</tr>
		<tr class="segundo">
			<td height="220px" class="formato"> </td>
			<td height="220px" class="formato"> </td>
			<td height="220px" class="formato"> </td>
			<td height="220px" class="formato" id="fondo"> </td>
			<td height="220px" class="formato" id="fondo"> </td>
			<td height="220px" class="formato" id="fondo"> </td>
			<td height="220px" class="formato"> </td>
			<td height="220px" class="formato"> </td>
			<td height="220px" class="formato"> </td>
			<td height="220px" class="formato"> </td>
		</tr>
	<tbody>
</table>
 
<div class="abajo">
	<table>
		<thead>
			<tr>
				<td> <b></b> </td>
				<td width="120px"> <b>Lorem ipsum</b> </td>
				<td width="120px"> <b>Lorem ipsum</b> </td>
				<td width="120px"> <b>Lorem ipsum</b> </td>
				<td width="120px"> <b>Lorem ipsum kg/lb</b> </td>
				<td width="120px"> <b>Lorem ipsum kg/lb</b> </td>
				<td width="120px"> <b>Lorem ipsum</b> </td>
				<td> <b>Total:</b> </td>
				<td> <b>2</b> </td>
				<td> <b>PCS</b> </td>
				<td> <b>Lorem ipsum</b> </td>
			</tr>
		</thead>
		<tbody class="dimencion">
			<tr>
				<td>Case 1:</td>
				<td>160</td>
				<td>160</td>
				<td>160</td>
				<td>1205.6/2652.32</td>
				<td>1205.6/2652.32</td>
				<td>675</td>
				<td colspan="5"></td>
			</tr>
			<tr>
				<td>Case 2:</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td colspan="5">Lorem ipsum</td>
			</tr>
			<tr>
				<td>Case 3:</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td colspan="5">Lorem ipsum</td>
			</tr>
			<tr>
				<td>Case 4:</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td colspan="5">Lorem ipsum</td>
			</tr>
			<tr>
				<td>Total:</td>
				<td></td>
				<td></td>
				<td></td>
				<td>Lorem ipsum</td>
				<td>Lorem ipsum</td>
				<td></td>
				<td colspan="5">Lorem ipsum</td>
			</tr>
		</tbody>
	</table>
</div>
<div class="pie">
	<p>
		<b>
			Lorem ipsum <br>
			Lorem ipsum <br>
			Lorem ipsum<br>
			Lorem ipsum <br>
			Lorem ipsum
		</b>
 
	</p>
</div>
 
</body>
</html>
 
 
<?php
ob_start();
// instantiate and use the dompdf class
 
$dompdf->load_html(ob_get_clean());
 
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
 
// Render the HTML as PDF
$dompdf->render();
 
// Output the generated PDF to Browser
$dompdf->stream();
?>



pero ahora me sale este error que no se como poder solucionarlo espero me puedan ayudar con esto

Unable to stream pdf: headers already sent

esto me sale a la hora de hacer la descarga de mi formato pdf
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar