Aspose.Words for .NET圖像處理教程——在Word文檔的頁面上插入條形碼
Aspose.Words For .Net是一種高級(jí)Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務(wù)。API支持生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印文檔,而無需在跨平臺(tái)應(yīng)用程序中直接使用Microsoft Word。此外,API支持所有流行的Word處理文件格式,并允許將Word文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
接下來我們將進(jìn)入關(guān)于“圖像處理”的介紹,在Aspose.Words中學(xué)會(huì)如何在Word文檔的所有或特定頁面上添加相同或不同的條形碼。
>>Aspose.Words for .NET更新至最新版v19.12,支持轉(zhuǎn)換為PDF 1.7標(biāo)準(zhǔn),點(diǎn)擊下載體驗(yàn)
在文檔的每一頁上插入條形碼
沒有直接的方法可以在文檔的所有頁面上添加條形碼,但是可以使用DocumentBuilder.MoveToSection、DocumentBuilder.MoveToHeaderFooter和DocumentBuilder.InsertImage方法移動(dòng)到任何部分或頁眉/頁腳,并插入條形碼圖像。以下代碼示例在文檔的每一頁上插入條形碼圖像。
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithImages(); // Create a blank documenet. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // The number of pages the document should have. int numPages = 4; // The document starts with one section, insert the barcode into this existing section. InsertBarcodeIntoFooter(builder, doc.FirstSection, 1, HeaderFooterType.FooterPrimary); for (int i = 1; i < numPages; i++) { // Clone the first section and add it into the end of the document. Section cloneSection = (Section)doc.FirstSection.Clone(false); cloneSection.PageSetup.SectionStart = SectionStart.NewPage; doc.AppendChild(cloneSection); // Insert the barcode and other information into the footer of the section. InsertBarcodeIntoFooter(builder, cloneSection, i, HeaderFooterType.FooterPrimary); } dataDir = dataDir + "Document_out.docx"; // Save the document as a PDF to disk. You can also save this directly to a stream. doc.Save(dataDir);
12月即將走過!Aspose.Total10000元直降活動(dòng)即將落下帷幕!趕緊聯(lián)系慧都客服1分鐘了解全部資訊!
private static void InsertBarcodeIntoFooter(DocumentBuilder builder, Section section, int pageId, HeaderFooterType footerType) { // Move to the footer type in the specific section. builder.MoveToSection(section.Document.IndexOf(section)); builder.MoveToHeaderFooter(footerType); // Insert the barcode, then move to the next line and insert the ID along with the page number. // Use pageId if you need to insert a different barcode on each page. 0 = First page, 1 = Second page etc. builder.InsertImage(System.Drawing.Image.FromFile( RunExamples.GetDataDir_WorkingWithImages() + "Barcode1.png")); builder.Writeln(); builder.Write("1234567890"); builder.InsertField("PAGE"); // Create a right aligned tab at the right margin. double tabPos = section.PageSetup.PageWidth - section.PageSetup.RightMargin - section.PageSetup.LeftMargin; builder.CurrentParagraph.ParagraphFormat.TabStops.Add(new TabStop(tabPos, TabAlignment.Right, TabLeader.None)); // Move to the right hand side of the page and insert the page and page total. builder.Write(ControlChar.Tab); builder.InsertField("PAGE"); builder.Write(" of "); builder.InsertField("NUMPAGES"); }
還想要更多嗎?您可以點(diǎn)擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請(qǐng)隨時(shí)加入Aspose技術(shù)交流群(642018183),我們很高興為您提供查詢和咨詢。