本文整理汇总了C#中DocumentBuilder.InsertImage方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentBuilder.InsertImage方法的具体用法?C# DocumentBuilder.InsertImage怎么用?C# DocumentBuilder.InsertImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentBuilder
的用法示例。
在下文中一共展示了DocumentBuilder.InsertImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Check for license and apply if exists
string licenseFile = AppDomain.CurrentDomain.BaseDirectory + "Aspose.Words.lic";
if (File.Exists(licenseFile))
{
// Apply Aspose.Words API License
Aspose.Words.License license = new Aspose.Words.License();
// Place license file in Bin/Debug/ Folder
license.SetLicense("Aspose.Words.lic");
}
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Image Before ReSize");
//insert image from disk
Shape shape = builder.InsertImage(@"../../data/aspose_Words-for-net.jpg");
// write text in document
builder.Write("Image After ReSize ");
//insert image from disk for resize
shape = builder.InsertImage(@"../../data/aspose_Words-for-net.jpg");
// To change the shape size. ( ConvertUtil Provides helper functions to convert between various measurement units. like Converts inches to points.)
shape.Width = ConvertUtil.InchToPoint(0.5);
shape.Height = ConvertUtil.InchToPoint(0.5);
// save new document
builder.Document.Save("ImageReSize.doc");
}
示例2: Iso29500Strict
public void Iso29500Strict()
{
//ExStart
//ExFor:OoxmlCompliance.Iso29500_2008_Strict
//ExSummary:Shows conversion vml shapes to dml using Iso29500_2008_Strict option
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
//Set Word2003 version for document, for inserting image as vml shape
doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2003);
Shape image = builder.InsertImage(MyDir + @"dotnet-logo.png");
// Loop through all single shapes inside document.
foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
{
Assert.AreEqual(ShapeMarkupLanguage.Vml, shape.MarkupLanguage);
}
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
saveOptions.Compliance = OoxmlCompliance.Iso29500_2008_Strict; //Iso29500_2008 does not allow vml shapes, so you need to use OoxmlCompliance.Iso29500_2008_Strict for converting vml to dml shapes
saveOptions.SaveFormat = SaveFormat.Docx;
MemoryStream dstStream = new MemoryStream();
doc.Save(dstStream, saveOptions);
//Assert that image have drawingML markup language
foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
{
Assert.AreEqual(ShapeMarkupLanguage.Dml, shape.MarkupLanguage);
}
//ExEnd
}
示例3: CreateFloatingPositionSize
public void CreateFloatingPositionSize()
{
//ExStart
//ExFor:ShapeBase.Left
//ExFor:ShapeBase.Top
//ExFor:ShapeBase.Width
//ExFor:ShapeBase.Height
//ExFor:DocumentBuilder.CurrentSection
//ExFor:PageSetup.PageWidth
//ExSummary:Shows how to insert a floating image and specify its position and size.
// This creates a builder and also an empty document inside the builder.
DocumentBuilder builder = new DocumentBuilder();
// By default, the image is inline.
Shape shape = builder.InsertImage(ExDir + "Hammer.wmf");
// Make the image float, put it behind text and center on the page.
shape.WrapType = WrapType.None;
// Make position relative to the page.
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
// Make the shape occupy a band 50 points high at the very top of the page.
shape.Left = 0;
shape.Top = 0;
shape.Width = builder.CurrentSection.PageSetup.PageWidth;
shape.Height = 50;
builder.Document.Save(ExDir + "Image.CreateFloatingPositionSize Out.doc");
//ExEnd
}
示例4: AddImageToPage
/// <summary>
/// Adds an image to a page using the supplied paragraph.
/// </summary>
/// <param name="para">The paragraph to an an image to.</param>
/// <param name="page">The page number the paragraph appears on.</param>
public static void AddImageToPage(Paragraph para, int page)
{
Document doc = (Document)para.Document;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveTo(para);
// Add a logo to the top left of the page. The image is placed infront of all other text.
Shape shape = builder.InsertImage(gDataDir + "Aspose Logo.png", RelativeHorizontalPosition.Page, 60,
RelativeVerticalPosition.Page, 60, -1, -1, WrapType.None);
// Add a textbox next to the image which contains some text consisting of the page number.
Shape textBox = new Shape(doc, ShapeType.TextBox);
// We want a floating shape relative to the page.
textBox.WrapType = WrapType.None;
textBox.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
textBox.RelativeVerticalPosition = RelativeVerticalPosition.Page;
// Set the textbox position.
textBox.Height = 30;
textBox.Width = 200;
textBox.Left = 150;
textBox.Top = 80;
// Add the textbox and set text.
textBox.AppendChild(new Paragraph(doc));
builder.InsertNode(textBox);
builder.MoveTo(textBox.FirstChild);
builder.Writeln("This is a custom note for page " + page);
}
示例5: CreateFloatingPageCenter
public void CreateFloatingPageCenter()
{
//ExStart
//ExFor:DocumentBuilder.InsertImage(string)
//ExFor:Shape
//ExFor:ShapeBase
//ExFor:ShapeBase.WrapType
//ExFor:ShapeBase.BehindText
//ExFor:ShapeBase.RelativeHorizontalPosition
//ExFor:ShapeBase.RelativeVerticalPosition
//ExFor:ShapeBase.HorizontalAlignment
//ExFor:ShapeBase.VerticalAlignment
//ExFor:WrapType
//ExFor:RelativeHorizontalPosition
//ExFor:RelativeVerticalPosition
//ExFor:HorizontalAlignment
//ExFor:VerticalAlignment
//ExSummary:Shows how to insert a floating image in the middle of a page.
// This creates a builder and also an empty document inside the builder.
DocumentBuilder builder = new DocumentBuilder();
// By default, the image is inline.
Shape shape = builder.InsertImage(ExDir + "Aspose.Words.gif");
// Make the image float, put it behind text and center on the page.
shape.WrapType = WrapType.None;
shape.BehindText = true;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.HorizontalAlignment = HorizontalAlignment.Center;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
shape.VerticalAlignment = VerticalAlignment.Center;
builder.Document.Save(ExDir + "Image.CreateFloatingPageCenter Out.doc");
//ExEnd
}
示例6: Main
static void Main(string[] args)
{
Document doc = new Document("../../data/document.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertImage("../../data/HumpbackWhale.jpg");
doc.Save("insertedImage.docx");
}
示例7: CreateFromUrl
public void CreateFromUrl()
{
//ExStart
//ExFor:DocumentBuilder.InsertImage(string)
//ExFor:DocumentBuilder.Writeln
//ExSummary:Shows how to inserts an image from a URL. The image is inserted inline and at 100% scale.
// This creates a builder and also an empty document inside the builder.
DocumentBuilder builder = new DocumentBuilder();
builder.Write("Image from local file: ");
builder.InsertImage(MyDir + "Aspose.Words.gif");
builder.Writeln();
builder.Write("Image from an internet url, automatically downloaded for you: ");
builder.InsertImage("http://www.aspose.com/Images/aspose-logo.jpg");
builder.Writeln();
builder.Document.Save(MyDir + @"\Artifacts\Image.CreateFromUrl.doc");
//ExEnd
}
示例8: ConvertImageToPdf
/// <summary>
/// Converts an image to PDF using Aspose.Words for .NET.
/// </summary>
/// <param name="inputFileName">File name of input image file.</param>
/// <param name="outputFileName">Output PDF file name.</param>
public static void ConvertImageToPdf(string inputFileName, string outputFileName)
{
Console.WriteLine("Converting " + inputFileName + " to PDF ....");
// ExStart:ConvertImageToPdf
// Create Document and DocumentBuilder.
// The builder makes it simple to add content to the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Read the image from file, ensure it is disposed.
using (Image image = Image.FromFile(inputFileName))
{
// Find which dimension the frames in this image represent. For example
// The frames of a BMP or TIFF are "page dimension" whereas frames of a GIF image are "time dimension".
FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);
// Get the number of frames in the image.
int framesCount = image.GetFrameCount(dimension);
// Loop through all frames.
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
{
// Insert a section break before each new page, in case of a multi-frame TIFF.
if (frameIdx != 0)
builder.InsertBreak(BreakType.SectionBreakNewPage);
// Select active frame.
image.SelectActiveFrame(dimension, frameIdx);
// We want the size of the page to be the same as the size of the image.
// Convert pixels to points to size the page to the actual image size.
PageSetup ps = builder.PageSetup;
ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
// Insert the image into the document and position it at the top left corner of the page.
builder.InsertImage(
image,
RelativeHorizontalPosition.Page,
0,
RelativeVerticalPosition.Page,
0,
ps.PageWidth,
ps.PageHeight,
WrapType.None);
}
}
// Save the document to PDF.
doc.Save(outputFileName);
// ExEnd:ConvertImageToPdf
}
示例9: InsertInlineImage
public static void InsertInlineImage(string dataDir)
{
// ExStart:DocumentBuilderInsertInlineImage
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertImage(dataDir + "Watermark.png");
dataDir = dataDir + "DocumentBuilderInsertInlineImage_out.doc";
doc.Save(dataDir);
// ExEnd:DocumentBuilderInsertInlineImage
Console.WriteLine("\nInline image using DocumentBuilder inserted successfully.\nFile saved at " + dataDir);
}
示例10: Main
static void Main(string[] args)
{
string MyDir = "";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
//Add picture
builder.InsertImage(MyDir + "download.jpg");
doc.Save(MyDir+"Add Picture and WordArt.doc");
}
示例11: Main
static void Main(string[] args)
{
//----------------------------------------------------
// NPOI
//----------------------------------------------------
//const int emusPerInch = 914400;
//const int emusPerCm = 360000;
//XWPFDocument doc = new XWPFDocument();
//XWPFParagraph p2 = doc.CreateParagraph();
//XWPFRun r2 = p2.CreateRun();
//r2.SetText("test");
//var widthEmus = (int)(400.0 * 9525);
//var heightEmus = (int)(300.0 * 9525);
//using (FileStream picData = new FileStream("../../image/HumpbackWhale.jpg", FileMode.Open, FileAccess.Read))
//{
// r2.AddPicture(picData, (int)PictureType.PNG, "image1", widthEmus, heightEmus);
//}
//using (FileStream sw = File.Create("test.docx"))
//{
// doc.Write(sw);
//}
//----------------------------------------------------
// Aspose.Words
//----------------------------------------------------
// Check for license and apply if exists
string licenseFile = AppDomain.CurrentDomain.BaseDirectory + "Aspose.Words.lic";
if (File.Exists(licenseFile))
{
// Apply Aspose.Words API License
Aspose.Words.License license = new Aspose.Words.License();
// Place license file in Bin/Debug/ Folder
license.SetLicense("Aspose.Words.lic");
}
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("test");
var widthEmus = (int)(400.0 * 9525);
var heightEmus = (int)(300.0 * 9525);
builder.InsertImage("../../image/HumpbackWhale.jpg", widthEmus, heightEmus);
doc.Save("test.docx");
}
示例12: Main
static void Main(string[] args)
{
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertImage("Download.jpg",
RelativeHorizontalPosition.Margin,
100,
RelativeVerticalPosition.Margin,
100,
200,
100,
WrapType.Square);
doc.Save("Picture Out.doc");
}
示例13: InsertImageFromByteArrayEx
public void InsertImageFromByteArrayEx()
{
//ExStart
//ExFor:DocumentBuilder.InsertImage(Byte[])
//ExSummary:Shows how to import an image into a document from a byte array.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Prepare a byte array of an image.
Image image = Image.FromFile(MyDir + "Aspose.Words.gif");
ImageConverter imageConverter = new ImageConverter();
byte[] imageBytes = (byte[])imageConverter.ConvertTo(image, typeof (byte[]));
builder.InsertImage(imageBytes);
builder.Document.Save(MyDir + @"\Artifacts\Image.CreateFromByteArrayDefault.doc");
//ExEnd
}
示例14: InsertImageFromByteArrayEx
public void InsertImageFromByteArrayEx()
{
//ExStart
//ExFor:DocumentBuilder.InsertImage(Byte[])
//ExSummary:Shows how to import an image from a byte array into a document.
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder();
// Prepare a byte array of an image.
System.Drawing.Image image = System.Drawing.Image.FromFile(ExDir + "Aspose.Words.gif");
System.Drawing.ImageConverter imageConverter = new System.Drawing.ImageConverter();
byte[] imageBytes = (byte[])imageConverter.ConvertTo(image, typeof (byte[]));
builder.InsertImage(imageBytes);
builder.Document.Save(ExDir + "Image.CreateFromByteArray Out.doc");
//ExEnd
}
示例15: InsertImageFromByteArrayRelativePositionEx
public void InsertImageFromByteArrayRelativePositionEx()
{
//ExStart
//ExFor:DocumentBuilder.InsertImage(Byte[], RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType)
//ExSummary:Shows how to import an image from a byte array into a document using relative positions.
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder();
// Prepare a byte array of an image.
System.Drawing.Image image = System.Drawing.Image.FromFile(ExDir + "Aspose.Words.gif");
System.Drawing.ImageConverter imageConverter = new System.Drawing.ImageConverter();
byte[] imageBytes = (byte[])imageConverter.ConvertTo(image, typeof(byte[]));
builder.InsertImage(imageBytes, Aspose.Words.ConvertUtil.PixelToPoint(450), Aspose.Words.ConvertUtil.PixelToPoint(144));
builder.Document.Save(ExDir + "Image.CreateFromByteArrayRelativePosition Out.doc");
//ExEnd
}