| Method from com.lowagie.text.pdf.PdfWriter Detail: |
PdfIndirectReference add(PdfImage pdfImage) throws PdfException {
if (! imageDictionary.contains(pdfImage.name())) {
checkPDFXConformance(this, PDFXKEY_IMAGE, pdfImage);
PdfIndirectObject object;
try {
object = addToBody(pdfImage);
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
imageDictionary.put(pdfImage.name(), object.getIndirectReference());
return object.getIndirectReference();
}
return (PdfIndirectReference) imageDictionary.get(pdfImage.name());
}
Writes a PdfImage to the outputstream. |
protected PdfIndirectReference add(PdfICCBased icc) throws PdfException {
PdfIndirectObject object;
try {
object = addToBody(icc);
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
return object.getIndirectReference();
}
|
PdfIndirectReference add(PdfPage page,
PdfContents contents) throws PdfException {
if (!open) {
throw new PdfException("The document isn't open.");
}
PdfIndirectObject object;
try {
object = addToBody(contents);
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
page.add(object.getIndirectReference());
if (group != null) {
page.put(PdfName.GROUP, group);
group = null;
}
root.addPage(page);
currentPageNumber++;
return null;
}
|
public void addAnnotation(PdfAnnotation annot) {
pdf.addAnnotation(annot);
}
Adds a PdfAnnotation or a PdfFormField
to the document. Only the top parent of a PdfFormField
needs to be added. |
void addAnnotation(PdfAnnotation annot,
int page) {
addAnnotation(annot);
}
|
public void addCalculationOrder(PdfFormField annot) {
pdf.addCalculationOrder(annot);
}
Adds the PdfAnnotation to the calculation order
array. |
PdfName addDirectImageSimple(Image image) throws PdfException, DocumentException {
PdfName name;
// if the images is already added, just retrieve the name
if (images.containsKey(image.getMySerialId())) {
name = (PdfName) images.get(image.getMySerialId());
}
// if it's a new image, add it to the document
else {
if (image.isImgTemplate()) {
name = new PdfName("img" + images.size());
if (image.templateData() == null) {
if(image instanceof ImgWMF){
try {
ImgWMF wmf = (ImgWMF)image;
wmf.readWMF(getDirectContent().createTemplate(0, 0));
}
catch (Exception e) {
throw new DocumentException(e);
}
}else{
try {
((ImgPostscript)image).readPostscript(getDirectContent().createTemplate(0, 0));
}
catch (Exception e) {
throw new DocumentException(e);
}
}
}
}
else {
Image maskImage = image.getImageMask();
PdfIndirectReference maskRef = null;
if (maskImage != null) {
PdfName mname = (PdfName)images.get(maskImage.getMySerialId());
maskRef = getImageReference(mname);
}
PdfImage i = new PdfImage(image, "img" + images.size(), maskRef);
if (image.hasICCProfile()) {
PdfICCBased icc = new PdfICCBased(image.getICCProfile());
PdfIndirectReference iccRef = add(icc);
PdfArray iccArray = new PdfArray();
iccArray.add(PdfName.ICCBASED);
iccArray.add(iccRef);
PdfObject colorspace = i.get(PdfName.COLORSPACE);
if (colorspace != null && colorspace.isArray()) {
ArrayList ar = ((PdfArray)colorspace).getArrayList();
if (ar.size() > 1 && PdfName.INDEXED.equals(ar.get(0)))
ar.set(1, iccArray);
else
i.put(PdfName.COLORSPACE, iccArray);
}
else
i.put(PdfName.COLORSPACE, iccArray);
}
add(i);
name = i.name();
}
images.put(image.getMySerialId(), name);
}
return name;
}
Adds an image to the document but not to the page resources. It is used with
templates and Document.add(Image). |
PdfName addDirectTemplateSimple(PdfTemplate template,
PdfName forcedName) {
PdfIndirectReference ref = template.getIndirectReference();
Object obj[] = (Object[])formXObjects.get(ref);
PdfName name = null;
try {
if (obj == null) {
if (forcedName == null) {
name = new PdfName("Xf" + formXObjectsCounter);
++formXObjectsCounter;
}
else
name = forcedName;
if (template.getType() == PdfTemplate.TYPE_IMPORTED)
template = null;
formXObjects.put(ref, new Object[]{name, template});
}
else
name = (PdfName)obj[0];
}
catch (Exception e) {
throw new ExceptionConverter(e);
}
return name;
}
Adds a template to the document but not to the page resources. |
public void addJavaScript(PdfAction js) {
pdf.addJavaScript(js);
}
Adds a JavaScript action at the document level. When the document
opens all this JavaScript runs. |
public void addJavaScript(String code) {
addJavaScript(code, false);
}
Adds a JavaScript action at the document level. When the document
opens all this JavaScript runs. |
public void addJavaScript(String code,
boolean unicode) {
addJavaScript(PdfAction.javaScript(code, this, unicode));
}
Adds a JavaScript action at the document level. When the document
opens all this JavaScript runs. |
void addLocalDestinations(TreeMap dest) throws IOException {
for (Iterator i = dest.keySet().iterator(); i.hasNext();) {
String name = (String)i.next();
Object obj[] = (Object[])dest.get(name);
PdfDestination destination = (PdfDestination)obj[2];
if (destination == null)
throw new RuntimeException("The name '" + name + "' has no local destination.");
if (obj[1] == null)
obj[1] = getPdfIndirectReference();
PdfIndirectObject iob = addToBody(destination, (PdfIndirectReference)obj[1]);
}
}
Adds the local destinations to the body of the document. |
public void addOCGRadioGroup(ArrayList group) {
PdfArray ar = new PdfArray();
for (int k = 0; k < group.size(); ++k) {
PdfLayer layer = (PdfLayer)group.get(k);
if (layer.getTitle() == null)
ar.add(layer.getRef());
}
if (ar.size() == 0)
return;
OCGRadioGroup.add(ar);
}
Sets a collection of optional content groups whose states are intended to follow
a "radio button" paradigm. That is, the state of at most one optional
content group in the array should be ON at a time: if one group is turned
ON, all others must be turned OFF. |
protected void addSharedObjectsToBody() throws IOException {
// add the fonts
for (Iterator it = documentFonts.values().iterator(); it.hasNext();) {
FontDetails details = (FontDetails)it.next();
details.writeFont(this);
}
// add the form XObjects
for (Iterator it = formXObjects.values().iterator(); it.hasNext();) {
Object objs[] = (Object[])it.next();
PdfTemplate template = (PdfTemplate)objs[1];
if (template != null && template.getIndirectReference() instanceof PRIndirectReference)
continue;
if (template != null && template.getType() == PdfTemplate.TYPE_TEMPLATE) {
PdfIndirectObject obj = addToBody(template.getFormXObject(), template.getIndirectReference());
}
}
// add all the dependencies in the imported pages
for (Iterator it = importedPages.values().iterator(); it.hasNext();) {
currentPdfReaderInstance = (PdfReaderInstance)it.next();
currentPdfReaderInstance.writeAllPages();
}
currentPdfReaderInstance = null;
// add the color
for (Iterator it = documentColors.values().iterator(); it.hasNext();) {
ColorDetails color = (ColorDetails)it.next();
PdfIndirectObject cobj = addToBody(color.getSpotColor(this), color.getIndirectReference());
}
// add the pattern
for (Iterator it = documentPatterns.keySet().iterator(); it.hasNext();) {
PdfPatternPainter pat = (PdfPatternPainter)it.next();
PdfIndirectObject pobj = addToBody(pat.getPattern(), pat.getIndirectReference());
}
// add the shading patterns
for (Iterator it = documentShadingPatterns.keySet().iterator(); it.hasNext();) {
PdfShadingPattern shadingPattern = (PdfShadingPattern)it.next();
shadingPattern.addToBody();
}
// add the shadings
for (Iterator it = documentShadings.keySet().iterator(); it.hasNext();) {
PdfShading shading = (PdfShading)it.next();
shading.addToBody();
}
// add the extgstate
for (Iterator it = documentExtGState.keySet().iterator(); it.hasNext();) {
PdfDictionary gstate = (PdfDictionary)it.next();
PdfObject obj[] = (PdfObject[])documentExtGState.get(gstate);
addToBody(gstate, (PdfIndirectReference)obj[1]);
}
// add the layers
for (Iterator it = documentLayers.keySet().iterator(); it.hasNext();) {
PdfOCG layer = (PdfOCG)it.next();
if (layer instanceof PdfLayerMembership)
addToBody(layer.getPdfObject(), layer.getRef());
}
for (Iterator it = documentOCG.iterator(); it.hasNext();) {
PdfOCG layer = (PdfOCG)it.next();
addToBody(layer.getPdfObject(), layer.getRef());
}
}
|
FontDetails addSimple(BaseFont bf) {
if (bf.getFontType() == BaseFont.FONT_TYPE_DOCUMENT) {
return new FontDetails(new PdfName("F" + (fontNumber++)), ((DocumentFont)bf).getIndirectReference(), bf);
}
FontDetails ret = (FontDetails)documentFonts.get(bf);
if (ret == null) {
checkPDFXConformance(this, PDFXKEY_FONT, bf);
ret = new FontDetails(new PdfName("F" + (fontNumber++)), body.getPdfIndirectReference(), bf);
documentFonts.put(bf, ret);
}
return ret;
}
Adds a BaseFont to the document but not to the page resources.
It is used for templates. |
ColorDetails addSimple(PdfSpotColor spc) {
ColorDetails ret = (ColorDetails)documentColors.get(spc);
if (ret == null) {
ret = new ColorDetails(new PdfName("CS" + (colorNumber++)), body.getPdfIndirectReference(), spc);
documentColors.put(spc, ret);
}
return ret;
}
Adds a SpotColor to the document but not to the page resources. |
PdfObject[] addSimpleExtGState(PdfDictionary gstate) {
if (!documentExtGState.containsKey(gstate)) {
checkPDFXConformance(this, PDFXKEY_GSTATE, gstate);
documentExtGState.put(gstate, new PdfObject[]{new PdfName("GS" + (documentExtGState.size() + 1)), getPdfIndirectReference()});
}
return (PdfObject[])documentExtGState.get(gstate);
}
|
PdfName addSimpleLayer(PdfOCG layer) {
if (!documentLayers.containsKey(layer)) {
checkPDFXConformance(this, PDFXKEY_LAYER, null);
documentLayers.put(layer, new PdfName("OC" + (documentLayers.size() + 1)));
}
return (PdfName)documentLayers.get(layer);
}
|
PdfName addSimplePattern(PdfPatternPainter painter) {
PdfName name = (PdfName)documentPatterns.get(painter);
try {
if ( name == null ) {
name = new PdfName("P" + patternNumber);
++patternNumber;
documentPatterns.put(painter, name);
}
} catch (Exception e) {
throw new ExceptionConverter(e);
}
return name;
}
|
ColorDetails addSimplePatternColorspace(Color color) {
int type = ExtendedColor.getType(color);
if (type == ExtendedColor.TYPE_PATTERN || type == ExtendedColor.TYPE_SHADING)
throw new RuntimeException("An uncolored tile pattern can not have another pattern or shading as color.");
try {
switch (type) {
case ExtendedColor.TYPE_RGB:
if (patternColorspaceRGB == null) {
patternColorspaceRGB = new ColorDetails(new PdfName("CS" + (colorNumber++)), body.getPdfIndirectReference(), null);
PdfArray array = new PdfArray(PdfName.PATTERN);
array.add(PdfName.DEVICERGB);
PdfIndirectObject cobj = addToBody(array, patternColorspaceRGB.getIndirectReference());
}
return patternColorspaceRGB;
case ExtendedColor.TYPE_CMYK:
if (patternColorspaceCMYK == null) {
patternColorspaceCMYK = new ColorDetails(new PdfName("CS" + (colorNumber++)), body.getPdfIndirectReference(), null);
PdfArray array = new PdfArray(PdfName.PATTERN);
array.add(PdfName.DEVICECMYK);
PdfIndirectObject cobj = addToBody(array, patternColorspaceCMYK.getIndirectReference());
}
return patternColorspaceCMYK;
case ExtendedColor.TYPE_GRAY:
if (patternColorspaceGRAY == null) {
patternColorspaceGRAY = new ColorDetails(new PdfName("CS" + (colorNumber++)), body.getPdfIndirectReference(), null);
PdfArray array = new PdfArray(PdfName.PATTERN);
array.add(PdfName.DEVICEGRAY);
PdfIndirectObject cobj = addToBody(array, patternColorspaceGRAY.getIndirectReference());
}
return patternColorspaceGRAY;
case ExtendedColor.TYPE_SEPARATION: {
ColorDetails details = addSimple(((SpotColor)color).getPdfSpotColor());
ColorDetails patternDetails = (ColorDetails)documentSpotPatterns.get(details);
if (patternDetails == null) {
patternDetails = new ColorDetails(new PdfName("CS" + (colorNumber++)), body.getPdfIndirectReference(), null);
PdfArray array = new PdfArray(PdfName.PATTERN);
array.add(details.getIndirectReference());
PdfIndirectObject cobj = addToBody(array, patternDetails.getIndirectReference());
documentSpotPatterns.put(details, patternDetails);
}
return patternDetails;
}
default:
throw new RuntimeException("Invalid color type in PdfWriter.addSimplePatternColorspace().");
}
}
catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
|
void addSimpleShading(PdfShading shading) {
if (!documentShadings.containsKey(shading)) {
documentShadings.put(shading, null);
shading.setName(documentShadings.size());
}
}
|
void addSimpleShadingPattern(PdfShadingPattern shading) {
if (!documentShadingPatterns.containsKey(shading)) {
shading.setName(patternNumber);
++patternNumber;
documentShadingPatterns.put(shading, null);
addSimpleShading(shading.getShading());
}
}
|
public PdfIndirectObject addToBody(PdfObject object) throws IOException {
PdfIndirectObject iobj = body.add(object);
return iobj;
}
Adds an object to the PDF body. |
public PdfIndirectObject addToBody(PdfObject object,
boolean inObjStm) throws IOException {
PdfIndirectObject iobj = body.add(object, inObjStm);
return iobj;
}
Adds an object to the PDF body. |
public PdfIndirectObject addToBody(PdfObject object,
PdfIndirectReference ref) throws IOException {
PdfIndirectObject iobj = body.add(object, ref);
return iobj;
}
Adds an object to the PDF body. |
public PdfIndirectObject addToBody(PdfObject object,
int refNumber) throws IOException {
PdfIndirectObject iobj = body.add(object, refNumber);
return iobj;
}
Adds an object to the PDF body. |
public PdfIndirectObject addToBody(PdfObject object,
PdfIndirectReference ref,
boolean inObjStm) throws IOException {
PdfIndirectObject iobj = body.add(object, ref, inObjStm);
return iobj;
}
Adds an object to the PDF body. |
public PdfIndirectObject addToBody(PdfObject object,
int refNumber,
boolean inObjStm) throws IOException {
PdfIndirectObject iobj = body.add(object, refNumber, inObjStm);
return iobj;
}
Adds an object to the PDF body. |
public boolean breakTableIfDoesntFit(PdfTable table) throws DocumentException {
return pdf.breakTableIfDoesntFit(table);
}
Row additions to the original Table used to build the PdfTable are processed and pre-rendered,
and then the contents are deleted.
If the pre-rendered table doesn't fit, then it is fully rendered and its data discarded.
There shouldn't be any column change in the underlying Table object.
(Contributed by dperezcar@fcc.es) |
static void checkPDFXConformance(PdfWriter writer,
int key,
Object obj1) {
if (writer == null || writer.pdfxConformance == PDFXNONE)
return;
int conf = writer.pdfxConformance;
switch (key) {
case PDFXKEY_COLOR:
switch (conf) {
case PDFX1A2001:
if (obj1 instanceof ExtendedColor) {
ExtendedColor ec = (ExtendedColor)obj1;
switch (ec.getType()) {
case ExtendedColor.TYPE_CMYK:
case ExtendedColor.TYPE_GRAY:
return;
case ExtendedColor.TYPE_RGB:
throw new PdfXConformanceException("Colorspace RGB is not allowed.");
case ExtendedColor.TYPE_SEPARATION:
SpotColor sc = (SpotColor)ec;
checkPDFXConformance(writer, PDFXKEY_COLOR, sc.getPdfSpotColor().getAlternativeCS());
break;
case ExtendedColor.TYPE_SHADING:
ShadingColor xc = (ShadingColor)ec;
checkPDFXConformance(writer, PDFXKEY_COLOR, xc.getPdfShadingPattern().getShading().getColorSpace());
break;
case ExtendedColor.TYPE_PATTERN:
PatternColor pc = (PatternColor)ec;
checkPDFXConformance(writer, PDFXKEY_COLOR, pc.getPainter().getDefaultColor());
break;
}
}
else if (obj1 instanceof Color)
throw new PdfXConformanceException("Colorspace RGB is not allowed.");
break;
}
break;
case PDFXKEY_CMYK:
break;
case PDFXKEY_RGB:
if (conf == PDFX1A2001)
throw new PdfXConformanceException("Colorspace RGB is not allowed.");
break;
case PDFXKEY_FONT:
if (!((BaseFont)obj1).isEmbedded())
throw new PdfXConformanceException("All the fonts must be embedded.");
break;
case PDFXKEY_IMAGE:
PdfImage image = (PdfImage)obj1;
if (image.get(PdfName.SMASK) != null)
throw new PdfXConformanceException("The /SMask key is not allowed in images.");
switch (conf) {
case PDFX1A2001:
PdfObject cs = image.get(PdfName.COLORSPACE);
if (cs == null)
return;
if (cs.isName()) {
if (PdfName.DEVICERGB.equals(cs))
throw new PdfXConformanceException("Colorspace RGB is not allowed.");
}
else if (cs.isArray()) {
if (PdfName.CALRGB.equals((PdfObject)((PdfArray)cs).getArrayList().get(0)))
throw new PdfXConformanceException("Colorspace CalRGB is not allowed.");
}
break;
}
break;
case PDFXKEY_GSTATE:
PdfDictionary gs = (PdfDictionary)obj1;
PdfObject obj = gs.get(PdfName.BM);
if (obj != null && !PdfGState.BM_NORMAL.equals(obj) && !PdfGState.BM_COMPATIBLE.equals(obj))
throw new PdfXConformanceException("Blend mode " + obj.toString() + " not allowed.");
obj = gs.get(PdfName.CA);
double v = 0.0;
if (obj != null && (v = ((PdfNumber)obj).doubleValue()) != 1.0)
throw new PdfXConformanceException("Transparency is not allowed: /CA = " + v);
obj = gs.get(PdfName.ca);
v = 0.0;
if (obj != null && (v = ((PdfNumber)obj).doubleValue()) != 1.0)
throw new PdfXConformanceException("Transparency is not allowed: /ca = " + v);
break;
case PDFXKEY_LAYER:
throw new PdfXConformanceException("Layers are not allowed.");
}
}
|
public synchronized void close() {
if (open) {
if ((currentPageNumber - 1) != pageReferences.size())
throw new RuntimeException("The page " + pageReferences.size() +
" was requested but the document has only " + (currentPageNumber - 1) + " pages.");
pdf.close();
try {
addSharedObjectsToBody();
// add the root to the body
PdfIndirectReference rootRef = root.writePageTree();
// make the catalog-object and add it to the body
PdfDictionary catalog = getCatalog(rootRef);
// make pdfx conformant
PdfDictionary info = getInfo();
if (pdfxConformance != PDFXNONE) {
if (info.get(PdfName.GTS_PDFXVERSION) == null) {
if (pdfxConformance == PDFX1A2001) {
info.put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-1:2001"));
info.put(new PdfName("GTS_PDFXConformance"), new PdfString("PDF/X-1a:2001"));
}
else if (pdfxConformance == PDFX32002)
info.put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-3:2002"));
}
if (info.get(PdfName.TITLE) == null) {
info.put(PdfName.TITLE, new PdfString("Pdf document"));
}
if (info.get(PdfName.CREATOR) == null) {
info.put(PdfName.CREATOR, new PdfString("Unknown"));
}
if (info.get(PdfName.TRAPPED) == null) {
info.put(PdfName.TRAPPED, new PdfName("False"));
}
getExtraCatalog();
if (extraCatalog.get(PdfName.OUTPUTINTENTS) == null) {
PdfDictionary out = new PdfDictionary(PdfName.OUTPUTINTENT);
out.put(PdfName.OUTPUTCONDITION, new PdfString("SWOP CGATS TR 001-1995"));
out.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("CGATS TR 001"));
out.put(PdfName.REGISTRYNAME, new PdfString("http://www.color.org"));
out.put(PdfName.INFO, new PdfString(""));
out.put(PdfName.S, PdfName.GTS_PDFX);
extraCatalog.put(PdfName.OUTPUTINTENTS, new PdfArray(out));
}
}
if (extraCatalog != null) {
catalog.mergeDifferent(extraCatalog);
}
PdfIndirectObject indirectCatalog = addToBody(catalog, false);
// add the info-object to the body
PdfIndirectObject infoObj = addToBody(info, false);
PdfIndirectReference encryption = null;
PdfObject fileID = null;
body.flushObjStm();
if (crypto != null) {
PdfIndirectObject encryptionObject = addToBody(crypto.getEncryptionDictionary(), false);
encryption = encryptionObject.getIndirectReference();
fileID = crypto.getFileID();
}
else
fileID = PdfEncryption.createInfoId(PdfEncryption.createDocumentId());
// write the cross-reference table of the body
body.writeCrossReferenceTable(os, indirectCatalog.getIndirectReference(),
infoObj.getIndirectReference(), encryption, fileID, prevxref);
// make the trailer
if (fullCompression) {
os.write(getISOBytes("startxref\n"));
os.write(getISOBytes(String.valueOf(body.offset())));
os.write(getISOBytes("\n%%EOF\n"));
}
else {
PdfTrailer trailer = new PdfTrailer(body.size(),
body.offset(),
indirectCatalog.getIndirectReference(),
infoObj.getIndirectReference(),
encryption,
fileID, prevxref);
trailer.toPdf(this, os);
}
super.close();
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
}
}
Signals that the Document was closed and that no other
Elements will be added.
The pages-tree is built and written to the outputstream.
A Catalog is constructed, as well as an Info-object,
the referencetable is composed and everything is written
to the outputstream embedded in a Trailer. |
void eliminateFontSubset(PdfDictionary fonts) {
for (Iterator it = documentFonts.values().iterator(); it.hasNext();) {
FontDetails ft = (FontDetails)it.next();
if (fonts.get(ft.getFontName()) != null)
ft.setSubset(false);
}
}
|
public boolean fitsPage(Table table) {
return fitsPage(table, 0);
}
Checks if a Table fits the current page of the PdfDocument. |
public boolean fitsPage(PdfPTable table) {
return pdf.fitsPage(table, 0);
}
Checks if a PdfPTable fits the current page of the PdfDocument. |
public boolean fitsPage(Table table,
float margin) {
return pdf.bottom(table) > pdf.indentBottom() + margin;
}
Checks if a Table fits the current page of the PdfDocument. |
public boolean fitsPage(PdfPTable table,
float margin) {
return pdf.fitsPage(table, margin);
}
Checks if a PdfPTable fits the current page of the PdfDocument. |
public void freeReader(PdfReader reader) throws IOException {
currentPdfReaderInstance = (PdfReaderInstance)importedPages.get(reader);
if (currentPdfReaderInstance == null)
return;
currentPdfReaderInstance.writeAllPages();
currentPdfReaderInstance = null;
importedPages.remove(reader);
}
Writes the reader to the document and frees the memory used by it.
The main use is when concatenating multiple documents to keep the
memory usage restricted to the current appending document. |
public PdfAcroForm getAcroForm() {
return pdf.getAcroForm();
}
Gets the AcroForm object. |
protected PdfDictionary getCatalog(PdfIndirectReference rootObj) {
PdfDictionary catalog = ((PdfDocument)document).getCatalog(rootObj);
if (documentOCG.size() == 0)
return catalog;
fillOCProperties(false);
catalog.put(PdfName.OCPROPERTIES, OCProperties);
return catalog;
}
|
public int getCurrentDocumentSize() {
return body.offset() + body.size() * 20 + 0x48;
}
Gets the current document size. This size only includes
the data already writen to the output stream, it does not
include templates or fonts. It is usefull if used with
freeReader() when concatenating many documents
and an idea of the current size is needed. |
PdfIndirectReference getCurrentPage() {
return getPageReference(currentPageNumber);
}
|
int getCurrentPageNumber() {
return currentPageNumber;
}
|
public PdfDictionary getDefaultColorspace() {
return defaultColorspace;
}
Gets the default colorspaces. |
public PdfContentByte getDirectContent() {
if (!open)
throw new RuntimeException("The document is not open.");
return directContent;
}
Gets the direct content for this document. There is only one direct content,
multiple calls to this method will allways retrieve the same. |
public PdfContentByte getDirectContentUnder() {
if (!open)
throw new RuntimeException("The document is not open.");
return directContentUnder;
}
Gets the direct content under for this document. There is only one direct content,
multiple calls to this method will allways retrieve the same. |
PdfEncryption getEncryption() {
return crypto;
}
|
public PdfDictionary getExtraCatalog() {
if (extraCatalog == null)
extraCatalog = new PdfDictionary();
return this.extraCatalog;
}
Sets extra keys to the catalog. |
public PdfDictionary getGroup() {
return this.group;
}
Getter for property group. |
PdfIndirectReference getImageReference(PdfName name) {
return (PdfIndirectReference) imageDictionary.get(name);
}
return the PdfIndirectReference to the image with a given name. |
public PdfImportedPage getImportedPage(PdfReader reader,
int pageNumber) {
PdfReaderInstance inst = (PdfReaderInstance)importedPages.get(reader);
if (inst == null) {
inst = reader.getPdfReaderInstance(this);
importedPages.put(reader, inst);
}
return inst.getImportedPage(pageNumber);
}
Gets a page from other PDF document. The page can be used as
any other PdfTemplate. Note that calling this method more than
once with the same parameters will retrieve the same object. |
int getIndirectReferenceNumber() {
return body.getIndirectReferenceNumber();
}
|
public PdfDictionary getInfo() {
return ((PdfDocument)document).getInfo();
}
Gets the info dictionary for changing. |
public static PdfWriter getInstance(Document document,
OutputStream os) throws DocumentException {
PdfDocument pdf = new PdfDocument();
document.addDocListener(pdf);
PdfWriter writer = new PdfWriter(pdf, os);
pdf.addWriter(writer);
return writer;
}
Gets an instance of the PdfWriter. |
public static PdfWriter getInstance(Document document,
OutputStream os,
DocListener listener) throws DocumentException {
PdfDocument pdf = new PdfDocument();
pdf.addDocListener(listener);
document.addDocListener(pdf);
PdfWriter writer = new PdfWriter(pdf, os);
pdf.addWriter(writer);
return writer;
}
Gets an instance of the PdfWriter. |
protected int getNewObjectNumber(PdfReader reader,
int number,
int generation) {
return currentPdfReaderInstance.getNewObjectNumber(number, generation);
}
|
public PdfOCProperties getOCProperties() {
fillOCProperties(true);
return OCProperties;
}
Gets the Optional Content Properties Dictionary. Each call fills the dictionary with the current layer
state. It's advisable to only call this method right before close and do any modifications
at that time. |
public OutputStreamCounter getOs() {
return os;
}
Returns the outputStreamCounter. |
public int getPDFXConformance() {
return pdfxConformance;
}
Gets the PDFX conformance level. |
public PdfPageEvent getPageEvent() {
return pageEvent;
}
Gets the PdfPageEvent for this document or null
if none is set. |
public int getPageNumber() {
return pdf.getPageNumber();
}
Gets the current pagenumber of this document. |
public PdfIndirectReference getPageReference(int page) {
--page;
if (page < 0)
throw new IndexOutOfBoundsException("The page numbers start at 1.");
PdfIndirectReference ref;
if (page < pageReferences.size()) {
ref = (PdfIndirectReference)pageReferences.get(page);
if (ref == null) {
ref = body.getPdfIndirectReference();
pageReferences.set(page, ref);
}
}
else {
int empty = page - pageReferences.size();
for (int k = 0; k < empty; ++k)
pageReferences.add(null);
ref = body.getPdfIndirectReference();
pageReferences.add(ref);
}
return ref;
}
Gets a reference to a page existing or not. If the page does not exist
yet the reference will be created in advance. If on closing the document, a
page number greater than the total number of pages was requested, an
exception is thrown. |
PdfDocument getPdfDocument() {
return pdf;
}
Gets the PdfDocument associated with this writer. |
public PdfIndirectReference getPdfIndirectReference() {
return body.getPdfIndirectReference();
}
Gets a PdfIndirectReference for an object that
will be created in the future. |
public PdfTable getPdfTable(Table table) {
return pdf.getPdfTable(table, true);
}
Gets a pre-rendered table.
(Contributed by dperezcar@fcc.es) |
RandomAccessFileOrArray getReaderFile(PdfReader reader) {
return currentPdfReaderInstance.getReaderFile();
}
|
public PdfOutline getRootOutline() {
return directContent.getRootOutline();
}
|
public int getRunDirection() {
return runDirection;
}
|
public float getSpaceCharRatio() {
return spaceCharRatio;
}
Gets the space/character extra spacing ratio for
fully justified text. |
public float getTableBottom(Table table) {
return pdf.bottom(table) - pdf.indentBottom();
}
Sometimes it is necessary to know where the just added Table ends.
For instance to avoid to add another table in a page that is ending up, because
the new table will be probably splitted just after the header (it is an
unpleasant effect, isn't it?).
Added on September 8th, 2001
by Francesco De Milato
francesco.demilato@tiscalinet.it |
public float getVerticalPosition(boolean ensureNewLine) {
return pdf.getVerticalPosition(ensureNewLine);
}
Gets the current vertical page position. |
public boolean isFullCompression() {
return this.fullCompression;
}
Gets the 1.5 compression status. |
boolean isPaused() {
return pause;
}
Checks if writing is paused. |
public boolean isStrictImageSequence() {
return pdf.isStrictImageSequence();
}
Getter for property strictImageSequence. |
public void open() {
super.open();
try {
os.write(HEADER);
body = new PdfBody(this);
if (pdfxConformance == PDFX32002) {
PdfDictionary sec = new PdfDictionary();
sec.put(PdfName.GAMMA, new PdfArray(new float[]{2.2f,2.2f,2.2f}));
sec.put(PdfName.MATRIX, new PdfArray(new float[]{0.4124f,0.2126f,0.0193f,0.3576f,0.7152f,0.1192f,0.1805f,0.0722f,0.9505f}));
sec.put(PdfName.WHITEPOINT, new PdfArray(new float[]{0.9505f,1f,1.089f}));
PdfArray arr = new PdfArray(PdfName.CALRGB);
arr.add(sec);
setDefaultColorspace(PdfName.DEFAULTRGB, addToBody(arr).getIndirectReference());
}
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
}
Signals that the Document has been opened and that
Elements can be added.
When this method is called, the PDF-document header is
written to the outputstream. |
void registerLayer(PdfOCG layer) {
checkPDFXConformance(this, PDFXKEY_LAYER, null);
if (layer instanceof PdfLayer) {
PdfLayer la = (PdfLayer)layer;
if (la.getTitle() == null) {
if (!documentOCG.contains(layer)) {
documentOCG.add(layer);
documentOCGorder.add(layer);
}
}
else {
documentOCGorder.add(layer);
}
}
else
throw new IllegalArgumentException("Only PdfLayer is accepted.");
}
|
public int reorderPages(int[] order) throws DocumentException {
return root.reorderPages(order);
}
Reorder the pages in the document. A null argument value
only returns the number of pages to process. It is
advisable to issue a Document.newPage()
before using this method. |
void resetContent() {
directContent.reset();
directContentUnder.reset();
}
Resets all the direct contents to empty. This happens when a new page is started. |
public void setAdditionalAction(PdfName actionType,
PdfAction action) throws PdfException {
if (!(actionType.equals(DOCUMENT_CLOSE) ||
actionType.equals(WILL_SAVE) ||
actionType.equals(DID_SAVE) ||
actionType.equals(WILL_PRINT) ||
actionType.equals(DID_PRINT))) {
throw new PdfException("Invalid additional action type: " + actionType.toString());
}
pdf.addAdditionalAction(actionType, action);
}
Additional-actions defining the actions to be taken in
response to various trigger events affecting the document
as a whole. The actions types allowed are: DOCUMENT_CLOSE,
WILL_SAVE, DID_SAVE, WILL_PRINT
and DID_PRINT. |
public void setBoxSize(String boxName,
Rectangle size) {
pdf.setBoxSize(boxName, size);
}
Sets the page box sizes. Allowed names are: "crop", "trim", "art" and "bleed". |
public void setCropBoxSize(Rectangle crop) {
pdf.setCropBoxSize(crop);
}
Sets the crop box. The crop box should not be rotated even if the
page is rotated. This change only takes effect in the next
page. |
public void setDefaultColorspace(PdfName key,
PdfObject cs) {
if (cs == null || cs.isNull())
defaultColorspace.remove(key);
defaultColorspace.put(key, cs);
}
Sets the default colorspace that will be applied to all the document.
The colorspace is only applied if another colorspace with the same name
is not present in the content.
The colorspace is applied immediately when creating templates and at the page
end for the main document content. |
public void setDuration(int seconds) {
pdf.setDuration(seconds);
}
Sets the display duration for the page (for presentations) |
public void setEncryption(byte[] userPassword,
byte[] ownerPassword,
int permissions,
boolean strength128Bits) throws DocumentException {
if (pdf.isOpen())
throw new DocumentException("Encryption can only be added before opening the document.");
crypto = new PdfEncryption();
crypto.setupAllKeys(userPassword, ownerPassword, permissions, strength128Bits);
}
Sets the encryption options for this document. The userPassword and the
ownerPassword can be null or have zero length. In this case the ownerPassword
is replaced by a random string. The open permissions for the document can be
AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
The permissions can be combined by ORing them. |
public void setEncryption(boolean strength,
String userPassword,
String ownerPassword,
int permissions) throws DocumentException {
setEncryption(getISOBytes(userPassword), getISOBytes(ownerPassword), permissions, strength);
}
Sets the encryption options for this document. The userPassword and the
ownerPassword can be null or have zero length. In this case the ownerPassword
is replaced by a random string. The open permissions for the document can be
AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
The permissions can be combined by ORing them. |
public void setFullCompression() {
this.fullCompression = true;
setPdfVersion(VERSION_1_5);
}
|
public void setGroup(PdfDictionary group) {
this.group = group;
}
Setter for property group. |
public void setLinearPageMode() {
root.setLinearMode(null);
}
Sets the document in a suitable way to do page reordering. |
public void setOpenAction(String name) {
pdf.setOpenAction(name);
}
When the document opens it will jump to the destination with
this name. |
public void setOpenAction(PdfAction action) {
pdf.setOpenAction(action);
}
When the document opens this action will be
invoked. |
public boolean setOutputIntents(PdfReader reader,
boolean checkExistence) throws IOException {
PdfDictionary catalog = reader.getCatalog();
PdfArray outs = (PdfArray)PdfReader.getPdfObject(catalog.get(PdfName.OUTPUTINTENTS));
if (outs == null)
return false;
ArrayList arr = outs.getArrayList();
if (arr.size() == 0)
return false;
PdfDictionary out = (PdfDictionary)PdfReader.getPdfObject((PdfObject)arr.get(0));
PdfObject obj = PdfReader.getPdfObject(out.get(PdfName.S));
if (obj == null || !PdfName.GTS_PDFX.equals(obj))
return false;
if (checkExistence)
return true;
PRStream stream = (PRStream)PdfReader.getPdfObject(out.get(PdfName.DESTOUTPUTPROFILE));
byte destProfile[] = null;
if (stream != null) {
destProfile = PdfReader.getStreamBytes(stream);
}
setOutputIntents(getNameString(out, PdfName.OUTPUTCONDITIONIDENTIFIER), getNameString(out, PdfName.OUTPUTCONDITION),
getNameString(out, PdfName.REGISTRYNAME), getNameString(out, PdfName.INFO), destProfile);
return true;
}
Copies the output intent dictionary from other document to this one. |
public void setOutputIntents(String outputConditionIdentifier,
String outputCondition,
String registryName,
String info,
byte[] destOutputProfile) throws IOException {
getExtraCatalog();
PdfDictionary out = new PdfDictionary(PdfName.OUTPUTINTENT);
if (outputCondition != null)
out.put(PdfName.OUTPUTCONDITION, new PdfString(outputCondition, PdfObject.TEXT_UNICODE));
if (outputConditionIdentifier != null)
out.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString(outputConditionIdentifier, PdfObject.TEXT_UNICODE));
if (registryName != null)
out.put(PdfName.REGISTRYNAME, new PdfString(registryName, PdfObject.TEXT_UNICODE));
if (info != null)
out.put(PdfName.INFO, new PdfString(registryName, PdfObject.TEXT_UNICODE));
if (destOutputProfile != null) {
PdfStream stream = new PdfStream(destOutputProfile);
stream.flateCompress();
out.put(PdfName.DESTOUTPUTPROFILE, addToBody(stream).getIndirectReference());
}
out.put(PdfName.S, PdfName.GTS_PDFX);
extraCatalog.put(PdfName.OUTPUTINTENTS, new PdfArray(out));
}
Sets the values of the output intent dictionary. Null values are allowed to
suppress any key. |
public void setPDFXConformance(int pdfxConformance) {
if (this.pdfxConformance == pdfxConformance)
return;
if (pdf.isOpen())
throw new PdfXConformanceException("PDFX conformance can only be set before opening the document.");
if (crypto != null)
throw new PdfXConformanceException("A PDFX conforming document cannot be encrypted.");
if (pdfxConformance != PDFXNONE)
setPdfVersion(VERSION_1_3);
this.pdfxConformance = pdfxConformance;
}
Sets the PDFX conformance level. Allowed values are PDFX1A2001 and PDFX32002. It
must be called before opening the document. |
public void setPageAction(PdfName actionType,
PdfAction action) throws PdfException {
if (!actionType.equals(PAGE_OPEN) && !actionType.equals(PAGE_CLOSE))
throw new PdfException("Invalid page additional action type: " + actionType.toString());
pdf.setPageAction(actionType, action);
}
Sets the open and close page additional action. |
public void setPageEmpty(boolean pageEmpty) {
pdf.setPageEmpty(pageEmpty);
}
If you use setPageEmpty(false), invoking newPage() after a blank page will add a newPage. |
public void setPageEvent(PdfPageEvent pageEvent) {
this.pageEvent = pageEvent;
}
Sets the PdfPageEvent for this document. |
public void setPageLabels(PdfPageLabels pageLabels) {
pdf.setPageLabels(pageLabels);
}
|
public void setPdfVersion(char version) {
if (HEADER.length > VPOINT)
HEADER[VPOINT] = (byte)version;
}
Sets the PDF version. Must be used right before the document
is opened. Valid options are VERSION_1_2, VERSION_1_3,
VERSION_1_4, VERSION_1_5 and VERSION_1_6. VERSION_1_4 is the default. |
public void setRunDirection(int runDirection) {
if (runDirection < RUN_DIRECTION_NO_BIDI || runDirection > RUN_DIRECTION_RTL)
throw new RuntimeException("Invalid run direction: " + runDirection);
this.runDirection = runDirection;
}
Sets the run direction. This is only used as a placeholder
as it does not affect anything. |
public void setSigFlags(int f) {
pdf.setSigFlags(f);
}
|
public void setSpaceCharRatio(float spaceCharRatio) {
if (spaceCharRatio < 0.001f)
this.spaceCharRatio = 0.001f;
else
this.spaceCharRatio = spaceCharRatio;
}
Sets the ratio between the extra word spacing and the extra character spacing
when the text is fully justified.
Extra word spacing will grow spaceCharRatio times more than extra character spacing.
If the ratio is PdfWriter.NO_SPACE_CHAR_RATIO then the extra character spacing
will be zero. |
public void setStrictImageSequence(boolean strictImageSequence) {
pdf.setStrictImageSequence(strictImageSequence);
}
Sets the image sequence to follow the text in strict order. |
public void setThumbnail(Image image) throws PdfException, DocumentException {
pdf.setThumbnail(image);
}
Sets the the thumbnail image for the current page. |
public void setTransition(PdfTransition transition) {
pdf.setTransition(transition);
}
Sets the transition for the page |
public void setViewerPreferences(int preferences) {
pdf.setViewerPreferences(preferences);
}
Sets the viewer preferences by ORing some constants.
- The page layout to be used when the document is opened (choose one).
- PageLayoutSinglePage - Display one page at a time. (default)
- PageLayoutOneColumn - Display the pages in one column.
- PageLayoutTwoColumnLeft - Display the pages in two columns, with
oddnumbered pages on the left.
- PageLayoutTwoColumnRight - Display the pages in two columns, with
oddnumbered pages on the right.
- The page mode how the document should be displayed
when opened (choose one).
- PageModeUseNone - Neither document outline nor thumbnail images visible. (default)
- PageModeUseOutlines - Document outline visible.
- PageModeUseThumbs - Thumbnail images visible.
- PageModeFullScreen - Full-screen mode, with no menu bar, window
controls, or any other window visible.
- PageModeUseOC - Optional content group panel visible
- HideToolbar - A flag specifying whether to hide the viewer application's tool
bars when the document is active.
- HideMenubar - A flag specifying whether to hide the viewer application's
menu bar when the document is active.
- HideWindowUI - A flag specifying whether to hide user interface elements in
the document's window (such as scroll bars and navigation controls),
leaving only the document's contents displayed.
- FitWindow - A flag specifying whether to resize the document's window to
fit the size of the first displayed page.
- CenterWindow - A flag specifying whether to position the document's window
in the center of the screen.
- DisplayDocTitle - A flag specifying whether to display the document's title
in the top bar.
- The predominant reading order for text. This entry has no direct effect on the
document's contents or page numbering, but can be used to determine the relative
positioning of pages when displayed side by side or printed n-up (choose one).
- DirectionL2R - Left to right
- DirectionR2L - Right to left (including vertical writing systems such as
Chinese, Japanese, and Korean)
- The document's page mode, specifying how to display the
document on exiting full-screen mode. It is meaningful only
if the page mode is PageModeFullScreen (choose one).
- NonFullScreenPageModeUseNone - Neither document outline nor thumbnail images
visible
- NonFullScreenPageModeUseOutlines - Document outline visible
- NonFullScreenPageModeUseThumbs - Thumbnail images visible
- NonFullScreenPageModeUseOC - Optional content group panel visible
- PrintScalingNone - Indicates that the print dialog should reflect no page scaling.
|