C # generate PDF

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.