[5682] iTextSharp :library to create PDF Files on fly in C#.net
-
Thank you for the Shortest Explanation
I was able to work out with vb.net using your help
Srinivas
Add the itextsharp.dll in the references
Add 2 command buttons
Add 6 text boxes
Add the Class MetaData with in the form class
copy the code in the respective places and run
Imports System
Imports System.IO
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports System.Data
Imports System.Text
Imports System.Drawing
Imports System.ComponentModel
Imports System.Collections
Private Sub Button1Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fs As FileStream
Dim sr As StreamReader
Dim mydocument As Document
Dim i As Integer
fs = New FileStream("c:\LOGFILE.txt", FileMode.Open, FileAccess.Read)
sr = New StreamReader(fs)
Dim t As String
t = "X"
While t <> ""
If i < 1 Then
t = sr.ReadToEnd
i = i + 1
mydocument = New Document
PdfWriter.GetInstance(mydocument, New FileStream("c:\csharp.pdf", FileMode.Create))
mydocument.AddTitle("SamplePDF")
mydocument.AddAuthor("Srinivas")
mydocument.AddCreator("PDM Technologies")
mydocument.AddKeywords("First testing program for checking the metada in pdf")
mydocument.AddSubject("PDF Creator")
mydocument.AddHeader("PDM Technologies", "PDM Technologies")
mydocument.Open()
mydocument.Add(New Paragraph(t))
mydocument.Close()
Else
t = sr.ReadToEnd
i = i + 1
If t <> "" Then
mydocument = New Document
PdfWriter.GetInstance(mydocument, New FileStream("c:\csharp.pdf", FileMode.Append, FileAccess.Write))
mydocument.Open()
mydocument.Add(New Paragraph(t))
mydocument.Close()
End If
End If
End While
sr.Close()
fs.Close()
End Sub
Private Sub Button2Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim fs As FileStream
Dim sw As StreamWriter
Dim mydocument As Document
Dim fr As FileStream
Dim sr As StreamReader
Dim t As String
Dim m As MemoryStream = New MemoryStream
Dim md As MetaData = New MetaData
Dim Reader As PdfReader = New PdfReader("c:\csharp.pdf")
md.info1 = Reader.Info
TextBox1.Text = md.info1("Author")
TextBox2.Text = md.info1("Subject")
TextBox3.Text = md.info1("Title")
TextBox4.Text = md.info1("Creator")
TextBox5.Text = md.info1("Producer")
TextBox6.Text = md.info1("Keywords")
End Sub
Public Class MetaData
Private info As Hashtable = New Hashtable
Public Property info1()
Get
Return info
End Get
Set(ByVal Value)
info = Value
End Set
End Property
Public Property Author() As String
Get
Return info1(Author)
End Get
Set(ByVal Value As String)
info.Add("Author", Value)
End Set
End Property
Public Property Title() As String
Get
Return info1(Title)
End Get
Set(ByVal Value As String)
info.Add("Title", Value)
End Set
End Property
Public Property Subject() As String
Get
Return info1(Subject)
End Get
Set(ByVal Value As String)
info.Add("Subject", Value)
End Set
End Property
Public Property Keywords() As String
Get
Return info1(Keywords)
End Get
Set(ByVal Value As String)
info.Add("Keywords", Value)
End Set
End Property
Public Property Producer() As String
Get
Return info1(Producer)
End Get
Set(ByVal Value As String)
info.Add("Producer", Value)
End Set
End Property
Public Property Creator() As String
Get
Return info1(Creator)
End Get
Set(ByVal Value As String)
info.Add("Creator", Value)
End Set
End Property
Public Property Version() As String
Get
Return info1(Version)
End Get
Set(ByVal Value As String)
info.Add("Version", Value)
End Set
End Property
Public Property Header() As String
Get
Return info1(Header)
End Get
Set(ByVal Value As String)
info.Add("Header", Value)
End Set
End Property
End Class -
Is there any other way to create our own schemas(Custom) for writing and reading the meta data
Please kindly help me
Thank you -
hi there,
nice and cool stuff
, but works with text files only
; what if i have images to be converted into pdf, or a word document with images. -
Hi
where i can dowload itextsharp.dll?
i can find in http://www.lowagie.com/iText/ -
Hi
where i can dowload itextsharp.dll?
i can't find in http://www.lowagie.com/iText/ -
I tried the example, but I got an error message --
Compiler Error Message: CS0117: 'iTextSharp.text.pdf.PdfWriter' does not contain a definition for 'getInstance'
I'm wondering what is wrong.
Thanks,
Mike -
I tried the example, but I got an error message --
Compiler Error Message: CS0117: 'iTextSharp.text.pdf.PdfWriter' does not contain a definition for 'getInstance'
I'm wondering what is wrong.
Thanks,
Mike -
Try:
PdfWriter.GetInstance(mydocument, New FileStream("filename.pdf", FileMode.Create));
If you're using C# it's case sensitive and the "g" needs to be uppercase.
-
I have a problem using itextsharp: I want to append a document to one existing, therefore i write:
PdfWriter.GetInstance(doc,new FileStream(filename,FileMode.Append,FileAccess.Write));
I also tried a StreamWriter:
StreamWriter sw = new StreamWriter(filename,true);
sw.AutoFlush = true;
PdfWriter.GetInstance(doc,sw.BaseStream);
Now the Problem is, that the Filesize of the pdf document is getting bigger and bigger, but I can always just see the last page added to the document
does anyone has any idea?? thx -
You can download from here
http://sourceforge.net/project/showfiles.php?group_id=72954&package_id=72901&release_id=458860
it's for CSharp (.NET)
But I need Tutorial on iTextSharp as I need to genetrate *.JTF , *.PDL file by "iTextSharp"
can any one help regards this
-
just download tutorial codes from http://blog.rubypdf.com/download
both C# and VB.NET(over 100 code examples)- iTextSharp Tutorial Codes(C#):nothing but more than 100 examples that teach you how to use iTextSharp.
- iTextSharp Tutorial Codes(VB.NET):As above but VB.NET Version.
-
This package cannot create PDF file from a string variable that contains Arabic letters
When creating PDF file of Arabic letters, there is no text in the output file.
-
Hello,I found out how to generate Arabic PDF files, here is an example:
Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2 PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("righttoleft.pdf",FileMode.Create)); // step 3document.Open();
BaseFont bf = BaseFont.CreateFont("c:\\windows\\fonts\\times.ttf", BaseFont.IDENTITY_H, true);iTextSharp.text.
Font f2 = new iTextSharp.text.Font(bf, 24, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLUE);
String atext = "اهلا"; PdfPTable table = new PdfPTable(1);table.RunDirection=
PdfWriter.RUN_DIRECTION_RTL; PdfPCell cell = new PdfPCell(new Phrase(10, atext, f2));table.AddCell(cell);
document.Add(table);
document.Close();
-
Hello,
Iam using itextsharp 4.0.2.0 and vc++.net 2003.
Could you please tell me how to create an array of image objects in Itextsharp
I tried this
iTextSharp::text::Image *in[]=new iTextSharp::text::Image[50];
for (int i=0;i<Length; i++)in[i]= iTextSharp::
text::Image::GetInstance(imgfilename[i]); //imgfilename[i]- path of image
in[i]->ScalePercent(95);
}
but it does not work.
Thanks in advance for your time.
-
Hello,
Iam using itextsharp 4.0.2.0 and vc++.net 2003.
Could you please tell me how to create an array of image objects in Itextsharp
I tried this
iTextSharp::text::Image *in[]=new iTextSharp::text::Image[50];
for (int i=0;iin[i]= iTextSharp::text::Image::GetInstance(imgfilename[i]);//imgfilename[i])- path of image
in[i]->ScalePercent(95);
}
but it does not work.
Thanks in advance for your time.
-
Hello, this code works fine and display URDU in pdf file but it did not display correctly. actually it break the font. May be there is a rendering issue in it. but i can not solve it.
so if any one can help me to resolve this issue i will be thankful to him. Thanks
Regards Ali bin zubair
!--removed tag--> -
Hi lenda,
I can't find the class iTextSharp.text.Color and the table is just added to the document without the arabic text I am using itextsharp version 5.0.2, I need to write in Arabic but it's not implemented till now
!--removed tag--> -
Hi ,
I tried this code to create pdf from text file it is working fine on button 1 click
it is creating pdf and assinging properties to it.
but when i am reading the properties value from the pdf on button2 click getting the following error.
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.String]' to type 'System.Collections.Hashtable'.
Public Property info1() Get Return info End Get Set(ByVal Value) info = Value End Set End Property
in this particular line
info = value
how to resolve that....
!--removed tag--> -
Hi,
I tried this code to create pdf from text file it is working fine on button 1 click
it is creating pdf and assinging properties to it.
but when i am reading the properties value from the pdf on button2 click getting the following error.
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.String]' to type 'System.Collections.Hashtable'.
Public Property info1() Get Return info End Get Set(ByVal Value) info = Value End Set End Property
in this particular line
info = value
how to resolve that....
!--removed tag--> -
Hi,
I tried this code to create pdf from text file it is working fine on button 1 click it is creating pdf and assinging properties to it. but when i am reading the properties value from the pdf on button2 click getting the following error.
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.String]' to type 'System.Collections.Hashtable'.
Public Property info1() Get Return info End Get Set(ByVal Value) info = Value End Set End Propertyin this particular line
info = value
how to resolve that.
!--removed tag-->
Post a reply
Quick links
Recent activity
- arif ahmad replied to How to receive data in web ...
- William Thompson replied to What is the name of the Win...
- Sameera Piyadigamage replied to Point of Sale Developers: H...
- Scott Carline replied to 4 x C# Developers for large...
- Rajendra Dhakal replied to Restore SQL Server text dat...
- cloud rainda replied to How to convert between TS f...
Enter your message below
Sign in or Join us (it's free).