個人目標目標要求:將一個圖片插入到頁面中,頁面邊界爲0,使用下面的代碼去實現(button1UseDocX_Click函數),生成的文檔不能達到目的。而使用Spire.Doc卻能達到目的button1UseSpireDoc_Click函數。函數
之因此要用DocX是由於Spire.的庫文件太大了,只是這一個小功能,就要30多M.orm
private void button1UseDocX_Click(object sender, EventArgs e)
{
// Create a document.
string filename = "_加頁碼.docx";圖片
using (DocX document = DocX.Create(filename + "_TEST.docx"))
{
document.InsertSection();
;
//document.InsertSection();
// Add a simple image from disk.
//document.PageWidth = 595;
//document.PageHeight = 842;
document.MarginBottom = 0;
document.MarginFooter = 0;
document.MarginHeader = 0;
document.MarginLeft = 0;
document.MarginRight = 0;
document.MarginTop = 0;
var image = document.AddImage("test1.jpg");
var picture = image.CreatePicture((int)document.PageHeight, (int)document.PageWidth);
var p = document.InsertParagraph();
p.AppendPicture(picture);
document.Save();
}文檔
private void button1UseSpireDoc_Click(object sender, EventArgs e)
{
string filename = "_輸出.docx";
//wordDocx = DocX.Create(filename);
Document document = new Document();string
//set the background type as picture.
document.Background.Type = Spire.Doc.Documents.BackgroundType.Picture;io
Spire.Doc.Section s = document.AddSection();
s.PageSetup.PageSize = Spire.Doc.Documents.PageSize.A4;
s.PageSetup.Margins.All = 0;
Spire.Doc.Documents.Paragraph p = s.AddParagraph();test
DocPicture Pic = p.AppendPicture(System.Drawing.Image.FromFile(imagefilename));
Pic.Width = s.PageSetup.PageSize.Width;
Pic.Height = s.PageSetup.PageSize.Height;
object
//Save and Launch
document.SaveToFile(filename, FileFormat.Docx);
System.Diagnostics.Process.Start(filename);
}file