Esempio n. 1
0
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            // generate view into string
            var sb = new System.Text.StringBuilder();
            TextWriter tw = new System.IO.StringWriter(sb);
            _result.View.Render(viewContext, tw);
            var resultCache = sb.ToString();

            var ms = new MemoryStream();
            var document = new Document();
            var pdfWriter = PdfWriter.GetInstance(document, ms);
            var worker = new HTMLWorker(document);
            document.Open();
            worker.StartDocument();

            pdfWriter.CloseStream = false;

            worker.Parse(new StringReader(resultCache));
            worker.EndDocument();
            worker.Close();
            document.Close();

            // this is as close as we can get to being "success" before writing output
            // so set the content type now
            viewContext.HttpContext.Response.ContentType = "application/pdf";
            pdfWriter.Flush();
            pdfWriter.Close();

            viewContext.HttpContext.Response.BinaryWrite(ms.ToArray());
        }
Esempio n. 2
0
 /**
  * Called when a Paragraph is written.
  * <P>
  * <CODE>paragraphPosition</CODE> will hold the height of the end of the paragraph.
  *
  * @param writer the <CODE>PdfWriter</CODE> for this document
  * @param document the document
  * @param paragraphPosition the position of the end of the paragraph
  */
 public virtual void OnParagraphEnd(PdfWriter writer,Document document,float paragraphPosition)
 {
 }
Esempio n. 3
0
 /**
                                  * Called when the document is opened.
                                  *
                                  * @param writer the <CODE>PdfWriter</CODE> for this document
                                  * @param document the document
                                  */
 public virtual void OnOpenDocument(PdfWriter writer,Document document)
 {
 }
Esempio n. 4
0
 /**
  * Called when a <CODE>Chunk</CODE> with a generic tag is written.
  * <P>
  * It is usefull to pinpoint the <CODE>Chunk</CODE> location to generate
  * bookmarks, for example.
  *
  * @param writer the <CODE>PdfWriter</CODE> for this document
  * @param document the document
  * @param rect the <CODE>Rectangle</CODE> containing the <CODE>Chunk</CODE>
  * @param text the text of the tag
  */
 public virtual void OnGenericTag(PdfWriter writer,Document document,Rectangle rect,string text)
 {
 }
Esempio n. 5
0
 /**
  * Called when a page is finished, just before being written to the document.
  *
  * @param writer the <CODE>PdfWriter</CODE> for this document
  * @param document the document
  */
 public virtual void OnEndPage(PdfWriter writer,Document document)
 {
 }
Esempio n. 6
0
 /**
  * Called when the document is closed.
  * <P>
  * Note that this method is called with the page number equal
  * to the last page plus one.
  *
  * @param writer the <CODE>PdfWriter</CODE> for this document
  * @param document the document
  */
 public virtual void OnCloseDocument(PdfWriter writer,Document document)
 {
 }
 /**
 * Called when a <CODE>Chunk</CODE> with a generic tag is written.
 * <P>
 * It is usefull to pinpoint the <CODE>Chunk</CODE> location to generate
 * bookmarks, for example.
 *
 * @param writer
 *            the <CODE>PdfWriter</CODE> for this document
 * @param document
 *            the document
 * @param rect
 *            the <CODE>Rectangle</CODE> containing the <CODE>Chunk
 *            </CODE>
 * @param text
 *            the text of the tag
 */
 public virtual void OnGenericTag(PdfWriter writer, Document document,
         Rectangle rect, String text)
 {
     foreach (IPdfPageEvent eventa in events) {
         eventa.OnGenericTag(writer, document, rect, text);
     }
 }
Esempio n. 8
0
 /**
  * Called when a Chapter is written.
  * <P>
  * <CODE>position</CODE> will hold the height at which the
  * chapter will be written to.
  *
  * @param writer            the <CODE>PdfWriter</CODE> for this document
  * @param document          the document
  * @param paragraphPosition the position the chapter will be written to
  * @param title             the title of the Chapter
  */
 public virtual void OnChapter(PdfWriter writer,Document document,float paragraphPosition,Paragraph title)
 {
 }
 /**
 * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String)
 */
 public override void OnGenericTag(PdfWriter writer, Document document,
         Rectangle rect, String text)
 {
     rect.Bottom = rect.Bottom - 3;
     PdfFormField field = (PdfFormField) genericChunkFields[text];
     if (field == null) {
         TextField tf = new TextField(writer, new Rectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)), text);
         tf.FontSize = 14;
         field = tf.GetTextField();
     }
     else {
         field.Put(PdfName.RECT,  new PdfRectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)));
     }
     if (parent == null)
         writer.AddAnnotation(field);
     else
         parent.AddKid(field);
 }
 /**
 * Called when a page is initialized.
 * <P>
 * Note that if even if a page is not written this method is still called.
 * It is preferable to use <CODE>onEndPage</CODE> to avoid infinite loops.
 *
 * @param writer
 *            the <CODE>PdfWriter</CODE> for this document
 * @param document
 *            the document
 */
 public virtual void OnStartPage(PdfWriter writer, Document document)
 {
     foreach (IPdfPageEvent eventa in events) {
         eventa.OnStartPage(writer, document);
     }
 }
 /**
 * Called when a Chapter is written.
 * <P>
 * <CODE>position</CODE> will hold the height at which the chapter will be
 * written to.
 *
 * @param writer
 *            the <CODE>PdfWriter</CODE> for this document
 * @param document
 *            the document
 * @param paragraphPosition
 *            the position the chapter will be written to
 * @param title
 *            the title of the Chapter
 */
 public virtual void OnChapter(PdfWriter writer, Document document,
         float paragraphPosition, Paragraph title)
 {
     foreach (IPdfPageEvent eventa in events) {
         eventa.OnChapter(writer, document, paragraphPosition, title);
     }
 }
 /**
 * Called when the end of a Section is reached.
 * <P>
 * <CODE>position</CODE> will hold the height of the section end.
 *
 * @param writer
 *            the <CODE>PdfWriter</CODE> for this document
 * @param document
 *            the document
 * @param position
 *            the position of the end of the section
 */
 public virtual void OnSectionEnd(PdfWriter writer, Document document, float position)
 {
     foreach (IPdfPageEvent eventa in events) {
         eventa.OnSectionEnd(writer, document, position);
     }
 }
 /**
 * Called when a Section is written.
 * <P>
 * <CODE>position</CODE> will hold the height at which the section will be
 * written to.
 *
 * @param writer
 *            the <CODE>PdfWriter</CODE> for this document
 * @param document
 *            the document
 * @param paragraphPosition
 *            the position the section will be written to
 * @param depth
 *            the number depth of the Section
 * @param title
 *            the title of the section
 */
 public virtual void OnSection(PdfWriter writer, Document document,
         float paragraphPosition, int depth, Paragraph title)
 {
     foreach (IPdfPageEvent eventa in events) {
         eventa.OnSection(writer, document, paragraphPosition, depth, title);
     }
 }
 /**
 * Called when a Paragraph is written.
 * <P>
 * <CODE>paragraphPosition</CODE> will hold the height of the end of the
 * paragraph.
 *
 * @param writer
 *            the <CODE>PdfWriter</CODE> for this document
 * @param document
 *            the document
 * @param paragraphPosition
 *            the position of the end of the paragraph
 */
 public virtual void OnParagraphEnd(PdfWriter writer, Document document,
         float paragraphPosition)
 {
     foreach (IPdfPageEvent eventa in events) {
         eventa.OnParagraphEnd(writer, document, paragraphPosition);
     }
 }
Esempio n. 15
0
 /**
  * Called when a Section is written.
  * <P>
  * <CODE>position</CODE> will hold the height at which the
  * section will be written to.
  *
  * @param writer            the <CODE>PdfWriter</CODE> for this document
  * @param document          the document
  * @param paragraphPosition the position the chapter will be written to
  * @param title             the title of the Chapter
  */
 public virtual void OnSection(PdfWriter writer,Document document,float paragraphPosition,int depth,Paragraph title)
 {
 }
Esempio n. 16
0
 /** Creates a PdfSmartCopy instance. */
 public PdfSmartCopy(Document document, Stream os)
     : base(document, os)
 {
     this.streamMap = new Hashtable();
 }
Esempio n. 17
0
 /**
  * Called when a page is initialized.
  * <P>
  * Note that if even if a page is not written this method is still
  * called. It is preferable to use <CODE>onEndPage</CODE> to avoid
  * infinite loops.
  *
  * @param writer the <CODE>PdfWriter</CODE> for this document
  * @param document the document
  */
 public virtual void OnStartPage(PdfWriter writer,Document document)
 {
 }
Esempio n. 18
0
 /**
 * Constructor
 * @param document
 * @param os outputstream
 */
 public PdfCopy(Document document, Stream os)
     : base(new PdfDocument(), os)
 {
     document.AddDocListener(pdf);
     pdf.AddWriter(this);
     indirectMap = new Hashtable();
 }
Esempio n. 19
0
 /**
  * Called when the end of a Chapter is reached.
  * <P>
  * <CODE>position</CODE> will hold the height of the end of the chapter.
  *
  * @param writer the <CODE>PdfWriter</CODE> for this document
  * @param document the document
  * @param position the position of the end of the chapter.
  */
 public virtual void OnChapterEnd(PdfWriter writer,Document document,float position)
 {
 }
Esempio n. 20
0
 /// <summary>
 /// Constructs a DocWriter.
 /// </summary>
 /// <param name="document">The Document that has to be written</param>
 /// <param name="os">The Stream the writer has to write to.</param>
 protected DocWriter(Document document, Stream os)
 {
     this.document = document;
     this.os = new OutputStreamCounter(os);
 }