import java.io.*;
import java.text.*;
import java.util.*;
/** A simple text test of SPDF package
*/
public class PDFDemo {
public static void main(String[] argv) throws IOException {
PrintWriter pout;
if (argv.length == 0) {
pout = new PrintWriter(System.out);
} else {
if (new File(argv[0]).exists()) {
throw new IOException(
"Output file " + argv[0] + " already exists");
}
pout = new PrintWriter(new FileWriter(argv[0]));
}
PDF p = new PDF(pout);
Page p1 = new Page(p);
p1.add(new MoveTo(p, 100, 600));
p1.add(new Text(p, "Hello world, live on the web."));
p1.add(new Text(p, "Hello world, line 2 on the web."));
p.add(p1);
p.setAuthor("Ian F. Darwin");
p.writePDF();
}
}
/** The main class for the Darwin Open Systems
* {Simple,Stupid,Simplistic} PDF API.
* PDF is Adobe's Portable Document Format, and is probably a trademark
* of Adobe Systems Inc, Mountain View, California.
* The Adobe PDF Specification which they publish grants everyone
* permission to write code to generate and/or process PDF files.
* A PDF Object represents one PDF file.
* @author Ian F. Darwin, http://www.darwinsys.com/
* @version $Id: PDF.java,v 1.6 2004/02/09 03:34:02 ian Exp $
*/
class PDF {
/** The output writer */
protected PrintWriter out;
/** The list of pages */
protected ArrayList pages;
/** The list of object xrefs */
protected ArrayList xrefs;
/** The root object */
PDFObject rootObj = new RootObject(this);
/** The Info object */
InfoObject infoObj = new InfoObject(this);
/** The outlines (outline font) object */
OutlinesObject outlinesObj = new OutlinesObject(this);
/** The Pages object */
PagesObject pagesObj = new PagesObject(this);
/** The Font Dictionary */
FontDict fontDict = new FontDict(this);
/** The object number of the current object */
protected int currObj = 1;
/** A flag to avoid writing twice */
protected boolean startedWriting = false;
/** A magic number that identifies the output as a PDF file */
protected final static String PDF_MAGIC = "%PDF-1.0";
/** Constructor */
public PDF(PrintWriter o) {
out = o;
pages = new ArrayList();
xrefs = new ArrayList();
}
public void add(Page p) {
pages.add(p);
}
public void insertPage(int where, Page p) {
pages.add(where, p);
}
// OUTPUT METHODS -- we provide our own print/println, so we
// can keep track of file offsets (it was either that, or kludgily
// use a RandomAccessFile and the getFilePointer() method).
long offset = 0;
/** Print a String */
Java 打印到PDF文件
最新推荐文章于 2024-04-23 18:52:22 发布