Document doc =NewDocument (); //Fan Name stringMemberName =""; varDetail =Listdetails.firstordefault (); if(Detail! =NULL) {Servicerecord record=detail. Servicerecord; if(Record! =NULL) {Member m=record. Member; if(M! =NULL) {membername= M.firstname +" "+M.lastname; } } } Try { //Step 2: Create a writer to listen to document and point to a file via Pdf-stream stringPdfname = DateTime.Now.ToString ("YYYYMMDDHHMMSS"); if(! Directory.Exists (Server.MapPath ("~/content/pdf/")) {directory.createdirectory (Server.MapPath ("~/content/pdf/")); } stringPdfpath = Server.MapPath (string. Format ("~/content/pdf/{0}.pdf", Pdfname)); Pdfwriter.getinstance (Doc,NewFileStream (Pdfpath, FileMode.Create)); Pdfurl= request.headers["Host"] + url.content (string. Format ("~/content/pdf/{0}.pdf", Pdfname)); //Step 3: Open DocumentDoc. Open (); }//----------------Doc. ADD (Createparagraphtxt (Newlist<string>{ATC. Title}, num); Doc. ADD (Createparagraphimg (ATC. Pictureurl));//--------------------------------- //Create a text paragraph PrivateParagraph Createparagraphtxt (list<string> Listtxt,intNumBOOLIscontent =true) {Paragraph phtxt=NewParagraph ();//paragraphBasefont BF = Basefont.createfont ("c://windows//fonts//simsun.ttc,0", Basefont.identity_h, basefont.embedded); ITextSharp.text.Font Font=NewITextSharp.text.Font (BF); Phtxt.font=font; if(num%2!=0) {PhTxt.Font.SetColor ( the, -,169); } phtxt.spacingafter=Ten; intFontSize = the; foreach(varIteminchlisttxt) {Chunk Chunktxt=NewChunk (item, Fontfactory.getfont (Fontfactory.courier,"unigb-ucs2-h", basefont.embedded, fontSize)); if(iscontent) {Phtxt.indentationleft= -; } phtxt.add (Chunktxt); } returnPhtxt; } //Create a picture paragraph PrivateParagraph createparagraphimg (stringImgurl) { if(System.IO.File.Exists (Server.MapPath (Imgurl))) {Paragraph phimg=NewParagraph ();//paragraphITextSharp.text.Image JPG1 =iTextSharp.text.Image.GetInstance (Server.MapPath (Imgurl)); Jpg1. Alignment=Element.align_left; Phimg.add (JPG1); returnphimg; } return NewParagraph ("Image Load failed"); }
C # generate PDF