package com.plexq.pdf.writer; import com.plexq.pdf.*; import java.io.*; import java.util.*; public class PDFWriter extends FileOutputStream { protected int bytesWritten=0; public PDFWriter(String fileName) throws IOException { super(fileName); } public void write(PDF p) throws IOException { write("%PDF-1.4\n"); write("%âãÏÓ"); Iterator it=p.getXRef().keySet().iterator(); PDFXRef xref=new PDFXRef(); int mark; int maxObject=0; while (it.hasNext()) { maxObject++; PDFInteger i=it.next(); PDFObject o=p.getXRef().getObject(i); mark=getBytesWritten(); xref.putEntry(new PDFInteger(mark),new PDFInteger(maxObject),new PDFInteger(0)); write(""+maxObject); write(" "); write("0 obj "); write(o); } mark=getBytesWritten(); write(xref); PDFTrailer trailer=p.getTrailer(); trailer.put(new PDFName("Size"),new PDFInteger(maxObject+1)); trailer.remove(new PDFName("Prev")); write(trailer); write("startxref\n"); write(""+mark); write("\n%%EOF\n"); } public void write(PDFArray a) throws IOException { write("["); for (int t=0;t it=d.keySet().iterator(); write("<<\n"); while (it.hasNext()) { write("\t"); PDFName n=it.next(); PDFObject o=d.get(n); write(n); write(" "); write(o); write("\n"); } write(">>\n"); } public void write(PDFHexString phs) throws IOException { StringBuffer sb=new StringBuffer(); String value=phs.getValue(); sb.append("<"); for (int t=0;t"); write(sb.toString()); } public void write(PDFIndirectReference pir) throws IOException { StringBuffer sb=new StringBuffer(); sb.append(pir.getRefId()); sb.append(" "); sb.append(pir.getRefGeneration()); sb.append(" "); sb.append("R"); write(sb.toString()); } public void write(PDFInteger i) throws IOException { write(""+i.getValue()); } public void write(PDFName n) throws IOException { write("/"+n.getName()); } public void write(PDFReal r) throws IOException { write(""+r.getValue()); } public void write(PDFString ps) throws IOException { StringBuffer sb=new StringBuffer(); sb.append("("); sb.append(ps.getValue()); sb.append(")"); write(sb.toString()); } public void write(PDFTrailer t) throws IOException { write("trailer\n"); writeDictionary(t); } public void write(PDFObject o){ throw new RuntimeException("Can't call write with a bare object"); } public void write(PDFStream s) throws IOException { write("stream\n"); write(s.getData()); write("\nendstream"); } public void write(String s) throws IOException { write(s.getBytes()); } public void write(byte[] b) throws IOException { for (int t=0;t