Greetings to all.

I apologise in advance for my ignorance.  I am trying to learn, using 
iTextSharp, how to take an existing PDF and add a bit of text to it in a VB.NET 
environment.  I am waiting for my copy of the book iText In Action to arrive, 
but wanted to try getting a head start... It would appear I am missing 
something very important.  

Here is my VB code-behind page:
_____________________
Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Linq
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Imports System.Collections.Generic
Imports System.IO
Imports System.Xml
Imports iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.html.simpleparser

Partial Public Class PdfGenerator

    Inherits System.Web.UI.Page


    Protected Sub GeneratePDFWithText(ByVal sender As Object, ByVal e As 
EventArgs)

        Dim fileName As String = "pdfDocument" & DateTime.Now.Ticks & ".pdf"
        Dim text As String = TextBox1.Text
        Dim document As New Document()
        Dim bf_times As BaseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, 
"Cp1252", False)
        Dim sourcepdf As String = 
System.AppDomain.CurrentDomain.BaseDirectory() & 
"SourcePDFs\CRM1008-01-MoreRefLtr.pdf"
        Dim reader As PdfReader = New PdfReader(sourcepdf)
        Dim stamp As PdfStamper = New PdfStamper(reader, Response.OutputStream)
        

        Response.Clear()

        Dim content As PdfContentByte = stamp.GetUnderContent(1)
        Dim txt As PdfContentByte = stamp.GetOverContent(1)
        txt.BeginText()
        txt.SetTextMatrix(250, 250)
        txt.SetFontAndSize(bf_times, 14)
        txt.ShowText(text)
        txt.EndText()

        content.Add(txt)

        stamp.Close()

        Response.ContentType = "application/pdf"
        Response.AddHeader("content-disposition", "attachment filename=" + 
fileName)
        Response.Flush()
        Response.End()

    End Sub


End Class
____________________________________

My content page simply contains a single textbox and a button to create and 
download the PDF to the user.

My application will accept the text into the box, and clicking the button 
successfully creates a PDF.  But when the downloaded PDF is opened, Adobe 
claims that the file is damaged and cannot be opened.

Have I missed something in how to add the text or properly code the PDF output?

Thank you in advance for any assistance you can offer.  

Craig
ShadesOfKnight AT yahoo dot com




      

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to