After a bunch of data, finally from the 2on1 This example of revelation, according to this transformation method.
Import Java.io.File;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import com.lowagie.text.Document;
Import com.lowagie.text.DocumentException;
Import Com.lowagie.text.Rectangle;
Import Com.lowagie.text.pdf.PdfImportedPage;
Import Com.lowagie.text.pdf.PdfReader;
Import Com.lowagie.text.pdf.PdfWriter;
public class Pdfutil {
public static Pdfimportedpage GetPage (String file_name,int i) {
try {
File out = new file ("2on1.pdf"); Create a temporary file for output
FileOutputStream outfile = new FileOutputStream (out);
Pdfreader reader = new Pdfreader (file_name); Create reader
Rectangle psize = reader.getpagesize (1);
Float width = psize.height ();
float height = psize.width ();
//Step 1:creation of a document-object
document document = new Document (New R Ectangle (width, height)); The size of the created file, previously caused by the absence of document creation, is often reported nullpoint
pdfwriter writer = pdfwriter.getinstance (document, outfile);
document.open ();
pdfimportedpage Page1 = writer.getimportedpage (reader, i);
writer.freereader (reader);
reader = null;
writer = null;
outfile.close ();
return Page1;
} catch (IOException e) {
//TODO auto-generated catch block
E.printstacktrace ();
} catch (Documentexception e) {
//TODO auto-generated catch block
e.printstacktrace ();
}
return null;
}
}