we override the onCloseDocument method.

@param writer
PdfWriter
@param document
Document
6766
@Override
	public void onCloseDocument(final PdfWriter writer, final Document document) {
		template.beginText();
		template.setFontAndSize(bf, 8);
		template.showText(String.valueOf(writer.getPageNumber() - 1));
		template.endText();
	}
427903
public void write(String key, String document) throws IOException {
    try {
      // Write the key.
      outputStream.write(key.getBytes("UTF-8"));

      // Write the key-document keyDocumentDelimiter.
      outputStream.write(keyDocumentDelimiter.getBytes("UTF-8"));

      // Write the document.
      outputStream.write(document.getBytes("UTF-8"));

      // Write the row keyDocumentDelimiter.
      outputStream.write(rowDelimiter.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) { LOGGER.error("Shouldn't happen."); }
  }
1346320
protected SnapshotWriter openWriter(SnapshotWriter writer, SnapshotDescriptor descriptor) {
    checkWriter();
    Assert.stateNot(descriptor.locked(), "cannot write to locked snapshot descriptor");
    this.writer = Assert.notNull(writer, "writer");
    return writer;
  }
559159
public void toPdf(PdfWriter writer, OutputStream os) throws IOException {
        if (color != null && !color.equals(Color.black)) {
            put(PdfName.C, new PdfArray(new float[]{color.getRed()/255f,color.getGreen()/255f,color.getBlue()/255f}));
        }
        int flag = 0;
        if ((style & Font.BOLD) != 0)
            flag |= 2;
        if ((style & Font.ITALIC) != 0)
            flag |= 1;
        if (flag != 0)
            put(PdfName.F, new PdfNumber(flag));
        if (parent != null) {
            put(PdfName.PARENT, parent.indirectReference());
        }
        if (destination != null && destination.hasPage()) {
            put(PdfName.DEST, destination);
        }
        if (action != null)
            put(PdfName.A, action);
        if (count != 0) {
            put(PdfName.COUNT, new PdfNumber(count));
        }
        super.toPdf(writer, os);
    }
749358
public void writeDocument(String filename, Document document) {
            ProvFormat format = getTypeForFile(filename);
            if (format == null) {
                System.err.println("Unknown output file format: " + filename);
                return;
            }
        writeDocument(filename, format, document);
    }
1220420
public void write(Writer out)
            throws XmlModelWriterException, IOException
    {
        try
        {
            DOMSource domSource = new DOMSource(_doc);
            StreamResult streamResult = new StreamResult(out);
            TransformerFactory tf = TransformerFactory.newInstance();
            tf.setAttribute("indent-number", new Integer(INDENT_LEN));
            Transformer serializer = tf.newTransformer();
            if (_publicID != null) {
                serializer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, _publicID);
            }
            if (_systemID != null) {
                serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, _systemID);
            }
            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
            serializer.transform(domSource, streamResult);
        }
        catch (TransformerException e)
        {
            throw new XmlModelWriterException(e);
        }
    }
1360416
private void handleDocument(EntityDocument document) {
		if (document instanceof ItemDocument) {
			this.entityDocumentProcessor
					.processItemDocument((ItemDocument) document);
		} else if (document instanceof PropertyDocument) {
			this.entityDocumentProcessor
					.processPropertyDocument((PropertyDocument) document);
		} else if(document instanceof LexemeDocument) {
			this.entityDocumentProcessor
					.processLexemeDocument((LexemeDocument) document);
		}
	}
159018
private void writeDocument( Document document, File file )
        throws TransformerException, FileNotFoundException
    {
        document.normalize();
        DOMSource source = new DOMSource( document );
        StreamResult result = new StreamResult( new FileOutputStream( file ) );
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
        transformer.transform( source, result );
    }
1009253
public static void closeEL(Writer w) {
	try {
	    if (w != null) w.close();
	}
	// catch (AlwaysThrow at) {throw at;}
	catch (Throwable e) {
	    ExceptionUtil.rethrowIfNecessary(e);
	}
    }
480374
public void write( Document document ) {
        assert document != null;
        ++count;
        ++totalCount;
        if (count > maxDocumentsPerFile) {
            // Close the stream (we'll open a new one later in the method) ...
            close();
            count = 1;
        }
        try {
            if (stream == null) {
                // Open the stream to the next file ...
                ++fileCount;
                String suffix = StringUtil.justifyRight(Long.toString(fileCount), BackupService.NUM_CHARS_IN_FILENAME_SUFFIX, '0');
                String filename = filenamePrefix + "_" + suffix + DOCUMENTS_EXTENSION;
                if (compress) filename = filename + GZIP_EXTENSION;
                currentFile = new File(parentDirectory, filename);
                OutputStream fileStream = new FileOutputStream(currentFile);
                if (compress) fileStream = new GZIPOutputStream(fileStream);
                stream = new BufferedOutputStream(fileStream);
            }
            Json.write(document, stream);
            // Need to append a non-consumable character so that we can read multiple JSON documents per file
            stream.write((byte)'\n');
        } catch (IOException e) {
            problems.addError(JcrI18n.problemsWritingDocumentToBackup, currentFile.getAbsolutePath(), e.getMessage());
        }
    }
8420
public void write(Writer out)
         throws IOException
    {
        writeHtmlHead(out);
        writeBodyTag(out);
        writeElements(out);
        writeHtmlEnd(out);
    }
937513
@Override
  public void closeWrite() throws IOException
  {
    if (_isWriteClosed) {
      return;
    }
    
    _isWriteClosed = true;
    
    StreamImpl stream = _streamImpl;
    
    if (stream != null) {
      stream.closeWrite();
    }
    else if (_sslSocket != null) {
      _sslSocket.getOutputStream().close();
    }
    else if (_channel != null) {
      try {
        _channel.shutdownOutput();
      } catch (UnsupportedOperationException e) {
        log.log(Level.FINEST, e.toString(), e);
      } catch (Exception e) {
        log.finer(e.toString());
        log.log(Level.FINEST, e.toString(), e);
      }
    }
  }
442019
public static void writeXML(DocumentFragment fragment, Writer writer) throws IOException {
		assert fragment != null : AssertMessages.notNullParameter(0);
		assert writer != null : AssertMessages.notNullParameter(1);
		writeNode(fragment, writer);
	}
401432
public void setDocumentation(String doc) {
		if (Strings.isEmpty(doc)) {
			getSarlAnnotationType().eAdapters().removeIf(new Predicate<Adapter>() {
				public boolean test(Adapter adapter) {
					return adapter.isAdapterForType(DocumentationAdapter.class);
				}
			});
		} else {
			DocumentationAdapter adapter = (DocumentationAdapter) EcoreUtil.getExistingAdapter(
					getSarlAnnotationType(), DocumentationAdapter.class);
			if (adapter == null) {
				adapter = new DocumentationAdapter();
				getSarlAnnotationType().eAdapters().add(adapter);
			}
			adapter.setDocumentation(doc);
		}
	}
169420
protected DocWriter createWriter(final MBasicTable table, final Document document,
			final OutputStream out) throws DocumentException {
		final PdfWriter writer = PdfWriter.getInstance(document, out);
		// writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft);

		// title
		if (table.getName() != null) {
			final HeaderFooter header = new HeaderFooter(new Phrase(table.getName()), false);
			header.setAlignment(Element.ALIGN_LEFT);
			header.setBorder(Rectangle.NO_BORDER);
			document.setHeader(header);
			document.addTitle(table.getName());
		}

		// simple page numbers : x
		// HeaderFooter footer = new HeaderFooter(new Phrase(), true);
		// footer.setAlignment(Element.ALIGN_RIGHT);
		// footer.setBorder(Rectangle.TOP);
		// document.setFooter(footer);

		// add the event handler for advanced page numbers : x/y
		writer.setPageEvent(new AdvancedPageNumberEvents());

		return writer;
	}
883712
public void addWriterListener(WriterListener writerListener) {
        if (writerListener == null) {
            return;
        }
        synchronized (listeners) {
            if (!listeners.contains(writerListener)) {
                listeners.add(writerListener);
            }
        }
    }
765161
@Override
    public synchronized void write(final Event event) throws IOException
    {
        if (!acceptsEvents) {
            log.warn("Writer not ready, discarding event: {}", event);
            return;
        }

        delegate.write(event);
        uncommittedWriteCount++;

        commitIfNeeded();
    }