Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java print pdf to printer

import com.spire.pdf.*;
import java.awt.print.*;

public class Print {
    public static void main(String[] args) {
        //load the sample document
        PdfDocument pdf = new PdfDocument();
        pdf.loadFromFile("Sample.pdf");

        PrinterJob loPrinterJob = PrinterJob.getPrinterJob();
        PageFormat loPageFormat  = loPrinterJob.defaultPage();
        Paper loPaper = loPageFormat.getPaper();

        //remove the default printing margins
        loPaper.setImageableArea(0,0,loPageFormat.getWidth(),loPageFormat.getHeight());

        //set the number of copies
        loPrinterJob.setCopies(2);

        loPageFormat.setPaper(loPaper);
        loPrinterJob.setPrintable(pdf,loPageFormat);
        try {
            loPrinterJob.print();
        } catch (PrinterException e) {
            e.printStackTrace();
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: integer.tostring java 
Java :: from date to string 
Java :: java hash password 
Java :: java stream get all max values 
Java :: how to check base64 in java 
Java :: max and min value in array 
Java :: check if list includes value java 
Java :: initialize applet in java 
Java :: creating a directory using java 
Java :: can interface have attributes java 
Java :: java.lang.string cannot be cast to java.lang.double react native 
Java :: setbackground java 
Java :: how generate a random number in java between 3 and 5 
Java :: how to operate on values from different classes in java 
Java :: random int in range java 
Java :: java checking the amount of duplicates in array 
Java :: java final meaning 
Java :: retrofit post header 
Java :: java suppresswarnings unchecked 
Java :: Caused by: java.lang.ClassNotFoundException 
Java :: convert a int to string in java 
Java :: java write to file 
Java :: how to remove all characters before a certain character from a string in java 
Java :: add element in the last in double linked list in java 
Java :: how to multiply bigdecimals 
Java :: how to use split on a file name java 
Java :: android setTextColor not working 
Java :: java program to Check given String is contians number or not 
Java :: how to convert arraylist to iterable in java 
Java :: do statement java 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =