Aspose.words working with Word to generate PDF documents

Source: Internet
Author: User

Aspose.words working with Word to generate PDF documents

usingaspose.words;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacetempaspose.words.function{ Public classWordtopdf {Private string_temppath;//Template Path        PrivateAspose.Words.Document doc =NULL;  PublicWordtopdf (stringTempPath) {             This. _temppath =TempPath; Doc=NewAspose.Words.Document (TempPath);//new An Object        }        /// <summary>        ///Insert a value at a bookmark/// </summary>        /// <param name= "key" ></param>        /// <param name= "value" ></param>        /// <returns></returns>         Public BOOLInsertvalue (stringKeystringvalue) {Bookmark Bookmark=Doc.            Range.bookmarks[key]; //determine if this label exists            if(Bookmark! =NULL) {bookmark. Text=value; return true; }            Else {                return false; }        }        /// <summary>        ///insert a picture at a bookmark/// </summary>        /// <param name= "key" >Bookmark</param>        /// <param name= "img" >Image</param>        /// <param name= "width" >Wide</param>        /// <param name= "height" >High</param>        /// <returns></returns>         Public BOOLInsertimage (stringKeystringImgDoubleWidthDoubleheight) {Documentbuilder Dbuilder=NewDocumentbuilder (DOC); BOOLPic =Dbuilder.movetobookmark (key); //determine if a bookmark exists            if(pic) {dBuilder.ParagraphFormat.Alignment=Paragraphalignment.center;                Dbuilder.insertimage (img, width, height); return true; }            Else {                return false; }                   }        #regionInsert table, not tested Public BOOLInsertdataset () {Try{System.Data.DataSet DataSet=NewSystem.Data.DataSet (); Doc.                Mailmerge.executewithregions (DataSet); return true; }            Catch(Exception ex) {return false; }        }         Public BOOLInserttable (stringkey,system.data.datatable DT) {            Try{documentbuilder Dbuilder=NewDocumentbuilder (DOC); BOOLTable =Dbuilder.movetobookmark (key); Dbuilder.starttable ();//Start Drawing TableDBuilder.ParagraphFormat.Alignment =Paragraphalignment.center; //Add a Word tableDbuilder.insertcell (); DBuilder.CellFormat.Width=600.0; DBuilder.CellFormat.PreferredWidth= Aspose.Words.Tables.PreferredWidth.FromPoints ( the); DBuilder.CellFormat.Borders.LineStyle=Linestyle.none; Dbuilder.starttable ();//Start Drawing TableDBuilder.RowFormat.Height =20.2;                Dbuilder.insertcell (); DBuilder.CellFormat.Borders.LineStyle=Linestyle.single; DBuilder.Font.Size=10.5; Dbuilder.bold=false; Dbuilder.write ("Marking Person"); DBuilder.CellFormat.VerticalAlignment= Aspose.Words.Tables.CellVerticalAlignment.Center;//align vertically with centerDBuilder.ParagraphFormat.Alignment =Paragraphalignment.center; DBuilder.CellFormat.Width=50.0; DBuilder.CellFormat.PreferredWidth= Aspose.Words.Tables.PreferredWidth.FromPoints ( -); DBuilder.RowFormat.Height=20.0;                Dbuilder.insertcell (); DBuilder.CellFormat.Borders.LineStyle=Linestyle.single; DBuilder.Font.Size=10.5; Dbuilder.bold=false; Dbuilder.write ("score"); DBuilder.CellFormat.VerticalAlignment= Aspose.Words.Tables.CellVerticalAlignment.Center;//align vertically with centerDBuilder.ParagraphFormat.Alignment =Paragraphalignment.center; DBuilder.CellFormat.Width=50.0; DBuilder.CellFormat.PreferredWidth= Aspose.Words.Tables.PreferredWidth.FromPoints ( -);                Dbuilder.endrow (); DBuilder.RowFormat.Height=25.0;                Dbuilder.insertcell (); DBuilder.RowFormat.Height=25.0;                Dbuilder.insertcell ();                Dbuilder.endrow ();                Dbuilder.endtable ();                Dbuilder.insertcell (); DBuilder.CellFormat.Width=300.0; DBuilder.CellFormat.PreferredWidth=Aspose.Words.Tables.PreferredWidth.Auto; DBuilder.CellFormat.Borders.LineStyle=Linestyle.none; //dBuilder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;//align vertically with center//dBuilder.ParagraphFormat.Alignment = Paragraphalignment.left; //dBuilder.Font.Size = 11; //Dbuilder.bold = true; //Dbuilder.write (Handtext); //Dbuilder.endrow (); //dBuilder.RowFormat.Height =;dbuilder.endtable (); return true; }            Catch(Exception ex) {return false; }            }        #endregion        /// <summary>        ///Save File/// </summary>        /// <param name= "path" >file path</param>        /// <param name= "Foemat" >file format, enumeration</param>        /// <returns></returns>         Public BOOLSaveFile (stringpath, SaveFormat Foemat) {            Try{doc.                Save (path, Foemat); return true; }            Catch(Exception ex) {return false; }        }    }}
aspose.words working with Word to generate PDF documents

Aspose.words working with Word to generate PDF documents

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.