My goal objectives and requirements: a picture into a page, the page border to 0, use the following code to achieve (button1UseDocX_Click function), the resulting document can not achieve their goals. The use Spire.Doc able to achieve the purpose of button1UseSpireDoc_Click function.
The reason to use DocX because Spire. The library file is too big, but this little feature, it is necessary more than 30 M.
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();
//set the background type as picture.
document.Background.Type = Spire.Doc.Documents.BackgroundType.Picture;
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();
DocPicture Pic = p.AppendPicture(System.Drawing.Image.FromFile(imagefilename));
Pic.Width = s.PageSetup.PageSize.Width;
Pic.Height = s.PageSetup.PageSize.Height;
//Save and Launch
document.SaveToFile(filename, FileFormat.Docx);
System.Diagnostics.Process.Start(filename);
}