Skip to main content

Posts

Showing posts from September, 2019

Merge PDF Files in Java

In this article, I will introduce two methods to merge PDF files in Java application. 1. Merge PDF files into a single file 2. Merge a specific page or a page range of a PDF file into another PDF file The below examples use Free Spire.PDF for Java library. Imported NameSpace: import com.spire.pdf.PdfDocument; import com.spire.pdf.PdfDocumentBase; Merge PDF files into a single file String[] files = new String[] { "file1.pdf" , "file2.pdf" }; //load PDF files PdfDocumentBase pdf = PdfDocument. mergeFiles (files); //merge into a single file pdf.save( "MergeFiles.pdf" );   Merge a specific page or a page range of a PDF file into another PDF file String[] files = new String[]         {                 "file1.pdf" ,                 "file2.pdf" ,         }; //create a PdfDocument[] PdfDocument[] pdfs = new PdfDocument[files. length ]; PdfDocument pdf = new PdfDocument(); for ( int i = 0 ; i &

Print Word Document in Java

Printing Word document is one of the most common requirements in our daily work. In this article, I will introduce how to print a Word document to a physic printer and a virtual printer. The required library: Free Spire.Doc for Java Print a Word document to a physic printer import com.spire.doc.Document; import com.spire.ms.System.Drawing.Printing.PrinterSettings; public class PrintWord {     public static void main(String[] args) {         //load a Word document that you want to print         Document document = new Document();         document.loadFromFile("C:\\Users\\Administrator\\Desktop\\DocoumentToPrint.docx");         //create a PrinterSettings object         PrinterSettings printerSettings = new PrinterSettings();          //specify printer name         printerSettings.setPrinterName("\\\\192.168.1.104\\HP LaserJet P1007");         //set copies to print         printerSettings.setCopies((short) 1);