<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: MUNEEB WAQAS</title>
    <description>The latest articles on Forem by MUNEEB WAQAS (@muneebwaqas416).</description>
    <link>https://forem.com/muneebwaqas416</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1025269%2Ff526b34d-74df-44a4-8513-c7f1fa4c61ab.jpeg</url>
      <title>Forem: MUNEEB WAQAS</title>
      <link>https://forem.com/muneebwaqas416</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/muneebwaqas416"/>
    <language>en</language>
    <item>
      <title>How to add Signatures to a text Field of a PDF in MERN Stack</title>
      <dc:creator>MUNEEB WAQAS</dc:creator>
      <pubDate>Thu, 08 Feb 2024 18:01:38 +0000</pubDate>
      <link>https://forem.com/muneebwaqas416/how-to-add-signatures-to-a-text-field-of-a-pdf-in-mern-stack-2gmd</link>
      <guid>https://forem.com/muneebwaqas416/how-to-add-signatures-to-a-text-field-of-a-pdf-in-mern-stack-2gmd</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;In today's digital age, electronic signatures play a vital role in various applications, from signing contracts to validating transactions. Integrating signature functionality into web applications is crucial for streamlining processes and enhancing user experience. In this guide, we'll explore how to implement a signature pad in React.js and then incorporate that signature into a text field within a PDF document in a MERN (MongoDB, Express.js, React.js, Node.js) stack.&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 1:
&lt;/h2&gt;

&lt;p&gt;Implementing Signature Pad in React.js First, let's set up a React.js project and integrate a signature pad component. We'll be using the &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;react-signature-canvas&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Library for this purpose, which provides an easy-to-use API for capturing signatures.This is the link for the npm package&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/react-signature-canvas"&gt;Npm Package if react-signature-canvas&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1:
&lt;/h2&gt;

&lt;p&gt;Installing the Signature Pad Library&lt;br&gt;
Next, install the react-signature-canvas library using npm or yarn:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install react-signature-canvas&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2:
&lt;/h2&gt;

&lt;p&gt;Integrating the Signature Pad Component Now, let's create a component called SignaturePad and integrate the SignatureCanvas component provided by react-signature-canvas.This is my ReactJS Code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Done = ()=&amp;gt;{
    seturl(sign.getTrimmedCanvas().toDataURL('image/png'));
}
const Clear = ()=&amp;gt;{
  sign.clear();
}

const Forward = ()  =&amp;gt; {
          console.log(url);
          axios.post('http://localhost:8080/send-data',{mydata  , price , IBAN , Rechnungsanschrift , Kontoinhaber , Gebäude , Gebäudeinhaber , url},{withCredentials : true}).then((response)=&amp;gt;{
                alert('PDF Saved'); 
        }).catch((error)=&amp;gt;{
        console.log(error);
              alert(error + 'in the PDF');
        })
  }

const [sign,setsign] = useState();
  const [url , seturl] = useState('');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is my JSX Code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div className='justify-content-center align-items-center canvas'&amp;gt;
                              &amp;lt;SignatureCanvas penColor='black'
               canvasProps={{className: 'sigCanvas canvas'}}
                  ref={data=&amp;gt;setsign(data)}
              /&amp;gt;
                    &amp;lt;/div&amp;gt;

                    &amp;lt;Button className={`rounded-5 w-25 m-3 btn-white`}  onClick={Clear}&amp;gt;
Cancel
                    &amp;lt;/Button&amp;gt;
                    &amp;lt;Button className={`rounded-5 w-25 m-3 btn-white`}  onClick={Done}&amp;gt;
Save
                    &amp;lt;/Button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Explanation of the code
&lt;/h2&gt;

&lt;p&gt;This code snippet is a React component that allows a user to draw a signature on a canvas using the SignatureCanvas component.&lt;/p&gt;

&lt;p&gt;Here's a breakdown of the functionality:&lt;/p&gt;

&lt;p&gt;Done: This function is called when the user clicks the "Save" button. It retrieves the data URL of the signature canvas, representing the drawn signature, and sets it in the component's state variable url.&lt;/p&gt;

&lt;p&gt;Clear: This function is called when the user clicks the "Cancel" button. It clears the signature canvas.&lt;/p&gt;

&lt;p&gt;Forward: This function is called when the user clicks a button to send data to a server. It sends various data, including the signature URL (url), to an endpoint using an Axios POST request.&lt;/p&gt;

&lt;p&gt;useState: This hook is used to initialize state variables. sign is used to hold a reference to the SignatureCanvas component, and url is used to store the data URL of the drawn signature.&lt;/p&gt;

&lt;p&gt;SignatureCanvas: This component provides a canvas for the user to draw a signature. It's configured with a black pen color and assigned a reference using the ref attribute, allowing access to its methods and properties.&lt;/p&gt;

&lt;p&gt;Buttons: Two buttons are rendered for the user to interact with the signature canvas. One button clears the canvas (Clear), and the other saves the drawn signature (Done).&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 2:
&lt;/h2&gt;

&lt;p&gt;Adding Signature to a PDF Text Field in MERN Stack&lt;br&gt;
Now, let's move on to integrating the signature captured in our React.js application with a PDF document in the MERN stack.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1:
&lt;/h2&gt;

&lt;p&gt;Create an Express.js API Endpoint Set up an Express.js server and create an API endpoint to receive and store signature data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post('/send-data' ,  async (req,res)=&amp;gt;{

  const {mydata  , price , IBAN , Rechnungsanschrift , Kontoinhaber , Gebäude , Gebäudeinhaber , url} = req.body;
}
// Now this image object has the URL of the captured
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2:
&lt;/h2&gt;

&lt;p&gt;Add Signature to PDF Document Using a library like pdf-lib, you can dynamically generate a PDF document with the signature added to a text field.&lt;br&gt;
&lt;code&gt;const pdfDoc = await PDFDocument.load(await readFile('NameofPDFFILE.pdf'));&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fetching and Embedding Image in PDF Document&lt;/strong&gt;&lt;br&gt;
 &lt;br&gt;
This code snippet demonstrates the process of fetching an image from a URL and embedding it into a PDF document&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const imageBytes = await fetchImageFromUrl(URL);
const image = await pdfDoc.embedPng(imageBytes);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Get the Signature/Text Field from the PDF and paste the image there&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const signature = form.getTextField('Datum und Unterschrift');
signature.setFontSize(25);
signature.setImage(image);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://youtu.be/SeSo0gPFbtw?si=leIJSHTTm2NLJ7UT"&gt;&lt;em&gt;Tutorial for Making Frontend in order to capture end user's Signature&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mern</category>
      <category>pdf</category>
      <category>react</category>
      <category>signature</category>
    </item>
    <item>
      <title>How much Html, CSS &amp; JS do I need to know?</title>
      <dc:creator>MUNEEB WAQAS</dc:creator>
      <pubDate>Wed, 21 Jun 2023 10:57:00 +0000</pubDate>
      <link>https://forem.com/muneebwaqas416/how-much-html-css-js-do-i-need-to-know-g8j</link>
      <guid>https://forem.com/muneebwaqas416/how-much-html-css-js-do-i-need-to-know-g8j</guid>
      <description>&lt;p&gt;Hi, I am a software Engineering Student. I wanted to be a front end engineer. I have learned basic HTML, CSS and JS. Furthermore, I have done 1–2 projects in them, and now I am learning ReactJS. But still I feel like I don’t know enough HTML, CSS and JS. Like If I have to centre a div then it will cause trouble for me on how to position it.So should I have to move on to ReactJS or learn more HTML, CSS and JS. Also give me some time frame on how much time should I have to spend on these skills(HTML, CSS &amp;amp; JS). Moreover, I have made a gig on Fiverr regarding ReactJS development, and I am in a hurry to earn quickly from front-end development.&lt;br&gt;
So what should I do in this scenario? Seniors, Please guide me.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>frontend</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Advice from Senior Software Engineers</title>
      <dc:creator>MUNEEB WAQAS</dc:creator>
      <pubDate>Tue, 20 Jun 2023 15:37:42 +0000</pubDate>
      <link>https://forem.com/muneebwaqas416/advice-from-senior-software-engineers-4m49</link>
      <guid>https://forem.com/muneebwaqas416/advice-from-senior-software-engineers-4m49</guid>
      <description>&lt;p&gt;Hi I am a 3rd year Software Engineering Student.I am currently Learning ReactJS and then I will move onto Full Stack development.But I wanted to learn Artificial Intelligence so that I can use my web development skills along with AI/ML/.So should I learn AI along with my web development learning or should I first learn web development and then Artificial Intelligence.Please Guide me.&lt;/p&gt;

</description>
      <category>learning</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Use of Bootstrap</title>
      <dc:creator>MUNEEB WAQAS</dc:creator>
      <pubDate>Sun, 12 Feb 2023 09:58:40 +0000</pubDate>
      <link>https://forem.com/muneebwaqas416/use-of-bootstrap-2lg7</link>
      <guid>https://forem.com/muneebwaqas416/use-of-bootstrap-2lg7</guid>
      <description>&lt;p&gt;Should a Front end developer learner use bootstrap, or should I have to develop each and every component of the website by myself. I am a beginner in front end development?&lt;/p&gt;

</description>
      <category>cleancode</category>
      <category>cleancoding</category>
      <category>softwareengineering</category>
      <category>books</category>
    </item>
  </channel>
</rss>
