Problem with converting .doc file to .pdf file and also filling it with some details using iTextSharp

Hello Mate,

                    I am having a problem in converting a .doc file in to .pdf file using iTextSharp.dll .And also i would like to wirte some details in to the form. the problem is the conversion of .doc to .pdf file is not working and also filling in to the converted .pdf file is also not working.Could you please tell me a solution?


This is my code

 in this below method i am passing the full path of an existing .doc file

public void Convert_And_Fill(string filepath)


StreamReader sr;

sr = File.OpenText(filepath); 

String strpdf = sr.ReadToEnd();


FileInfo f1 = new FileInfo(filepath);

string delim = ".";

char[] delimiter11 = delim.ToCharArray();string[] docfilename = Convert.ToString(f1.Name).Split(delimiter11);


Document document = new Document();


string newpdffile = Server.MapPath("~/Admin/FormUpload/" + docfilename[0] + ".pdf");

PdfWriter.GetInstance(document, new FileStream(newpdffile, FileMode.Create));


new Paragraph(strpdf));



FillForm(filename, newpdffile);

FileInfo file = new FileInfo(strCompleteFilePath);

//Checking if file exists

if (file.Exists)


DateTime start_time = DateTime.Now;

//Clear the content of the response


//LINE1: Add the file name and attachment, which will force the open/cance/save dialog to show, to the header

Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);

//Add the file size into the response header

Response.AddHeader("Content-Length", file.Length.ToString());

//Set the ContentType

//Response.ContentType = ReturnExtension(file.Extension.ToLower());

//Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)







And the Method used to fill in the pdf document is


private void FillForm(string filename, string filepath)




string pdfTemplate = filepath;string newFile = Server.MapPath("~/Admin/FormUpload/completed_" + filename);

strCompleteFilePath = newFile;

PdfReader pdfReader = new PdfReader(pdfTemplate);

PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(

newFile, FileMode.Create));

AcroFields pdfFormFields = pdfStamper.AcroFields;

object[] Parameters = new object[1];

Parameters[0] = Session["UserName"].ToString();DataSet dsattorney = new DataSet();

dsattorney = aobj.GetLawyer_Details(Parameters);//here i am getting the values from the database to fill in to the pdf document.

if (dsattorney.Tables.Count != 0 && dsattorney.Tables[0].Rows.Count != 0)


string fname = dsattorney.Tables[0].Rows[0]["NAME"].ToString();

string mname = dsattorney.Tables[0].Rows[0]["MIDDLE_INITIAL"].ToString();

string lname = dsattorney.Tables[0].Rows[0]["LAST_NAME"].ToString();

string name = fname + " " + mname + " " + lname;

string add1 = dsattorney.Tables[0].Rows[0]["STREET_ADD"].ToString();

string add2 = dsattorney.Tables[0].Rows[0]["CITY"].ToString();

string address = add1 + " " + add2;

string add3 = dsattorney.Tables[0].Rows[0]["STATE"].ToString();

string mobile = dsattorney.Tables[0].Rows[0]["MOBILE"].ToString();

string fax = dsattorney.Tables[0].Rows[0]["FAX"].ToString();string email = dsattorney.Tables[0].Rows[0]["EMAIL"].ToString();


pdfFormFields.SetField("FillText87", name);

pdfFormFields.SetField("FillText86", address);

pdfFormFields.SetField("FillText84", add3);

pdfFormFields.SetField("FillText82", mobile);

pdfFormFields.SetField("FillText80", email);

pdfFormFields.SetField("FillText81", fax);


// report by reading values from completed PDF

string sTmp = "W-4 Completed for " + pdfFormFields.GetField("f1_09(0)") + " " + pdfFormFields.GetField("f1_10(0)");

// flatten the form to remove editting options, set it to false

// to leave the form open to subsequent manual edits

pdfStamper.FormFlattening = false;

// close the pdf



catch (Exception ex)


throw ex;



Much Obliged & Thanks a Lot,
12/16/2008 9:31:05 AM 1793 articles. 0 followers. Follow

0 Replies

Similar Articles

[PageSpeed] 19


Similar Artilces:

How to convert .tiff image file to .pdf file without using any 3rd party tool using
HI allI have a urgent requirement i want to convert .tiff image to .pdf file Thanks in advance Regards RaviPlease click "mark as answer" if this post helped you. I dont think its possible without doing a lot of code or using third party tools, but if you  are looking for a free tool you can try a combination of Thanks and RegardsS.K.Vignesh----------------------Do remember to "Mark as answer" for this pos...

how to convert html file (with tables) to pdf file using iTextSharp.
hello, i searched a lot and also look at iTextsharp tutorials but didn't find any solutions. i have a html file which contains a table. and i try to convert it into pdf using iTextSharp but it doesn't work. here is my code:string inputFile =@"C:\Try.htm";string outputfile =@"C:\try.pdf";            try            {                // step 1: creation of a document-object  &...

convert .doc file to .pdf file in C#
Hello,I need to convert a .doc file to .pdf file in dot net using C# . Any help will be highly appreciated. Thanks Hello, Please check the link below. Hope it will help you, do let me know if it helps you.S.SRIRAM Thanks for your reply but it is not working.  Hello, What problem you r facing?.. Alternate links are here. .... Please let me know if you still face issues,  S.SRIRAM Hi, Based on my understanding, you should belon...

COnverting image file into PDF file in C#.NET
hi friends, i have a problem in creating a PDF file from an image file. first of all pls clarify what is the internal concept in converting to PDF file. if nay one knows pls mail me the related code if you find any solution pls mail me at thank u all hari babu...

Convert Gridview Data in to PDf file. or Convert report data in pdf file
 Hi have problem to convert Gridview data into PDF file..let me know is there any solution or open source components..Regards Rambhopal Reddy EPlease remember to click “Mark as Answer” on the post that helps you, and to click “Unmark asAnswer” if a marked post does not actually answer your question. Friend, Check this thread for soultions and then to   Good luck!     Please Don't forget to click "Mark as Answer" on the post that helped you.This can be benef...

web services used to convert Word files to PDF files
My professor asked me to design a web services which convert Microsoft's word files to PDF files. by use VS.NET and Windows Server 2003. After I installe Adode Acrobat 6.0 Professional, I can find some Acrobat components, Acrobat Distiller, Acrobat Web Capture 1.0 Type Library, etc. Please tell me which one can be used for my project and how to use it. Or please tell me popular free components of third parts. Thanks!...

Convert Word DOC File to Adobe Acrobat PDF file
Hello, Does anyone knows a component to convert an Word DOC File to Adobe Acrobat PDF file? I am creating a web site where people upload word  Word DOC files to the server. I need to convert the Word Doc files into PDF files as they are uploaded. Thanks, Miguel shapper--Regarding this... shapper wrote:...Does anyone knows a component to convert an Word DOC File to Adobe Acrobat PDF file?......I am creating a web site where people upload word  Word DOC files to the server. I need to convert the Word Doc files into PDF files as they are should ...

problems in converting doc to pdf using itextsharps
Hi friends,i need help for this problem.......i am having a doc document and want to convert into pdf and i have come to a situation where my code is not passing any error but it is not converting doc to pdf solution is like this........1)Get the doc file and convert it into html........2)Save that html and parse it in pdf using htmlparser of itextsharp.Now my code is working properly for doc to html and also the file is saved in to html but here is i am having problem....problem1)I dont know how to dispose COM resources.problem2)After running the html to pdf code when i open...

PDF files and DOC files
Name: Jeff Kopacz Email: Product: Firefox Summary: PDF files and DOC files Comments: When using Firefox and have to view a pdf file or Doc file I have to have Adobe Reader or Word started before selecting the file or the computer will lockup. I am using XP and Firefox 1.0.7. If I use either IE or Netscape they will open properly. This has recently occured with either version 6 or 7 Browser Details: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7 ...

How to convert a pdf file to text format using .net
Hi all, I want to convert a PDF format file to a text format file(i.e., Wordpad or Notepad).For this i have to use .Net only. Plz send replies urgently. tnx ramesh...

silent print a pdf / doc file using
hi,i need code to print a pdf / doc file silently without opening the pdf / word document  and i need to select local / network printer and i need to select the file to print , all these things should be done in application can any one give me the code for this i need this very urgently by tomorrow   ...

problem with editing the content of pdf file using
hi all.... is the any way to edit the bookmark in a pdf file ...... for exmaple replace some string and save it... like replace("abcde","lmnop") is it possible to do it ? thanks  you can define variables in PDF Files and can access those variables programtically than change values of that required variable and save you pdf againIf this post helps you, please mark it as Answer.Cheers,Muhammad Rizwan JavedSr .Net DeveloperAim 168, Dubai, UAE. thanks for ur help..... u got any reference on this...... sorry ...cos i am new to pdf actions in thanks &nb...

How to convert an RTF File to a PDF File?
Hello, I am using Powerbuilder 10.5.1 build 6565 and the following code to convert an RTF File to a PDF File. rte_1.SaveDocument("test.pdf", FileTypePDF!) But, it fails when I install my app on a different ws. What are the DLLs that I need to copy to the ws? Do I need to install Ghostscript or Adobe Writer? Thanks, Attilio Attilio, 10.5 has a new RichText control. It requires the files located in this directory: C:\Program Files\Sybase\Shared\PowerBuilder\rtc Roland <Attilio> wrote in message > Hell...

How to convert a PCL file into a PDF file?
How do I convert a PCL file into a PDF file for printing/saving purposes(possibly using Amyuni PDF converter)? Thank you! You would need a 3rd party tool. A search in Google found many results: Brad Alex wrote: > How do I convert a PCL file into a PDF file for > printing/saving purposes(possibly using Amyuni PDF > converter)? > > Thank you! ...

Web resources about - Problem with converting .doc file to .pdf file and also filling it with some details using iTextSharp -

PastBook’s Integration Eases Process Of Converting Facebook Content To Books
PastBook , one of several companies that allow Facebook users to publish their content on the social network in actual books , announced the ...

Facebook No Longer Converting Groups Into Pages
Back when Facebook first launched Facebook Pages, many businesses and brands who had built up substantial audiences in their Facebook Groups ...

Zwartz Laminating-Converting B.V. on the App Store on iTunes
Get Zwartz Laminating-Converting B.V. on the App Store. See screenshots and ratings, and read customer reviews.

"Occupier" Thanked Former Soviet Citizen for "Converting" Him to Capitalism, Pro-Israel, Pro-USA - YouTube ...
May Day Demonstration on Union Square in New York City Zionism & Birth of Modern Israel in 1948: Former Soviet Citizen Pays Tribute to Ben-Gurion ...

Click go fears of converting print files
Is there a way to convert a print queue item to a .RTF or .PDF file? I like to save or email them. - The Sydney Morning Herald

Sudanese woman ordered to hang under sharia law for converting to Christianity gives birth
Khartoum, Sudan: A Christian Sudanese woman sentenced to hang for apostasy has given birth in jail, a Western diplomat said on Tuesday.

Imams warn against radicalism to Aboriginal inmates converting to Islam
The prison system has enlisted the help of ASIO to crack down on radicalisation behind bars amid revelations that Aboriginals are converting ...

Converting the world's companies one by one - The Science Show - ABC Radio National (Australian Broadcasting ...
Image: Trucks carrying logs make their way up a road in Jambi, Indonesia. A vast area of the Sumatran forest, and orangutan habitat, is being ...

Converting Churches Into Homes Is The Latest Hollywood Trend
You don't have to be a believer to be moved by the beauty of a church.

Resources last updated: 11/23/2015 11:13:54 PM