Step 2: Activate Dynamsoft Document Viewer

  1. In index.html, create an input element for the license key and a button to activate the SDK:

  2. Implement the activation logic in main.js:

    async function activate(license) {    try {        Dynamsoft.DDV.Core.license = license;        Dynamsoft.DDV.Core.engineResourcePath = \\\"https://cdn.jsdelivr.net/npm/[email protected]/dist/engine\\\";        await Dynamsoft.DDV.Core.init();        Dynamsoft.DDV.setProcessingHandler(\\\"imageFilter\\\", new Dynamsoft.DDV.ImageFilter());        docManager = Dynamsoft.DDV.documentManager;    } catch (error) {        console.error(error);        toggleLoading(false);    }}

    Explanation

Step 3: Create a Web PDF Viewer with Ready-to-Use Components

The Dynamsoft Document Viewer SDK provides a built-in document editor that requires minimal code to construct a web PDF viewer application.

  1. Create a container element for the document viewer in index.html:

  2. Initialize the document viewer in main.js:

    async function showViewer() {    if (!docManager) return;    let editContainer = document.getElementById(\\\"edit-viewer\\\");    editContainer.parentNode.style.display = \\\"block\\\";    editViewer = new Dynamsoft.DDV.EditViewer({        container: editContainer,        uiConfig: DDV.getDefaultUiConfig(\\\"editViewer\\\", { includeAnnotationSet: true })    });}

    The uiConfig parameter specifies the default UI configuration for the document viewer, including annotation tools.

Step 4: Add a Custom Button to Insert Barcodes into the PDF Document

Dynamsoft Document Viewer allows for customization of UI elements and event handlers. According to the official documentation, you can add custom buttons.

A Custom Barcode Button with Google\\'s Material Icons

Define a custom button object in main.js:

const qrButton = {    type: Dynamsoft.DDV.Elements.Button,    className: \\\"material-icons icon-qr_code\\\",    tooltip: \\\"Add a QR code. Ctrl Q\\\",    events: {        click: \\\"addQr\\\",    },};

The className points to Google fonts. Use the material-icons class to display the qr_code icon in the button.

Add the Barcode Button to the Toolbar

To add the button to the toolbar, modify the uiConfig parameter in the showViewer function:

const pcEditViewerUiConfig = {    type: Dynamsoft.DDV.Elements.Layout,    flexDirection: \\\"column\\\",    className: \\\"ddv-edit-viewer-desktop\\\",    children: [        {            type: Dynamsoft.DDV.Elements.Layout,            className: \\\"ddv-edit-viewer-header-desktop\\\",            children: [                {                    type: Dynamsoft.DDV.Elements.Layout,                    children: [                        Dynamsoft.DDV.Elements.ThumbnailSwitch,                        Dynamsoft.DDV.Elements.Zoom,                        Dynamsoft.DDV.Elements.FitMode,                        Dynamsoft.DDV.Elements.DisplayMode,                        Dynamsoft.DDV.Elements.RotateLeft,                        Dynamsoft.DDV.Elements.RotateRight,                        Dynamsoft.DDV.Elements.Crop,                        Dynamsoft.DDV.Elements.Filter,                        Dynamsoft.DDV.Elements.Undo,                        Dynamsoft.DDV.Elements.Redo,                        Dynamsoft.DDV.Elements.DeleteCurrent,                        Dynamsoft.DDV.Elements.DeleteAll,                        Dynamsoft.DDV.Elements.Pan,                        Dynamsoft.DDV.Elements.AnnotationSet,                        qrButton,                    ],                },                {                    type: Dynamsoft.DDV.Elements.Layout,                    children: [                        {                            type: Dynamsoft.DDV.Elements.Pagination,                            className: \\\"ddv-edit-viewer-pagination-desktop\\\",                        },                        Dynamsoft.DDV.Elements.Load,                        {                            type: Dynamsoft.DDV.Elements.Button,                            className: \\\"ddv-button ddv-button-download\\\",                            events: {                                click: \\\"download\\\",                            }                        }                    ],                },            ],        },        Dynamsoft.DDV.Elements.MainView,    ],};editViewer = new Dynamsoft.DDV.EditViewer({    container: editContainer,    uiConfig: pcEditViewerUiConfig});

Press the Button to Pop Up a Barcode Generation Dialog

When the barcode button is clicked, a pop-up dialog will appear for users to input the barcode content and select the barcode type:

editViewer.on(\\\"addQr\\\", addQr);

The dialog contains the following elements:

Here\\'s the full code:

Step 5: Generate a Barcode and Insert it as Annotation to PDF Document

Include the bwip-js library in index.html. This library is used to generate barcodes in various formats, such as QR Code, PDF417, and DataMatrix.

After retrieving the barcode content and type, use bwipjs to draw the generated barcode on a canvas. Then, convert the canvas to a blob and insert it as an annotation to the PDF document.

if (barcodeContent !== null) {    try {        bwipjs.toCanvas(tempCanvas, {            bcid: barcodeType,            text: barcodeContent,            scale: 3,            includetext: false,        });        tempCanvas.toBlob(async (blob) => {            if (blob) {                let currentPageId = docs[0].pages[editViewer.getCurrentPageIndex()];                let pageData = await docs[0].getPageData(currentPageId);                const option = {                    stamp: blob,                    x: pageData.mediaBox.width - 110,                    y: 10,                    width: 100,                    height: 100,                    opacity: 1.0,                    flags: {                        print: false,                        noView: false,                        readOnly: false,                    }                }                if (applyToAllPages) {                    for (let i = 0; i < docs[0].pages.length; i  ) {                        await Dynamsoft.DDV.annotationManager.createAnnotation(docs[0].pages[i], \\\"stamp\\\", option)                    }                } else {                    await Dynamsoft.DDV.annotationManager.createAnnotation(currentPageId, \\\"stamp\\\", option)                }            }        }, \\'image/png\\');    } catch (e) {        console.log(e);    }}

Step 6: Save the PDF Document with Barcodes to Local Disk

Create a download() function and bind it to the download button in the toolbar:

editViewer.on(\\\"download\\\", download);async function download() {    try {        const pdfSettings = {            saveAnnotation: \\\"flatten\\\",        };        let blob = await editViewer.currentDocument.saveToPdf(pdfSettings);        saveBlob(blob, `document_${Date.now()}.pdf`);    } catch (error) {        console.log(error);    }}function saveBlob(blob, fileName) {    const url = URL.createObjectURL(blob);    const a = document.createElement(\\'a\\');    a.href = url;    a.download = fileName;    document.body.appendChild(a);    a.click();    document.body.removeChild(a);    URL.revokeObjectURL(url);}

When saving the PDF document, the saveAnnotation option is set to flatten, ensuring that annotations, including the barcodes, are embedded in the document.

Running the Web PDF Document Editor

  1. Start a web server in the root directory of your project:

    python -m http.server
  2. Open http://localhost:8000 in your web browser.

  3. Load a PDF document.

  4. Insert a barcode as an annotation into the PDF document.

    \\\"How

Reading Barcodes from PDF Documents

Once the PDF document is saved to your local disk, you can verify the barcode content by reading it with the Dynamsoft Barcode Reader.

  1. Install barcode4nodejs, a Node.js wrapper built with the Dynamsoft C Barcode Reader SDK.

    npm i barcode4nodejs
  2. Create a script file, test.js, to read barcodes from the PDF document:

    var dbr = require(\\'barcode4nodejs\\');var barcodeTypes = dbr.formats.ALL;dbr.initLicense(\\\"LICENSE-KEY\\\");let args = process.argv;if (args.includes(\\'-f\\')) {  let fIndex = args.indexOf(\\'-f\\');  if (args[fIndex   1]) {    (async function () {      try {        var result = await dbr.decodeFileAsync(args[fIndex   1], barcodeTypes, \\\"\\\");        console.log(result);        setTimeout(() => {          console.log(\\'terminated\\');        }, 1000);      } catch (error) {        console.log(error);      }    })();  } else {    console.log(\\'Please add a file.\\');  }}

    Note: You need to replace the LICENSE-KEY with your own.

  3. Run the script with the path to a PDF file:

    node test.js -f 

    The barcode content will be printed in the console.

    \\\"How

Source Code

https://github.com/yushulx/web-twain-document-scan-management/tree/main/examples/document_annotation

","image":"http://www.luping.net/uploads/20241119/1731991338673c172aa2afc.png","datePublished":"2024-11-19T13:47:08+08:00","dateModified":"2024-11-19T13:47:08+08:00","author":{"@type":"Person","name":"luping.net","url":"https://www.luping.net/articlelist/0_1.html"}}
”工欲善其事,必先利其器。“—孔子《论语.录灵公》

如何使用 HTMLnd JavaScript 将条形码插入 PDF 文档

发布于2024-11-19
浏览:817

Inserting barcodes into PDF documents can significantly streamline document management, tracking, and data processing workflows. Barcodes serve as unique identifiers, enabling automated data entry, quick retrieval, and enhanced security. In this article, we'll demonstrate how to leverage HTML5, JavaScript, and the Dynamsoft Document Viewer SDK to generate and embed barcodes into PDF documents.

Web PDF Editor Demo Video

Online Demo

https://yushulx.me/web-document-annotation/

Prerequisites

  • Dynamsoft Document Viewer: This JavaScript SDK allows for seamless viewing and annotation of various document formats, including PDFs and common image files such as JPEG, PNG, TIFF, and BMP. With its robust feature set, you can render PDFs, navigate pages, enhance image quality, and save annotated documents. Install the package from npm to get started.

  • Dynamsoft Capture Vision Trial License: To access the full capabilities of the Dynamsoft SDKs, sign up for a 30-day free trial license. This trial offers complete access to all features, enabling you to explore the SDKs in-depth.

Steps to Implement a PDF Document Editor in HTML5 and JavaScript

In the following paragraphs, we'll walk you through the process of creating a web-based PDF document editor with barcode insertion capabilities. The editor will enable users to load PDF documents, insert barcodes as annotations, and save the modified PDF files locally.

Step 1: Include the Dynamsoft Document Viewer SDK

In the

section of your HTML file, add the following script tags to include the Dynamsoft Document Viewer SDK:

Step 2: Activate Dynamsoft Document Viewer

  1. In index.html, create an input element for the license key and a button to activate the SDK:

  2. Implement the activation logic in main.js:

    async function activate(license) {
        try {
            Dynamsoft.DDV.Core.license = license;
            Dynamsoft.DDV.Core.engineResourcePath = "https://cdn.jsdelivr.net/npm/[email protected]/dist/engine";
            await Dynamsoft.DDV.Core.init();
            Dynamsoft.DDV.setProcessingHandler("imageFilter", new Dynamsoft.DDV.ImageFilter());
            docManager = Dynamsoft.DDV.documentManager;
    
        } catch (error) {
            console.error(error);
            toggleLoading(false);
        }
    
    }
    

    Explanation

    • The engineResourcePath must point to the location of the Dynamsoft Document Viewer engine files.
    • setProcessingHandler sets the image filter for enhancing image quality.
    • The documentManager object is used to manage the document viewer and editor.

Step 3: Create a Web PDF Viewer with Ready-to-Use Components

The Dynamsoft Document Viewer SDK provides a built-in document editor that requires minimal code to construct a web PDF viewer application.

  1. Create a container element for the document viewer in index.html:

  2. Initialize the document viewer in main.js:

    async function showViewer() {
        if (!docManager) return;
        let editContainer = document.getElementById("edit-viewer");
        editContainer.parentNode.style.display = "block";
        editViewer = new Dynamsoft.DDV.EditViewer({
            container: editContainer,
            uiConfig: DDV.getDefaultUiConfig("editViewer", { includeAnnotationSet: true })
        });
    }
    

    The uiConfig parameter specifies the default UI configuration for the document viewer, including annotation tools.

  3. Step 4: Add a Custom Button to Insert Barcodes into the PDF Document

    Dynamsoft Document Viewer allows for customization of UI elements and event handlers. According to the official documentation, you can add custom buttons.

    A Custom Barcode Button with Google's Material Icons

    Define a custom button object in main.js:

    const qrButton = {
        type: Dynamsoft.DDV.Elements.Button,
        className: "material-icons icon-qr_code",
        tooltip: "Add a QR code. Ctrl Q",
        events: {
            click: "addQr",
        },
    };
    

    The className points to Google fonts. Use the material-icons class to display the qr_code icon in the button.

    Add the Barcode Button to the Toolbar

    To add the button to the toolbar, modify the uiConfig parameter in the showViewer function:

    const pcEditViewerUiConfig = {
        type: Dynamsoft.DDV.Elements.Layout,
        flexDirection: "column",
        className: "ddv-edit-viewer-desktop",
        children: [
            {
                type: Dynamsoft.DDV.Elements.Layout,
                className: "ddv-edit-viewer-header-desktop",
                children: [
                    {
                        type: Dynamsoft.DDV.Elements.Layout,
                        children: [
                            Dynamsoft.DDV.Elements.ThumbnailSwitch,
                            Dynamsoft.DDV.Elements.Zoom,
                            Dynamsoft.DDV.Elements.FitMode,
                            Dynamsoft.DDV.Elements.DisplayMode,
                            Dynamsoft.DDV.Elements.RotateLeft,
                            Dynamsoft.DDV.Elements.RotateRight,
                            Dynamsoft.DDV.Elements.Crop,
                            Dynamsoft.DDV.Elements.Filter,
                            Dynamsoft.DDV.Elements.Undo,
                            Dynamsoft.DDV.Elements.Redo,
                            Dynamsoft.DDV.Elements.DeleteCurrent,
                            Dynamsoft.DDV.Elements.DeleteAll,
                            Dynamsoft.DDV.Elements.Pan,
                            Dynamsoft.DDV.Elements.AnnotationSet,
                            qrButton,
                        ],
                    },
                    {
                        type: Dynamsoft.DDV.Elements.Layout,
                        children: [
                            {
                                type: Dynamsoft.DDV.Elements.Pagination,
                                className: "ddv-edit-viewer-pagination-desktop",
                            },
                            Dynamsoft.DDV.Elements.Load,
                            {
                                type: Dynamsoft.DDV.Elements.Button,
                                className: "ddv-button ddv-button-download",
                                events: {
                                    click: "download",
                                }
                            }
                        ],
                    },
                ],
            },
            Dynamsoft.DDV.Elements.MainView,
        ],
    };
    
    editViewer = new Dynamsoft.DDV.EditViewer({
        container: editContainer,
        uiConfig: pcEditViewerUiConfig
    });
    
    

    Press the Button to Pop Up a Barcode Generation Dialog

    When the barcode button is clicked, a pop-up dialog will appear for users to input the barcode content and select the barcode type:

    editViewer.on("addQr", addQr);
    

    The dialog contains the following elements:

    • A dropdown list for selecting barcode types.
    • An input field for entering barcode content.
    • An OK button to submit the data.
    • A Cancel button to close the pop-up without submitting.

    Here's the full code:

    Step 5: Generate a Barcode and Insert it as Annotation to PDF Document

    Include the bwip-js library in index.html. This library is used to generate barcodes in various formats, such as QR Code, PDF417, and DataMatrix.

    After retrieving the barcode content and type, use bwipjs to draw the generated barcode on a canvas. Then, convert the canvas to a blob and insert it as an annotation to the PDF document.

    if (barcodeContent !== null) {
        try {
    
            bwipjs.toCanvas(tempCanvas, {
                bcid: barcodeType,
                text: barcodeContent,
                scale: 3,
                includetext: false,
            });
    
            tempCanvas.toBlob(async (blob) => {
                if (blob) {
                    let currentPageId = docs[0].pages[editViewer.getCurrentPageIndex()];
                    let pageData = await docs[0].getPageData(currentPageId);
    
                    const option = {
                        stamp: blob,
                        x: pageData.mediaBox.width - 110,
                        y: 10,
                        width: 100,
                        height: 100,
                        opacity: 1.0,
                        flags: {
                            print: false,
                            noView: false,
                            readOnly: false,
    
                        }
                    }
    
                    if (applyToAllPages) {
                        for (let i = 0; i 
    
    
    
    

    Step 6: Save the PDF Document with Barcodes to Local Disk

    Create a download() function and bind it to the download button in the toolbar:

    editViewer.on("download", download);
    
    async function download() {
        try {
            const pdfSettings = {
                saveAnnotation: "flatten",
            };
    
            let blob = await editViewer.currentDocument.saveToPdf(pdfSettings);
    
            saveBlob(blob, `document_${Date.now()}.pdf`);
        } catch (error) {
            console.log(error);
        }
    
    }
    
    function saveBlob(blob, fileName) {
        const url = URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = url;
        a.download = fileName;
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        URL.revokeObjectURL(url);
    }
    

    When saving the PDF document, the saveAnnotation option is set to flatten, ensuring that annotations, including the barcodes, are embedded in the document.

    Running the Web PDF Document Editor

    1. Start a web server in the root directory of your project:

      python -m http.server
      
    2. Open http://localhost:8000 in your web browser.

    3. Load a PDF document.

    4. Insert a barcode as an annotation into the PDF document.

      How to Insert Barcodes into a PDF Document with HTMLnd JavaScript

    Reading Barcodes from PDF Documents

    Once the PDF document is saved to your local disk, you can verify the barcode content by reading it with the Dynamsoft Barcode Reader.

    1. Install barcode4nodejs, a Node.js wrapper built with the Dynamsoft C Barcode Reader SDK.

      npm i barcode4nodejs
      
    2. Create a script file, test.js, to read barcodes from the PDF document:

      var dbr = require('barcode4nodejs');
      var barcodeTypes = dbr.formats.ALL;
      
      dbr.initLicense("LICENSE-KEY");
      
      let args = process.argv;
      if (args.includes('-f')) {
        let fIndex = args.indexOf('-f');
        if (args[fIndex   1]) {
          (async function () {
            try {
              var result = await dbr.decodeFileAsync(args[fIndex   1], barcodeTypes, "");
              console.log(result);
              setTimeout(() => {
                console.log('terminated');
              }, 1000);
            } catch (error) {
              console.log(error);
            }
          })();
        } else {
          console.log('Please add a file.');
        }
      
      }
      

      Note: You need to replace the LICENSE-KEY with your own.

    3. Run the script with the path to a PDF file:

      node test.js -f 

      The barcode content will be printed in the console.

      How to Insert Barcodes into a PDF Document with HTMLnd JavaScript

    Source Code

    https://github.com/yushulx/web-twain-document-scan-management/tree/main/examples/document_annotation

版本声明 本文转载于:https://dev.to/yushulx/how-to-insert-barcodes-into-a-pdf-document-with-html5-and-javascript-32g9?1如有侵犯,请联系[email protected]删除
最新教程 更多>
  • 如何通过唯一键约束消除MySQL数据库中的重复记录?
    如何通过唯一键约束消除MySQL数据库中的重复记录?
    从 MySQL 数据库中清除重复记录:独特的关键解决方案维护数据完整性对于任何数据库的高效运行至关重要。在本例中,您会遇到一个包含“id”和“title”列的表,其中“title”应该不同。然而,超过 600,000 条记录的存在(包括大量重复记录)对实现唯一性构成了挑战。我们的目标是在不影响任何唯...
    编程 发布于2024-11-19
  • 为什么我找不到“vendor/autoload.php”:解决 Composer 自动加载错误的指南
    为什么我找不到“vendor/autoload.php”:解决 Composer 自动加载错误的指南
    解决“require(vendor/autoload.php): 无法打开流”错误问题描述:在PHP脚本开头遇到以下错误:Warning: require(vendor/autoload.php): failed to open stream: No such file or directory F...
    编程 发布于2024-11-19
  • 如何模拟 Python 的请求模块以实现真实的 API 交互?
    如何模拟 Python 的请求模块以实现真实的 API 交互?
    模拟 API 交互的模拟 Python 请求模块在我们全面测试与 API 交互的 Python 代码的过程中,有效地模拟 requests 模块至关重要。以下是使用自定义响应模拟 requests.get() 调用的分步方法:第 1 步:模拟 Requests 模块利用 Python 的模拟包,我们...
    编程 发布于2024-11-19
  • ## 淘汰视图模型:对象文字或函数 - 哪一个适合您?
    ## 淘汰视图模型:对象文字或函数 - 哪一个适合您?
    KO 视图模型:对象文字与函数在 Knockout JS 中,可以使用对象文字或函数来声明视图模型。虽然两者的主要目的都是定义可观察的属性和计算函数,但它们之间的关键区别会影响封装、灵活性和代码组织。对象文字:var viewModel = { firstname: ko.observabl...
    编程 发布于2024-11-19
  • 为什么我们应该避免在 MySQL 脚本中使用“SET NAMES”?
    为什么我们应该避免在 MySQL 脚本中使用“SET NAMES”?
    使用“SET NAMES”的注意事项在MySQL数据库处理的上下文中,“SET NAMES”的正确使用一直是一个讨论的话题。正如 O'Reilly 的《高性能 MySQL》中所述,在脚本开头使用“SET NAMES UTF8”的做法因其效率低下而受到质疑。Unicode 感知数据库的最佳实践...
    编程 发布于2024-11-19
  • 除了“if”语句之外:还有哪些地方可以在不进行强制转换的情况下使用具有显式“bool”转换的类型?
    除了“if”语句之外:还有哪些地方可以在不进行强制转换的情况下使用具有显式“bool”转换的类型?
    无需强制转换即可上下文转换为 bool您的类定义了对 bool 的显式转换,使您能够在条件语句中直接使用其实例“t”。然而,这种显式转换提出了一个问题:“t”在哪里可以在不进行强制转换的情况下用作 bool?上下文转换场景C 标准指定了四种值可以根据上下文转换为的主要场景bool:语句:if、whi...
    编程 发布于2024-11-19
  • 如何确保 MySQL 表是使用 Hibernate 使用 InnoDB 引擎创建的?
    如何确保 MySQL 表是使用 Hibernate 使用 InnoDB 引擎创建的?
    如何使用 Hibernate 创建 MySQL InnoDB 表当使用 Hibernate 和 JPA 时,用户在使用 InnoDB 创建 MySQL 表时经常遇到挑战引擎而不是 MyISAM。为了解决这个问题,一个广泛推荐的解决方案是通过设置 hibernate.dialect 属性来配置 Hib...
    编程 发布于2024-11-19
  • 大批
    大批
    方法是可以在对象上调用的 fns 数组是对象,因此它们在 JS 中也有方法。 slice(begin):将数组的一部分提取到新数组中,而不改变原始数组。 let arr = ['a','b','c','d','e']; // Usecase: Extract till index p...
    编程 发布于2024-11-19
  • 使用子类对象的超类引用
    使用子类对象的超类引用
    考虑一个场景,我们创建一个名为 User 的类,然后创建一个扩展 User 的子类,名为 Employee。 通常,我们使用以下内容创建 User 的实例: User user = new User(); 这里User是变量user的类型,user是保存类实例的变量,new User()创建了一个新...
    编程 发布于2024-11-19
  • 如何在 Go 中不阻塞地检查 Stdin 中的数据?
    如何在 Go 中不阻塞地检查 Stdin 中的数据?
    使用 Go 检查 Stdin 中的数据在 Go 中,在使用命令和管道时,与标准输入 (stdin) 交互通常是一项关键任务。然而,在不阻塞程序执行的情况下确定 stdin 是否有数据可能具有挑战性。os.Stdin 文件对象代表 stdin,它拥有与 Go 中其他文件对象类似的功能。这使我们能够利用...
    编程 发布于2024-11-19
  • 什么时候应该在 JavaScript 中使用 const:优化代码还是过度使用?
    什么时候应该在 JavaScript 中使用 const:优化代码还是过度使用?
    JavaScript 中的 Const:优化代码性能并促进语义清晰度在 JavaScript 中,const 关键字的引入引发了关于其最优值的讨论用法。虽然它可能看起来与 var 关键字类似,但使用 const 有明显的优势,可以提高代码效率并提高语义精度。const 何时合适? const 的主要...
    编程 发布于2024-11-19
  • 何时应为特殊情况保留例外?
    何时应为特殊情况保留例外?
    例外:为特殊情况保留尽管例外很普遍,但通常还是提倡保守地使用例外。深入研究这一哲学背后的原因揭示了无数的考虑因素。语义滥用为真正特殊情况而设计的异常经常被误用为控制流机制。这破坏了它们的预期语义功能,因为预计不会引发异常来响应可预见的事件,例如不正确的用户输入。异常处理的负担异常破坏正常的执行流程,...
    编程 发布于2024-11-19
  • 如何在 PHP 中组合两个关联数组,同时保留唯一 ID 并处理重复名称?
    如何在 PHP 中组合两个关联数组,同时保留唯一 ID 并处理重复名称?
    在 PHP 中组合关联数组在 PHP 中,将两个关联数组组合成一个数组是一项常见任务。考虑以下请求:问题描述:提供的代码定义了两个关联数组,$array1 和 $array2。目标是创建一个新数组 $array3,它合并两个数组中的所有键值对。 此外,提供的数组具有唯一的 ID,而名称可能重合。要求...
    编程 发布于2024-11-19
  • CSS 和 Javascript 代码应该放在 HTML 网页中的什么位置?
    CSS 和 Javascript 代码应该放在 HTML 网页中的什么位置?
    在HTML网页中实现CSS和Javascript代码在Web开发过程中,确定CSS和Javascript代码的适当放置位置至关重要。这些文件在设计网页样式和增强网页功能方面发挥着重要作用。当遇到诸如 之类的代码时,了解其在 HTML 文档中的预期位置非常重要。放置选项在 HTML 文档中包含 CS...
    编程 发布于2024-11-19
  • 在 Go 中使用 WebSocket 进行实时通信
    在 Go 中使用 WebSocket 进行实时通信
    构建需要实时更新的应用程序(例如聊天应用程序、实时通知或协作工具)需要比传统 HTTP 更快、更具交互性的通信方法。这就是 WebSockets 发挥作用的地方!今天,我们将探讨如何在 Go 中使用 WebSocket,以便您可以向应用程序添加实时功能。 在这篇文章中,我们将介绍: WebSocke...
    编程 发布于2024-11-19

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3