本文整理汇总了C#中Document.SaveToFile方法的典型用法代码示例。如果您正苦于以下问题:C# Document.SaveToFile方法的具体用法?C# Document.SaveToFile怎么用?C# Document.SaveToFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.SaveToFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Button1_Click
protected void Button1_Click(object sender, System.EventArgs e)
{
//Create word document
Document document = new Document();
InsertWatermark(document);
//Save doc file.
document.SaveToFile("Sample.doc", FileFormat.Doc,Response, HttpContentType.Attachment);
}
示例2: Convert
public String Convert(String sourceFile)
{
Document document = new Document();
document.LoadFromFile(sourceFile);
var fileName = String.Format("{0}.pdf",Path.GetFileNameWithoutExtension(sourceFile));
var fullPath = String.Format("{0}{1}", _storageRootTemp, fileName);
document.SaveToFile(fullPath, FileFormat.PDF);
return fileName;
}
示例3: DocTest
public void DocTest()
{
const string fileName = "shay.pdf";
var doc = new Document();
var section = doc.AddSection();
// var table = section.AddTable(false);
// var row = table.AddRow();
// var cell = row.AddCell();
var baseArea = section.AddParagraph();
var rang = baseArea.AppendText("试卷标题123456【A卷】");
rang.CharacterFormat.FontSize = 14;
rang.CharacterFormat.Bold = true;
rang.CharacterFormat.FontName = "宋体";
doc.SaveToFile(fileName, FileFormat.PDF);
Process.Start(fileName);
}
示例4: autoFillDocument
public static void autoFillDocument(string templateURL, string filepath, Claim claim, bool isHeader = false)
{
Document document = new Document();
// load document template
//document.LoadFromFile(templateURL, FileFormat.Doc);
document.LoadFromFile(templateURL, FileFormat.Auto);
// load merge fields
loadFieldValues(claim);
//if (isHeader)
// setHeader(document, lead.Client);
document.MailMerge.Execute(fieldNames, fieldValues);
document.SaveToFile(filepath, FileFormat.Doc);
//document.SaveToFile(filepath, FileFormat.Auto);
document.Close();
document = null;
}
示例5: CameraReadySubmission
public ActionResult CameraReadySubmission([Bind(Include = "PaperId,ConferenceId,UserId,PaperTitle,AuthorList,Co_Author,Affiliation,Presenter,Abstract,PaperDescription,AbstractFile,FullPaperFile,CameraReadyPaperFile,Keywords,TopicId,Prefix,AbstractSubmissionDate,FullPaperSubmissionDate,CameraReadyPaperSubmissionDate,AbstractSubmissionNotification,TotalNumberOfPages,Marks")] Paper paper)
{
try
{
Conference conference = db.Conferences.FirstOrDefault(u => u.ConferenceId == paper.ConferenceId);
AbstractFileFormat fileformat = db.AbstractFileFormats.FirstOrDefault(u => u.ConferenceId == paper.ConferenceId);
string filePath = FileUrl(paper.CameraReadyPaperFile, paper.Prefix);
string wordFilePath = WordFileUrl(paper.CameraReadyPaperFile, paper.Prefix);
if (fileformat != null)
{
Document doc = new Document();
doc.LoadFromFile(wordFilePath);
int count = 0;
int styleName = 0;
foreach (Section section in doc.Sections)
{
foreach (Paragraph paragraph in section.Paragraphs)
{
paragraph.Format.LineSpacing = (float)fileformat.LineSpacing;
string text = paragraph.Text.ToLower();
if (text.Length > 0 && text.Equals("abstract"))
{
count = 1;
}
if (text.Length > 1 && count == 1)
{
ParagraphStyle style = new ParagraphStyle(doc);
paragraph.Format.HorizontalAlignment = HorizontalAlignment.Left;
style.Name = styleName.ToString();
style.CharacterFormat.FontName = fileformat.FontName.Name;
style.CharacterFormat.FontSize = fileformat.FontSize;
doc.Styles.Add(style);
paragraph.ApplyStyle(style.Name);
}
styleName++;
}
section.PageSetup.Margins.Top = (float)fileformat.Margin_Top;
section.PageSetup.Margins.Bottom = (float)fileformat.Margin_Bottom;
section.PageSetup.Margins.Left = (float)fileformat.Margin_Left;
section.PageSetup.Margins.Right = (float)fileformat.Margin_Right;
}
doc.SaveToFile(wordFilePath);
}
paper.CameraReadyPaperSubmissionDate = DateTime.Now.ToString();
paper.CameraReadyPaperFile = filePath;
if (ModelState.IsValid)
{
db.Entry(paper).State = EntityState.Modified;
db.SaveChanges();
}
return RedirectToAction("CameraReadyIndex", new { id = paper.ConferenceId });
}
catch
{
ViewBag.ConferenceId = new SelectList(db.Conferences, "ConferenceId", "Username", paper.ConferenceId);
ViewBag.TopicId = new SelectList(db.Topics, "TopicId", "Name", paper.TopicId);
ViewBag.UserId = new SelectList(db.Users, "UserId", "Email", paper.UserId);
return View(paper);
}
}
示例6: Create
public ActionResult Create([Bind(Include= "PaperTitle,AuthorList,Affiliation,Presenter,AbstractFile,Abstract,Keywords,TopicId,TotalNumberOfPages")] Paper paper)
{
try
{
int userId = (int)Session["sessionLoggedInUserId"];
var submission = new Paper();
submission.PaperTitle = paper.PaperTitle;
submission.AuthorList = paper.AuthorList;
submission.Affiliation = paper.Affiliation;
submission.Presenter = paper.Presenter;
submission.Abstract = paper.Abstract;
submission.Keywords = paper.Keywords;
submission.TopicId = paper.TopicId;
submission.UserId = userId;
submission.AbstractTotalNumberOfPages = paper.AbstractTotalNumberOfPages;
submission.ConferenceId = (int)Session["ConferenceId"];
Conference conference = db.Conferences.FirstOrDefault(u => u.ConferenceId == submission.ConferenceId);
AbstractFileFormat fileformat = db.AbstractFileFormats.FirstOrDefault(u => u.ConferenceId == submission.ConferenceId);
Paper papers = db.Papers.FirstOrDefault(u => u.ConferenceId == submission.ConferenceId);
if(papers == null)
{
submission.Prefix = conference.PaperPrefix + 1;
}
else
{
Paper last = db.Papers.OrderByDescending(u => u.PaperId).FirstOrDefault(u => u.ConferenceId == submission.ConferenceId);
string[] word = last.Prefix.Split('-');
int paperNumber = Int32.Parse(word[1].ToString()) + 1;
submission.Prefix = conference.PaperPrefix + paperNumber;
}
string filePath = FileUrl(paper.AbstractFile, submission.Prefix);
string wordFilePath = WordFileUrl(paper.AbstractFile, submission.Prefix);
if (fileformat != null)
{
Document doc = new Document();
doc.LoadFromFile(wordFilePath);
submission.AbstractTotalNumberOfPages = doc.PageCount;
int count = 0;
int styleName = 0;
foreach (Section section in doc.Sections)
{
foreach (Paragraph paragraph in section.Paragraphs)
{
paragraph.Format.LineSpacing = (float)fileformat.LineSpacing;
string text = paragraph.Text.ToLower();
if (text.Length > 0 && text.Equals("abstract"))
{
count = 1;
}
if (text.Length > 1 && count == 1)
{
ParagraphStyle style = new ParagraphStyle(doc);
paragraph.Format.HorizontalAlignment = HorizontalAlignment.Left;
style.Name = styleName.ToString();
style.CharacterFormat.FontName = fileformat.FontName.Name;
style.CharacterFormat.FontSize = fileformat.FontSize;
doc.Styles.Add(style);
paragraph.ApplyStyle(style.Name);
}
styleName++;
}
section.PageSetup.Margins.Top = (float)fileformat.Margin_Top;
section.PageSetup.Margins.Bottom = (float)fileformat.Margin_Bottom;
section.PageSetup.Margins.Left = (float)fileformat.Margin_Left;
section.PageSetup.Margins.Right = (float)fileformat.Margin_Right;
}
doc.SaveToFile(wordFilePath);
}
submission.AbstractSubmissionDate = DateTime.Now.ToString();
submission.AbstractFile = filePath;
db.Papers.Add(submission);
db.SaveChanges();
return RedirectToAction("Index", new { id = submission.UserId });
}
catch
{
ViewBag.ConferenceId = new SelectList(db.Conferences, "ConferenceId", "Username");
ViewBag.TopicId = new SelectList(db.Topics, "TopicId", "Name");
ViewBag.UserId = new SelectList(db.Users, "UserId", "Email");
return View(paper);
}
}