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