-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrint.java
64 lines (44 loc) · 1.39 KB
/
Print.java
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
import java.awt.print.*;
import com.spire.pdf.*;
/**
* @author Pablo Rodriguez
* @version 10.12.2020
*/
public class Print
{
/**
* Constructor
*/
public Print()
{
}
public void imprimir (String ruta, InterfazSimple is) throws Exception
{
//Crea instancia del PDF y asigna ruta
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile(ruta);
//Crea trabajo de impresion
PrinterJob printerJob = PrinterJob.getPrinterJob();
PageFormat formatoPagina = printerJob.defaultPage();
Paper papel = formatoPagina.getPaper();
//Remueve los margenes por default y pone orientacion horizontal
//papel.setSize(8.5d, 11d);
papel.setImageableArea(0, 0, formatoPagina.getWidth(), formatoPagina.getHeight());
formatoPagina.setOrientation(PageFormat.LANDSCAPE);
//Cargando papel al formato y asignando el documento a imprimir con el formato dado
formatoPagina.setPaper(papel);
printerJob.setPrintable(pdf, formatoPagina);
//Para desplegar trabajo de impresion
if (printerJob.printDialog())
{
try
{
printerJob.print();
is.imprimiendo();
} catch (PrinterException e)
{
e.printStackTrace();
}
}
}
}