本文整理汇总了C#中Novacode.DocX.AddImage方法的典型用法代码示例。如果您正苦于以下问题:C# DocX.AddImage方法的具体用法?C# DocX.AddImage怎么用?C# DocX.AddImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Novacode.DocX
的用法示例。
在下文中一共展示了DocX.AddImage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public TemplGraphic Load(DocX doc)
{
if (!Loaded)
{
Image = doc.AddImage(Data);
Loaded = true;
}
return this;
}
示例2: CreateImage
private static void CreateImage(DocX doc)
{
try
{
string imgPath = "rpg-game.png";
var pic = doc.AddImage(imgPath).CreatePicture();
var drawingImg = System.Drawing.Image.FromFile(imgPath);
int ratio = drawingImg.Width / drawingImg.Height;
int newWidth = (int)doc.PageWidth - (int)(doc.MarginLeft + doc.MarginRight);
pic.Width = newWidth;
pic.Height = newWidth / ratio;
doc.InsertParagraph().InsertPicture(pic);
}
catch (System.IO.FileNotFoundException ex)
{
System.Console.WriteLine(ex.Message);
}
}
示例3: InsertPicture
private static void InsertPicture(DocX doc, string filename, Formatting format)
{
using (MemoryStream memoryStream = new MemoryStream())
{
System.Drawing.Image myImg = System.Drawing.Image.FromFile(filename);
myImg.Save(memoryStream, myImg.RawFormat); // Save your picture in a memory stream.
memoryStream.Seek(0, SeekOrigin.Begin);
Novacode.Image img = doc.AddImage(memoryStream); // Create image.
Paragraph p = doc.InsertParagraph("", false);
Picture pic1 = img.CreatePicture(); // Create picture.
p.InsertPicture(pic1, 0); // Insert picture into paragraph.
doc.Save();
}
}
示例4: CreateInvoiceFromTemplate
// Create an invoice for a factitious company called "The Happy Builder".
private static DocX CreateInvoiceFromTemplate(DocX template)
{
#region Logo
// A quick glance at the template shows us that the logo Paragraph is in row zero cell 1.
Paragraph logo_paragraph = template.Tables[0].Rows[0].Cells[1].Paragraphs[0];
// Remove the template Picture that is in this Paragraph.
logo_paragraph.Pictures[0].Remove();
// Add the Happy Builders logo to this document.
RelativeDirectory rd = new RelativeDirectory(); // prepares the files for testing
rd.Up(2);
Image logo = template.AddImage(rd.Path + @"\images\logo_the_happy_builder.png");
// Insert the Happy Builders logo into this Paragraph.
logo_paragraph.InsertPicture(logo.CreatePicture());
#endregion
#region Set CustomProperty values
// Set the value of the custom property 'company_name'.
template.AddCustomProperty(new CustomProperty("company_name", "The Happy Builder"));
// Set the value of the custom property 'company_slogan'.
template.AddCustomProperty(new CustomProperty("company_slogan", "No job too small"));
// Set the value of the custom properties 'hired_company_address_line_one', 'hired_company_address_line_two' and 'hired_company_address_line_three'.
template.AddCustomProperty(new CustomProperty("hired_company_address_line_one", "The Crooked House,"));
template.AddCustomProperty(new CustomProperty("hired_company_address_line_two", "Dublin,"));
template.AddCustomProperty(new CustomProperty("hired_company_address_line_three", "12345"));
// Set the value of the custom property 'invoice_date'.
template.AddCustomProperty(new CustomProperty("invoice_date", DateTime.Today.Date.ToString("d")));
// Set the value of the custom property 'invoice_number'.
template.AddCustomProperty(new CustomProperty("invoice_number", 1));
// Set the value of the custom property 'hired_company_details_line_one' and 'hired_company_details_line_two'.
template.AddCustomProperty(new CustomProperty("hired_company_details_line_one", "Business Street, Dublin, 12345"));
template.AddCustomProperty(new CustomProperty("hired_company_details_line_two", "Phone: 012-345-6789, Fax: 012-345-6789, e-mail: [email protected]"));
#endregion
/*
* InvoiceTemplate.docx contains a blank Table,
* we want to replace this with a new Table that
* contains all of our invoice data.
*/
Table t = template.Tables[1];
Table invoice_table = CreateAndInsertInvoiceTableAfter(t, ref template);
t.Remove();
// Return the template now that it has been modified to hold all of our custom data.
return template;
}