• Aspose.Words for .NET图像处理教程——在Word文档的页面上插入条形码


    Aspose.Words For .Net是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,API支持所有流行的Word处理文件格式,并允许将Word文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。

    接下来我们将进入关于“图像处理”的介绍,在Aspose.Words中学会如何在Word文档的所有或特定页面上添加相同或不同的条形码。

    >>Aspose.Words for .NET更新至最新版        点击下载体验

    欢迎下载|体验更多Aspose文档管理产品或 加入Aspose技术交流群(761297826)


    在文档的每一页上插入条形码

    没有直接的方法可以在文档的所有页面上添加条形码,但是可以使用DocumentBuilder.MoveToSectionDocumentBuilder.MoveToHeaderFooterDocumentBuilder.InsertImage方法移动到任何部分或页眉/页脚,并插入条形码图像。以下代码示例在文档的每一页上插入条形码图像。

    1. // The path to the documents directory.
    2. string dataDir = RunExamples.GetDataDir_WorkingWithImages();
    3. // Create a blank documenet.
    4. Document doc = new Document();
    5. DocumentBuilder builder = new DocumentBuilder(doc);
    6. // The number of pages the document should have.
    7. int numPages = 4;
    8. // The document starts with one section, insert the barcode into this existing section.
    9. InsertBarcodeIntoFooter(builder, doc.FirstSection, 1, HeaderFooterType.FooterPrimary);
    10. for (int i = 1; i < numPages; i++)
    11. {
    12.     // Clone the first section and add it into the end of the document.
    13.     Section cloneSection = (Section)doc.FirstSection.Clone(false);
    14.     cloneSection.PageSetup.SectionStart = SectionStart.NewPage;
    15.     doc.AppendChild(cloneSection);
    16.     // Insert the barcode and other information into the footer of the section.
    17.     InsertBarcodeIntoFooter(builder, cloneSection, i, HeaderFooterType.FooterPrimary);
    18. }
    19. dataDir  = dataDir + "Document_out.docx";
    20. // Save the document as a PDF to disk. You can also save this directly to a stream.
    21. doc.Save(dataDir);
    22. 12月即将走过!Aspose.Total10000元直降活动即将落下帷幕!赶紧联系慧都客服1分钟了解全部资讯!
    23. private static void InsertBarcodeIntoFooter(DocumentBuilder builder, Section section, int pageId, HeaderFooterType footerType)
    24. {
    25.     // Move to the footer type in the specific section.
    26.     builder.MoveToSection(section.Document.IndexOf(section));
    27.     builder.MoveToHeaderFooter(footerType);
    28.     // Insert the barcode, then move to the next line and insert the ID along with the page number.
    29.     // Use pageId if you need to insert a different barcode on each page. 0 = First page, 1 = Second page etc.    
    30.     builder.InsertImage(System.Drawing.Image.FromFile( RunExamples.GetDataDir_WorkingWithImages() + "Barcode1.png"));
    31.     builder.Writeln();
    32.     builder.Write("1234567890");
    33.     builder.InsertField("PAGE");
    34.     // Create a right aligned tab at the right margin.
    35.     double tabPos = section.PageSetup.PageWidth - section.PageSetup.RightMargin - section.PageSetup.LeftMargin;
    36.     builder.CurrentParagraph.ParagraphFormat.TabStops.Add(new TabStop(tabPos, TabAlignment.Right, TabLeader.None));
    37.     // Move to the right hand side of the page and insert the page and page total.
    38.     builder.Write(ControlChar.Tab);
    39.     builder.InsertField("PAGE");
    40.     builder.Write(" of ");
    41.     builder.InsertField("NUMPAGES");
    42. }

  • 相关阅读:
    服务器折腾日志
    Linux下NFS共享存储安装详细步骤
    数据可视化带你了解茶饮市场规模
    构建本地Web小游戏网站:Ubuntu下的快速部署与公网用户远程访问
    Linux——Linux驱动之iMX6ULL平台下串口UART驱动实现RS232数据通信开发实战(UART驱动框架、源码分析、串口应用程序编写)
    使用信号量实现简单双向同步
    基于Python pyqt5的随机抽号机源代码 ,可设备抽号器的人数及刷新间隔
    第7章 - 多无人机系统的协同控制 --> 无人机飞行原理
    Unity中PICO中手柄按键返回值
    Hbase的scan原理
  • 原文地址:https://blog.csdn.net/m0_67129275/article/details/125557825