<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>pdf manipulation on Document Processing REST APIs | GroupDocs Cloud</title>
    <link>https://blog-qa.groupdocs.cloud/tag/pdf-manipulation/</link>
    <description>Recent content in pdf manipulation on Document Processing REST APIs | GroupDocs Cloud</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Wed, 21 Oct 2026 13:18:44 +0000</lastBuildDate><atom:link href="https://blog-qa.groupdocs.cloud/tag/pdf-manipulation/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Remove Annotation Objects from PDF with REST in Node.JS</title>
      <link>https://blog-qa.groupdocs.cloud/annotation/remove-annotation-objects-from-pdf-with-rest-in-nodejs/</link>
      <pubDate>Wed, 21 Oct 2026 13:18:44 +0000</pubDate>
      
      <guid>https://blog-qa.groupdocs.cloud/annotation/remove-annotation-objects-from-pdf-with-rest-in-nodejs/</guid>
      <description>Learn how to remove Annotation objects from PDF with REST in Node.JS using GroupDocs.Annotation Cloud SDK. Step-by-step guide with code, cURL and practices.</description>
      <content:encoded><![CDATA[<p>Removing unwanted notes, highlights, or ink marks from PDFs is a frequent requirement when preparing clean documents for distribution. <a href="https://products.groupdocs.cloud/annotation/nodejs/">GroupDocs.Annotation Cloud SDK for Node.js</a> provides a powerful REST‑based library that lets you manage <a href="https://docs.fileformat.com/pdf">PDF</a> annotations programmatically. This guide shows you how to remove Annotation objects from PDF with REST in Node.JS, step by step. You will see a complete code example, equivalent cURL commands, configuration tips, and best‑practice recommendations to integrate annotation removal into your services.</p>
<h2 id="full-working-example-to-remove-annotation-objects-from-pdf-with-rest-in-nodejs">Full Working Example to Remove Annotation Objects from PDF with REST in Node.JS</h2>
<p>This example demonstrates how to upload a PDF, delete all its annotations, and download the cleaned file using the GroupDocs.Annotation SDK.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">fs</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">require</span>(<span style="color:#e6db74">&#39;fs&#39;</span>);
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">path</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">require</span>(<span style="color:#e6db74">&#39;path&#39;</span>);
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">require</span>(<span style="color:#e6db74">&#34;@groupdocs/annotation-cloud&#34;</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// ==== Authentication =========================================================
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">clientId</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;YOUR_CLIENT_ID&#34;</span>;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">clientSecret</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;YOUR_CLIENT_SECRET&#34;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">config</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">Configuration</span>(<span style="color:#a6e22e">clientId</span>, <span style="color:#a6e22e">clientSecret</span>);
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">annotationsApi</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">AnnotationsApi</span>(<span style="color:#a6e22e">config</span>);
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">storageApi</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">StorageApi</span>(<span style="color:#a6e22e">config</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// ==== Local &amp; Remote file definitions =======================================
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">localInputPath</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">path</span>.<span style="color:#a6e22e">resolve</span>(<span style="color:#a6e22e">__dirname</span>, <span style="color:#e6db74">&#34;input.pdf&#34;</span>);
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">localOutputPath</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">path</span>.<span style="color:#a6e22e">resolve</span>(<span style="color:#a6e22e">__dirname</span>, <span style="color:#e6db74">&#34;output.pdf&#34;</span>);
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">remoteFilePath</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;input.pdf&#34;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// ==== Main workflow ==========================================================
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>(<span style="color:#66d9ef">async</span> () =&gt; {
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// 1. Upload PDF to GroupDocs Cloud storage
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">fileBytes</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">fs</span>.<span style="color:#a6e22e">readFileSync</span>(<span style="color:#a6e22e">localInputPath</span>);
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">uploadRequest</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">UploadFileRequest</span>({
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">remoteFilePath</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">file</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">fileBytes</span>
</span></span><span style="display:flex;"><span>    });
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">await</span> <span style="color:#a6e22e">storageApi</span>.<span style="color:#a6e22e">uploadFile</span>(<span style="color:#a6e22e">uploadRequest</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// 2. Build FileInfo object for the uploaded PDF
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">fileInfo</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">FileInfo</span>({
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">filePath</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">remoteFilePath</span>
</span></span><span style="display:flex;"><span>    });
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// 3. Retrieve all existing annotations
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">getAnnotationsRequest</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">GetAnnotationsRequest</span>({
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">fileInfo</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">fileInfo</span>
</span></span><span style="display:flex;"><span>    });
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">annotationsResult</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">await</span> <span style="color:#a6e22e">annotationsApi</span>.<span style="color:#a6e22e">getAnnotations</span>(<span style="color:#a6e22e">getAnnotationsRequest</span>);
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">annotationIds</span> <span style="color:#f92672">=</span> (<span style="color:#a6e22e">annotationsResult</span>.<span style="color:#a6e22e">annotations</span> <span style="color:#f92672">||</span> []).<span style="color:#a6e22e">map</span>(<span style="color:#a6e22e">a</span> =&gt; <span style="color:#a6e22e">a</span>.<span style="color:#a6e22e">id</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// 4. Delete all annotations (if any)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#66d9ef">if</span> (<span style="color:#a6e22e">annotationIds</span>.<span style="color:#a6e22e">length</span> <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">0</span>) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">deleteRequest</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">DeleteAnnotationsRequest</span>({
</span></span><span style="display:flex;"><span>            <span style="color:#a6e22e">fileInfo</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">fileInfo</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#a6e22e">annotationIds</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">annotationIds</span>
</span></span><span style="display:flex;"><span>        });
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">await</span> <span style="color:#a6e22e">annotationsApi</span>.<span style="color:#a6e22e">deleteAnnotations</span>(<span style="color:#a6e22e">deleteRequest</span>);
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// 5. Download the cleaned PDF back to local storage
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">downloadRequest</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">DownloadFileRequest</span>({
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">remoteFilePath</span>
</span></span><span style="display:flex;"><span>    });
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">fileStream</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">await</span> <span style="color:#a6e22e">storageApi</span>.<span style="color:#a6e22e">downloadFile</span>(<span style="color:#a6e22e">downloadRequest</span>);
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">fs</span>.<span style="color:#a6e22e">writeFileSync</span>(<span style="color:#a6e22e">localOutputPath</span>, <span style="color:#a6e22e">fileStream</span>);
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#e6db74">`All annotations removed. Clean file saved to </span><span style="color:#e6db74">${</span><span style="color:#a6e22e">localOutputPath</span><span style="color:#e6db74">}</span><span style="color:#e6db74">`</span>);
</span></span><span style="display:flex;"><span>})();
</span></span></code></pre></div><blockquote>
<p><strong>Note:</strong> This code example demonstrates the core functionality. Before using it in your project, make sure to update any file paths and configuration values to match your actual environment, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the <a href="https://docs.groupdocs.cloud/annotation/">official documentation</a> or reach out to the <a href="https://forum.groupdocs.cloud/c/annotation/10">support team</a> for assistance.</p>
</blockquote>
<h2 id="delete-pdf-annotations-via-rest-api-using-curl">Delete PDF Annotations via REST API Using cURL</h2>
<p>Below are the cURL commands that perform the same annotation removal workflow through the GroupDocs.Annotation Cloud REST endpoints.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># 1. Obtain an access token</span>
</span></span><span style="display:flex;"><span>curl -X POST <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/auth/token&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Content-Type: application/json&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -d <span style="color:#e6db74">&#34;{\&#34;client_id\&#34;:\&#34;YOUR_CLIENT_ID\&#34;,\&#34;client_secret\&#34;:\&#34;YOUR_CLIENT_SECRET\&#34;}&#34;</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># 2. Upload the source PDF</span>
</span></span><span style="display:flex;"><span>curl -X PUT <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/storage/file/input.pdf&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Authorization: Bearer YOUR_ACCESS_TOKEN&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Content-Type: application/pdf&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     --data-binary <span style="color:#e6db74">&#34;@input.pdf&#34;</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># 3. Retrieve annotation IDs</span>
</span></span><span style="display:flex;"><span>curl -X GET <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/annotation/annotations?filePath=input.pdf&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Authorization: Bearer YOUR_ACCESS_TOKEN&#34;</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># 4. Delete all retrieved annotations</span>
</span></span><span style="display:flex;"><span>curl -X DELETE <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/annotation/annotations?filePath=input.pdf&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Authorization: Bearer YOUR_ACCESS_TOKEN&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Content-Type: application/json&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -d <span style="color:#e6db74">&#34;{\&#34;annotationIds\&#34;:[\&#34;id1\&#34;,\&#34;id2\&#34;]}&#34;</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># 5. Download the cleaned PDF</span>
</span></span><span style="display:flex;"><span>curl -X GET <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/storage/file/input.pdf&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Authorization: Bearer YOUR_ACCESS_TOKEN&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -o output.pdf
</span></span></code></pre></div><p>For a complete list of endpoints and parameters, see the <a href="https://reference.groupdocs.cloud/annotation/">official API documentation</a>.</p>
<h2 id="how-remove-annotation-objects-from-pdf-with-rest-in-nodejs-works">How Remove Annotation Objects from PDF with REST in Node.JS Works</h2>
<ol>
<li><strong>Authentication Setup</strong> - The <code>Configuration</code> class is instantiated with your <code>clientId</code> and <code>clientSecret</code>, creating an authenticated context for all subsequent API calls.
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">config</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">Configuration</span>(<span style="color:#a6e22e">clientId</span>, <span style="color:#a6e22e">clientSecret</span>);
</span></span></code></pre></div></li>
<li><strong>File Upload</strong> - <code>UploadFileRequest</code> sends the local PDF bytes to GroupDocs Cloud storage. The <code>storageApi.uploadFile</code> method handles the transfer.
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">uploadRequest</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">UploadFileRequest</span>({
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">remoteFilePath</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">file</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">fileBytes</span>
</span></span><span style="display:flex;"><span>});
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">await</span> <span style="color:#a6e22e">storageApi</span>.<span style="color:#a6e22e">uploadFile</span>(<span style="color:#a6e22e">uploadRequest</span>);
</span></span></code></pre></div></li>
<li><strong>Retrieve Annotations</strong> - <code>GetAnnotationsRequest</code> builds a request object with a <code>FileInfo</code> reference. The <code>annotationsApi.getAnnotations</code> call returns a collection of annotation objects, from which IDs are extracted.
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">getAnnotationsRequest</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">GetAnnotationsRequest</span>({
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">fileInfo</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">fileInfo</span>
</span></span><span style="display:flex;"><span>});
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">annotationsResult</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">await</span> <span style="color:#a6e22e">annotationsApi</span>.<span style="color:#a6e22e">getAnnotations</span>(<span style="color:#a6e22e">getAnnotationsRequest</span>);
</span></span></code></pre></div></li>
<li><strong>Delete Annotations</strong> - If any IDs exist, <code>DeleteAnnotationsRequest</code> is populated and passed to <code>annotationsApi.deleteAnnotations</code>, which permanently removes the annotations from the stored PDF.
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">deleteRequest</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">DeleteAnnotationsRequest</span>({
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">fileInfo</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">fileInfo</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">annotationIds</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">annotationIds</span>
</span></span><span style="display:flex;"><span>});
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">await</span> <span style="color:#a6e22e">annotationsApi</span>.<span style="color:#a6e22e">deleteAnnotations</span>(<span style="color:#a6e22e">deleteRequest</span>);
</span></span></code></pre></div></li>
<li><strong>Download Clean PDF</strong> - Finally, <code>DownloadFileRequest</code> fetches the updated file, and <code>fs.writeFileSync</code> writes it to the local filesystem.
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">downloadRequest</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">DownloadFileRequest</span>({
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">remoteFilePath</span>
</span></span><span style="display:flex;"><span>});
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">fileStream</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">await</span> <span style="color:#a6e22e">storageApi</span>.<span style="color:#a6e22e">downloadFile</span>(<span style="color:#a6e22e">downloadRequest</span>);
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">fs</span>.<span style="color:#a6e22e">writeFileSync</span>(<span style="color:#a6e22e">localOutputPath</span>, <span style="color:#a6e22e">fileStream</span>);
</span></span></code></pre></div></li>
</ol>
<p>For detailed class and method definitions, refer to the <a href="https://reference.groupdocs.cloud/annotation/">API reference</a>.</p>
<h2 id="installing-and-configuring-groupdocsannotation-cloud-sdk-for-nodejs">Installing and Configuring GroupDocs.Annotation Cloud SDK for Node.js</h2>
<p>The SDK is distributed as an npm package. Install it with the command below and then require it in your project.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>npm install groupdocs-annotation-cloud
</span></span></code></pre></div><p>You can also download the latest package directly from the <a href="https://github.com/groupdocs-annotation-cloud/groupdocs-annotation-cloud-node">GitHub releases page</a> or the official <a href="https://releases.groupdocs.cloud/annotation/nodejs/">download URL</a>.</p>
<p>After installation, import the library and create a configuration object as shown in the code example:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">require</span>(<span style="color:#e6db74">&#34;@groupdocs/annotation-cloud&#34;</span>);
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">config</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">GroupDocsAnnotationCloud</span>.<span style="color:#a6e22e">Configuration</span>(<span style="color:#e6db74">&#34;YOUR_CLIENT_ID&#34;</span>, <span style="color:#e6db74">&#34;YOUR_CLIENT_SECRET&#34;</span>);
</span></span></code></pre></div><p>Make sure your runtime environment meets the Node.js version requirements and that you have a valid GroupDocs account to obtain the client credentials.</p>
<h2 id="annotation-removal-options-and-settings">Annotation Removal Options and Settings</h2>
<p>The SDK exposes several parameters you can tune:</p>
<ul>
<li><strong>clientId / clientSecret</strong> - Credentials for OAuth authentication. Set them in the <code>Configuration</code> constructor.</li>
<li><strong>fileInfo.filePath</strong> - The path of the PDF in GroupDocs Cloud storage. Adjust this if you store files in a different folder.</li>
<li><strong>annotationIds</strong> - An array of IDs returned by <code>GetAnnotations</code>. Supplying a subset allows selective deletion.</li>
</ul>
<p>Additional settings such as request timeouts and proxy configuration are available in the SDK documentation; see the <a href="https://docs.groupdocs.cloud/annotation/">official documentation</a> for the full list.</p>
<h2 id="best-practices-for-removing-pdf-annotations-via-rest">Best Practices for Removing PDF Annotations via REST</h2>
<ul>
<li><strong>Validate Annotation IDs</strong> - Always check that the IDs you intend to delete exist; attempting to delete non‑existent IDs can cause a 404 error.</li>
<li><strong>Use HTTPS</strong> - All API calls must be made over HTTPS to protect your credentials and document data.</li>
<li><strong>Handle Large Files with Chunked Uploads</strong> - For PDFs larger than 100 MB, prefer the multipart upload endpoint to avoid timeouts.</li>
<li><strong>Log API Responses</strong> - Store request IDs and responses for audit trails and easier troubleshooting.</li>
<li><strong>Reuse Access Tokens</strong> - Cache the OAuth token until it expires to reduce authentication overhead.</li>
</ul>
<h2 id="common-questions">Common Questions</h2>
<ul>
<li>
<p><strong>How do I authenticate with GroupDocs.Annotation Cloud API?</strong><br>
Obtain a client ID and secret from your GroupDocs account, then request an access token via the OAuth endpoint. See the <a href="https://docs.groupdocs.cloud/annotation/">official documentation</a> for details.</p>
</li>
<li>
<p><strong>Can I delete specific annotations instead of all?</strong><br>
Yes, provide the IDs of the annotations you want to remove in the DeleteAnnotationsRequest. The SDK returns the list of annotation IDs after a GetAnnotations call.</p>
</li>
<li>
<p><strong>How can I remove Annotation objects from PDF with REST in Node.JS?</strong><br>
Use the GroupDocs.Annotation Cloud SDK for Node.js to call the DeleteAnnotations endpoint after retrieving annotation IDs. The full workflow is demonstrated in the code example and cURL section of this guide.</p>
</li>
<li>
<p><strong>What licensing is required for production use?</strong><br>
A paid license is needed for production. You can acquire a temporary license from the <a href="https://purchase.groupdocs.cloud/temporary-license/">temporary license page</a> while evaluating.</p>
</li>
</ul>
<h2 id="further-reading">Further Reading</h2>
<ul>
<li><a href="https://blog.groupdocs.cloud/annotation/extract-or-remove-annotations-from-pdf-using-rest-api-in-node-js/">Extract or Remove Annotations from PDF using REST API in Node.js</a></li>
<li><a href="https://blog.groupdocs.cloud/annotation/strikethrough-text-in-a-pdf-using-nodejs/">Strikethrough Text in a PDF with Node.js and REST API</a></li>
<li><a href="https://blog.groupdocs.cloud/annotation/remove-annotations-from-pdf-using-rest-api-in-python/">Remove Annotations from PDF using REST API in Python</a></li>
</ul>
]]></content:encoded>
    </item>
    
    <item>
      <title>Merge PDF in Node.JS</title>
      <link>https://blog-qa.groupdocs.cloud/merger/merge-pdf-in-nodejs/</link>
      <pubDate>Mon, 19 Oct 2026 15:04:19 +0000</pubDate>
      
      <guid>https://blog-qa.groupdocs.cloud/merger/merge-pdf-in-nodejs/</guid>
      <description>Learn how to merge PDF files in Node.JS using GroupDocs.Merger Cloud SDK. Step-by-step guide, code example, cURL commands, and performance tips for developers.</description>
      <content:encoded><![CDATA[<p>Combining multiple <a href="https://docs.fileformat.com/pdf">PDF</a> documents into a single file is a frequent requirement when building document workflows or generating reports. <a href="https://products.groupdocs.cloud/merger/nodejs/">GroupDocs.Merger Cloud SDK for Node.js</a> makes it easy to merge PDF in Node.JS without dealing with low‑level PDF structures. This guide walks you through setup, a step‑by‑step implementation, a full code example, equivalent cURL calls, and performance tips for large or encrypted PDFs.</p>
<h2 id="before-you-start-prerequisites-and-installation">Before You Start: Prerequisites and Installation</h2>
<p>Before you begin, ensure you have the following:</p>
<ul>
<li>Node.js 14 or later installed on your development machine.</li>
<li>An active GroupDocs Cloud account with client ID and client secret.</li>
<li>Access to the PDF files you want to combine, stored in GroupDocs Cloud storage.</li>
</ul>
<p>Install the SDK via npm and download the latest package:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>npm install groupdocs-merger-cloud
</span></span></code></pre></div><p>You can also retrieve the SDK from the official release page: <a href="https://releases.groupdocs.cloud/merger/nodejs/">Download SDK</a>. After installation, you are ready to start coding.</p>
<h2 id="step-by-step-guide-to-merge-pdf-in-nodejs">Step-by-Step Guide to Merge PDF in Node.JS</h2>
<h3 id="step-1-install-sdk-and-import-required-classes">Step 1: Install SDK and Import Required Classes</h3>
<p>First, import the classes you will need for merging PDFs.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> { <span style="color:#a6e22e">MergeApi</span>, <span style="color:#a6e22e">MergeOptions</span>, <span style="color:#a6e22e">FileInfo</span>, <span style="color:#a6e22e">Configuration</span> } <span style="color:#f92672">=</span> <span style="color:#a6e22e">require</span>(<span style="color:#e6db74">&#34;@groupdocs/merger-cloud&#34;</span>);
</span></span></code></pre></div><p>This import gives you access to the core API, configuration objects, and file descriptors.</p>
<h3 id="step-2-configure-your-groupdocs-credentials">Step 2: Configure Your GroupDocs Credentials</h3>
<p>Create a configuration object with your client credentials.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">config</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Configuration</span>({
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">clientId</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#34;YOUR_CLIENT_ID&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">clientSecret</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#34;YOUR_CLIENT_SECRET&#34;</span>
</span></span><span style="display:flex;"><span>});
</span></span></code></pre></div><p>Providing the correct credentials lets the library authenticate your requests.</p>
<h3 id="step-3-define-the-pdf-files-to-merge">Step 3: Define the PDF Files to Merge</h3>
<p>List the PDF documents you want to combine. This step prepares you to merge PDF in Node.JS efficiently.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">filesToMerge</span> <span style="color:#f92672">=</span> [
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">FileInfo</span>({ <span style="color:#a6e22e">filePath</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#34;input1.pdf&#34;</span> }),
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">FileInfo</span>({ <span style="color:#a6e22e">filePath</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#34;input2.pdf&#34;</span> })
</span></span><span style="display:flex;"><span>];
</span></span></code></pre></div><p>Each <code>FileInfo</code> points to a file stored in your GroupDocs Cloud storage.</p>
<h3 id="step-4-set-merge-options">Step 4: Set Merge Options</h3>
<p>Configure the output location and attach the file list to the merge request.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">mergeOptions</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">MergeOptions</span>();
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">mergeOptions</span>.<span style="color:#a6e22e">fileInfos</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">filesToMerge</span>;
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">mergeOptions</span>.<span style="color:#a6e22e">outputPath</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;merged_output.pdf&#34;</span>;
</span></span></code></pre></div><p>These settings control how you merge PDF in Node.JS and where the result will be saved.</p>
<h3 id="step-5-execute-the-merge-operation">Step 5: Execute the Merge Operation</h3>
<p>Create the API instance, call the merge method, and handle the response.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">mergeApi</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">MergeApi</span>(<span style="color:#a6e22e">config</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">try</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">result</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">await</span> <span style="color:#a6e22e">mergeApi</span>.<span style="color:#a6e22e">mergeDocuments</span>(<span style="color:#a6e22e">mergeOptions</span>);
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#e6db74">&#34;Merge completed. Output file stored at:&#34;</span>, <span style="color:#a6e22e">result</span>.<span style="color:#a6e22e">path</span>);
</span></span><span style="display:flex;"><span>} <span style="color:#66d9ef">catch</span> (<span style="color:#a6e22e">error</span>) {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">error</span>(<span style="color:#e6db74">&#34;Error during PDF merge:&#34;</span>, <span style="color:#a6e22e">error</span>);
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>The async call returns the path of the merged document if the operation succeeds.</p>
<h2 id="full-implementation-example-for-merging-pdfs-in-nodejs">Full Implementation Example for Merging PDFs in Node.JS</h2>
<p>The following code demonstrates the complete workflow from configuration to result handling.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> { <span style="color:#a6e22e">MergeApi</span>, <span style="color:#a6e22e">MergeOptions</span>, <span style="color:#a6e22e">FileInfo</span>, <span style="color:#a6e22e">Configuration</span> } <span style="color:#f92672">=</span> <span style="color:#a6e22e">require</span>(<span style="color:#e6db74">&#34;@groupdocs/merger-cloud&#34;</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// Configure the SDK (replace with your actual credentials)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">config</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Configuration</span>({
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">clientId</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#34;YOUR_CLIENT_ID&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">clientSecret</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#34;YOUR_CLIENT_SECRET&#34;</span>
</span></span><span style="display:flex;"><span>});
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">async</span> <span style="color:#66d9ef">function</span> <span style="color:#a6e22e">mergePdfFiles</span>() {
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// Initialize the Merge API
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">mergeApi</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">MergeApi</span>(<span style="color:#a6e22e">config</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// Define the PDF files to be merged (must exist in GroupDocs Cloud storage)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">filesToMerge</span> <span style="color:#f92672">=</span> [
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">FileInfo</span>({ <span style="color:#a6e22e">filePath</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#34;input1.pdf&#34;</span> }),
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">FileInfo</span>({ <span style="color:#a6e22e">filePath</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#34;input2.pdf&#34;</span> })
</span></span><span style="display:flex;"><span>    ];
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// Set merge options
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">mergeOptions</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">MergeOptions</span>();
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">mergeOptions</span>.<span style="color:#a6e22e">fileInfos</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">filesToMerge</span>;
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">mergeOptions</span>.<span style="color:#a6e22e">outputPath</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;merged_output.pdf&#34;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">try</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// Perform the merge operation
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">result</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">await</span> <span style="color:#a6e22e">mergeApi</span>.<span style="color:#a6e22e">mergeDocuments</span>(<span style="color:#a6e22e">mergeOptions</span>);
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#e6db74">&#34;Merge completed. Output file stored at:&#34;</span>, <span style="color:#a6e22e">result</span>.<span style="color:#a6e22e">path</span>);
</span></span><span style="display:flex;"><span>    } <span style="color:#66d9ef">catch</span> (<span style="color:#a6e22e">error</span>) {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">error</span>(<span style="color:#e6db74">&#34;Error during PDF merge:&#34;</span>, <span style="color:#a6e22e">error</span>);
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// Execute the merge
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#a6e22e">mergePdfFiles</span>();
</span></span></code></pre></div><blockquote>
<p><strong>Note:</strong> This code example demonstrates the core functionality. Before using it in your project, make sure to update any file paths and configuration values to match your actual environment, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the <a href="https://docs.groupdocs.cloud/merger/">official documentation</a> or reach out to the <a href="https://forum.groupdocs.cloud/c/merger/18">support team</a> for assistance.</p>
</blockquote>
<h2 id="merging-pdfs-via-rest-api-using-curl">Merging PDFs via REST API Using cURL</h2>
<p>If you prefer a pure REST approach, the same operation can be performed with cURL commands.</p>
<p>First, obtain an access token:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl -X POST <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/oauth2/token&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Content-Type: application/json&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -d <span style="color:#e6db74">&#39;{&#34;client_id&#34;:&#34;YOUR_CLIENT_ID&#34;,&#34;client_secret&#34;:&#34;YOUR_CLIENT_SECRET&#34;,&#34;grant_type&#34;:&#34;client_credentials&#34;}&#39;</span>
</span></span></code></pre></div><p>Upload the source PDFs to your storage (replace <code>YOUR_ACCESS_TOKEN</code> with the token from the previous step):</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl -X POST <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/storage/file/upload?path=input1.pdf&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Authorization: Bearer YOUR_ACCESS_TOKEN&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -F <span style="color:#e6db74">&#34;file=@/local/path/input1.pdf&#34;</span>
</span></span></code></pre></div><p>Repeat the upload for <code>input2.pdf</code>. Then request the merge operation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl -X POST <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/merger/merge&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Authorization: Bearer YOUR_ACCESS_TOKEN&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Content-Type: application/json&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -d <span style="color:#e6db74">&#39;{
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">           &#34;fileInfos&#34;: [
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">               {&#34;filePath&#34;:&#34;input1.pdf&#34;},
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">               {&#34;filePath&#34;:&#34;input2.pdf&#34;}
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">           ],
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">           &#34;outputPath&#34;:&#34;merged_output.pdf&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">         }&#39;</span>
</span></span></code></pre></div><p>Finally, download the merged file:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl -X GET <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/storage/file/download?path=merged_output.pdf&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Authorization: Bearer YOUR_ACCESS_TOKEN&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -o merged_output.pdf
</span></span></code></pre></div><p>For a complete list of endpoints and parameters, see the <a href="https://reference.groupdocs.cloud/merger/">API reference</a>.</p>
<h2 id="configuring-merge-options">Configuring Merge Options</h2>
<p>The SDK exposes several options that let you fine‑tune the merge process:</p>
<ul>
<li><strong>outputPath</strong> - Destination path for the merged PDF. Adjust this to control where the result is stored.</li>
<li><strong>fileInfos</strong> - An array of <code>FileInfo</code> objects that define the source PDFs and their order.</li>
</ul>
<p>You can also set additional properties such as <code>pages</code> to merge specific page ranges, or <code>password</code> for encrypted PDFs. Refer to the <a href="https://docs.groupdocs.cloud/merger/">official documentation</a> for the full list of configurable fields.</p>
<h2 id="performance-considerations-for-merging-pdfs">Performance Considerations for Merging PDFs</h2>
<p>When merging large or many PDF files, keep these tips in mind:</p>
<ul>
<li><strong>Use async/await</strong> to avoid blocking the event loop, especially for big documents.</li>
<li><strong>Batch uploads</strong>: upload source PDFs in parallel before invoking the merge to reduce overall latency.</li>
<li><strong>Streamed processing</strong>: for extremely large PDFs, consider storing intermediate results in cloud storage and merging them in smaller chunks.</li>
<li><strong>Encrypted PDFs</strong>: provide passwords in the <code>FileInfo</code> objects; processing encrypted files adds overhead, so merge them after decryption when possible.</li>
</ul>
<p>Applying these practices helps you merge PDF in Node.JS efficiently while minimizing memory consumption.</p>
<h2 id="questions-you-might-have">Questions You Might Have</h2>
<ul>
<li>
<p><strong>How do I merge PDF files in Node.JS using GroupDocs?</strong><br>
Use the <a href="https://products.groupdocs.cloud/merger/nodejs/">GroupDocs.Merger Cloud SDK for Node.js</a> to create a <code>MergeApi</code> instance, configure <code>MergeOptions</code> with your source PDFs, and call <code>mergeDocuments</code>. The full code example in this guide demonstrates the process.</p>
</li>
<li>
<p><strong>Can I merge encrypted PDF files in Node.JS?</strong><br>
Yes, the SDK supports merging encrypted PDFs. Provide the correct passwords in the <code>FileInfo</code> objects before calling <code>mergeDocuments</code>. See the <a href="https://docs.groupdocs.cloud/merger/">official documentation</a> for details.</p>
</li>
<li>
<p><strong>What are the licensing options for GroupDocs.Merger?</strong><br>
GroupDocs offers flexible pricing plans. For testing, you can request a <a href="https://purchase.groupdocs.cloud/temporary-license/">temporary license</a> to evaluate the library before purchasing a full subscription.</p>
</li>
<li>
<p><strong>Where can I find more examples and support?</strong><br>
Additional samples are available on the <a href="https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node">GitHub repository</a>. For help, visit the <a href="https://forum.groupdocs.cloud/c/merger/18">support forum</a>.</p>
</li>
</ul>
<h2 id="further-reading">Further Reading</h2>
<ul>
<li><a href="https://blog.groupdocs.cloud/merger/split-pdf-into-multiple-pdf-in-nodejs/">Split PDF into Multiple PDF in Node.JS</a></li>
<li><a href="https://blog.groupdocs.cloud/merger/lock-pdf-with-password-using-rest-api-in-nodejs/">Lock PDF Documents with Passwords using REST API in Node.js</a></li>
<li><a href="https://blog.groupdocs.cloud/merger/how-to-merge-pdf-files-in-csharp-using-rest-api/">How to Merge PDF Files in C# using REST API</a></li>
</ul>
]]></content:encoded>
    </item>
    
    <item>
      <title>Add Image Watermark to PDF Documents in Java</title>
      <link>https://blog-qa.groupdocs.cloud/watermark/add-image-watermark-to-pdf-documents-in-java/</link>
      <pubDate>Fri, 28 Aug 2026 19:41:04 +0000</pubDate>
      
      <guid>https://blog-qa.groupdocs.cloud/watermark/add-image-watermark-to-pdf-documents-in-java/</guid>
      <description>Learn how to add an image watermark to PDF documents in Java using GroupDocs.Watermark Cloud SDK. Step-by-step guide with code, cURL and configuration tips.</description>
      <content:encoded><![CDATA[<p>Adding a visual identifier to <a href="https://docs.fileformat.com/pdf">PDF</a> files is essential for protecting intellectual property and branding documents. <a href="https://products.groupdocs.cloud/watermark/java/">GroupDocs.Watermark Cloud SDK for Java</a> offers a straightforward API to embed image watermarks directly into PDFs from your Java application. In this tutorial you will learn how to add image watermark to PDF documents in Java, see a complete working example, and explore the equivalent cURL REST calls for cloud integration.</p>
<h2 id="add-image-watermark-to-pdf-documents-in-java-in-5-steps">Add Image Watermark to PDF Documents in Java in 5 Steps</h2>
<ol>
<li>
<p><strong>Initialize the API client</strong>: Create an <code>ApiClient</code> instance with your client ID and secret.</p>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span>ApiClient apiClient <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> ApiClient<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;YOUR_CLIENT_ID&#34;</span><span style="color:#f92672">,</span> <span style="color:#e6db74">&#34;YOUR_CLIENT_SECRET&#34;</span><span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>WatermarkApi watermarkApi <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> WatermarkApi<span style="color:#f92672">(</span>apiClient<span style="color:#f92672">);</span>
</span></span></code></pre></div><!--[CODE_SNIPPET_END]-->  
<p>This step connects your Java code to the GroupDocs.Watermark Cloud service. See the <a href="https://reference.groupdocs.cloud/watermark/">API reference</a> for more details.</p>
</li>
<li>
<p><strong>Specify the source PDF file</strong>: Build a <code>FileInfo</code> object that points to the PDF you want to watermark.</p>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span>FileInfo fileInfo <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> FileInfo<span style="color:#f92672">();</span>
</span></span><span style="display:flex;"><span>fileInfo<span style="color:#f92672">.</span><span style="color:#a6e22e">setFilePath</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;input.pdf&#34;</span><span style="color:#f92672">);</span>
</span></span></code></pre></div><!--[CODE_SNIPPET_END]-->  
<p>The file must be uploaded to your GroupDocs storage before the request.</p>
</li>
<li>
<p><strong>Configure the image watermark</strong>: Define the image path, opacity, scale factor, rotation and alignment.</p>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span>ImageWatermark imageWatermark <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> ImageWatermark<span style="color:#f92672">();</span>
</span></span><span style="display:flex;"><span>imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setImagePath</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;watermark.png&#34;</span><span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setOpacity</span><span style="color:#f92672">(</span>0<span style="color:#f92672">.</span><span style="color:#a6e22e">5</span><span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setScaleFactor</span><span style="color:#f92672">(</span>0<span style="color:#f92672">.</span><span style="color:#a6e22e">3</span><span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setHorizontalAlignment</span><span style="color:#f92672">(</span>HorizontalAlignment<span style="color:#f92672">.</span><span style="color:#a6e22e">CENTER</span><span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setVerticalAlignment</span><span style="color:#f92672">(</span>VerticalAlignment<span style="color:#f92672">.</span><span style="color:#a6e22e">CENTER</span><span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setMargin</span><span style="color:#f92672">(</span><span style="color:#66d9ef">new</span> Margin<span style="color:#f92672">(</span>10<span style="color:#f92672">,</span> 10<span style="color:#f92672">,</span> 10<span style="color:#f92672">,</span> 10<span style="color:#f92672">));</span>
</span></span></code></pre></div><!--[CODE_SNIPPET_END]-->  
<p>Adjust these values to achieve the desired appearance opacity controls transparency, while scaleFactor determines the size relative to the page.</p>
</li>
<li>
<p><strong>Set watermark options and output path</strong>: Combine the file info and watermark into a <code>WatermarkOptions</code> object.</p>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span>WatermarkOptions options <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> WatermarkOptions<span style="color:#f92672">();</span>
</span></span><span style="display:flex;"><span>options<span style="color:#f92672">.</span><span style="color:#a6e22e">setFileInfo</span><span style="color:#f92672">(</span>fileInfo<span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>options<span style="color:#f92672">.</span><span style="color:#a6e22e">setImageWatermark</span><span style="color:#f92672">(</span>imageWatermark<span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>options<span style="color:#f92672">.</span><span style="color:#a6e22e">setOutputPath</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;output.pdf&#34;</span><span style="color:#f92672">);</span>
</span></span></code></pre></div><!--[CODE_SNIPPET_END]-->  
<p>The <code>outputPath</code> tells the service where to store the resulting PDF.</p>
</li>
<li>
<p><strong>Execute the request</strong>: Build an <code>AddWatermarkRequest</code> and call the API. Handle success or error responses.</p>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span>AddWatermarkRequest request <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> AddWatermarkRequest<span style="color:#f92672">(</span>options<span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">try</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    AddWatermarkResponse response <span style="color:#f92672">=</span> watermarkApi<span style="color:#f92672">.</span><span style="color:#a6e22e">addWatermark</span><span style="color:#f92672">(</span>request<span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>    System<span style="color:#f92672">.</span><span style="color:#a6e22e">out</span><span style="color:#f92672">.</span><span style="color:#a6e22e">println</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Watermark added successfully. Output file: &#34;</span> <span style="color:#f92672">+</span> response<span style="color:#f92672">.</span><span style="color:#a6e22e">getPath</span><span style="color:#f92672">());</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span> <span style="color:#66d9ef">catch</span> <span style="color:#f92672">(</span>Exception e<span style="color:#f92672">)</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    System<span style="color:#f92672">.</span><span style="color:#a6e22e">err</span><span style="color:#f92672">.</span><span style="color:#a6e22e">println</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Error adding watermark: &#34;</span> <span style="color:#f92672">+</span> e<span style="color:#f92672">.</span><span style="color:#a6e22e">getMessage</span><span style="color:#f92672">());</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span></code></pre></div><!--[CODE_SNIPPET_END]-->  
<p>After execution, the watermarked PDF is available at the location you specified.</p>
</li>
</ol>
<h2 id="complete-code-example-add-image-watermark-to-pdf-documents-in-java">Complete Code Example: Add Image Watermark to PDF Documents in Java</h2>
<p>The following example demonstrates the full implementation from client initialization to saving the watermarked PDF.</p>
<!--[COMPLETE_CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#f92672">import</span> com.groupdocs.cloud.watermark.api.WatermarkApi<span style="color:#f92672">;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> com.groupdocs.cloud.watermark.client.ApiClient<span style="color:#f92672">;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> com.groupdocs.cloud.watermark.model.AddWatermarkRequest<span style="color:#f92672">;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> com.groupdocs.cloud.watermark.model.AddWatermarkResponse<span style="color:#f92672">;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> com.groupdocs.cloud.watermark.model.FileInfo<span style="color:#f92672">;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> com.groupdocs.cloud.watermark.model.ImageWatermark<span style="color:#f92672">;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> com.groupdocs.cloud.watermark.model.Margin<span style="color:#f92672">;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> com.groupdocs.cloud.watermark.model.WatermarkOptions<span style="color:#f92672">;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> com.groupdocs.cloud.watermark.model.enums.HorizontalAlignment<span style="color:#f92672">;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> com.groupdocs.cloud.watermark.model.enums.VerticalAlignment<span style="color:#f92672">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">AddImageWatermarkExample</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">public</span> <span style="color:#66d9ef">static</span> <span style="color:#66d9ef">void</span> <span style="color:#a6e22e">main</span><span style="color:#f92672">(</span>String<span style="color:#f92672">[]</span> args<span style="color:#f92672">)</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// Initialize API client (replace with your actual credentials)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        ApiClient apiClient <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> ApiClient<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;YOUR_CLIENT_ID&#34;</span><span style="color:#f92672">,</span> <span style="color:#e6db74">&#34;YOUR_CLIENT_SECRET&#34;</span><span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>        WatermarkApi watermarkApi <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> WatermarkApi<span style="color:#f92672">(</span>apiClient<span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// Input PDF file information
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        FileInfo fileInfo <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> FileInfo<span style="color:#f92672">();</span>
</span></span><span style="display:flex;"><span>        fileInfo<span style="color:#f92672">.</span><span style="color:#a6e22e">setFilePath</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;input.pdf&#34;</span><span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// Image watermark configuration
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        ImageWatermark imageWatermark <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> ImageWatermark<span style="color:#f92672">();</span>
</span></span><span style="display:flex;"><span>        imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setImagePath</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;watermark.png&#34;</span><span style="color:#f92672">);</span>          <span style="color:#75715e">// Path to watermark image
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setOpacity</span><span style="color:#f92672">(</span>0<span style="color:#f92672">.</span><span style="color:#a6e22e">5</span><span style="color:#f92672">);</span>                        <span style="color:#75715e">// 50% opacity
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setScaleFactor</span><span style="color:#f92672">(</span>0<span style="color:#f92672">.</span><span style="color:#a6e22e">3</span><span style="color:#f92672">);</span>                    <span style="color:#75715e">// 30% of page size
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setRotationAngle</span><span style="color:#f92672">(</span>0<span style="color:#f92672">);</span>                    <span style="color:#75715e">// No rotation
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setHorizontalAlignment</span><span style="color:#f92672">(</span>HorizontalAlignment<span style="color:#f92672">.</span><span style="color:#a6e22e">CENTER</span><span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>        imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setVerticalAlignment</span><span style="color:#f92672">(</span>VerticalAlignment<span style="color:#f92672">.</span><span style="color:#a6e22e">CENTER</span><span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>        imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setMargin</span><span style="color:#f92672">(</span><span style="color:#66d9ef">new</span> Margin<span style="color:#f92672">(</span>10<span style="color:#f92672">,</span> 10<span style="color:#f92672">,</span> 10<span style="color:#f92672">,</span> 10<span style="color:#f92672">));</span>  <span style="color:#75715e">// 10 points margin on all sides
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// Watermark options
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        WatermarkOptions options <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> WatermarkOptions<span style="color:#f92672">();</span>
</span></span><span style="display:flex;"><span>        options<span style="color:#f92672">.</span><span style="color:#a6e22e">setFileInfo</span><span style="color:#f92672">(</span>fileInfo<span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>        options<span style="color:#f92672">.</span><span style="color:#a6e22e">setImageWatermark</span><span style="color:#f92672">(</span>imageWatermark<span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>        options<span style="color:#f92672">.</span><span style="color:#a6e22e">setOutputPath</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;output.pdf&#34;</span><span style="color:#f92672">);</span> <span style="color:#75715e">// Resulting PDF with watermark
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// Create request and call API
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        AddWatermarkRequest request <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> AddWatermarkRequest<span style="color:#f92672">(</span>options<span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">try</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>            AddWatermarkResponse response <span style="color:#f92672">=</span> watermarkApi<span style="color:#f92672">.</span><span style="color:#a6e22e">addWatermark</span><span style="color:#f92672">(</span>request<span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>            System<span style="color:#f92672">.</span><span style="color:#a6e22e">out</span><span style="color:#f92672">.</span><span style="color:#a6e22e">println</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Watermark added successfully. Output file: &#34;</span> <span style="color:#f92672">+</span> response<span style="color:#f92672">.</span><span style="color:#a6e22e">getPath</span><span style="color:#f92672">());</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">}</span> <span style="color:#66d9ef">catch</span> <span style="color:#f92672">(</span>Exception e<span style="color:#f92672">)</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>            System<span style="color:#f92672">.</span><span style="color:#a6e22e">err</span><span style="color:#f92672">.</span><span style="color:#a6e22e">println</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Error adding watermark: &#34;</span> <span style="color:#f92672">+</span> e<span style="color:#f92672">.</span><span style="color:#a6e22e">getMessage</span><span style="color:#f92672">());</span>
</span></span><span style="display:flex;"><span>            e<span style="color:#f92672">.</span><span style="color:#a6e22e">printStackTrace</span><span style="color:#f92672">();</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span></code></pre></div><!--[COMPLETE_CODE_SNIPPET_END]-->
<blockquote>
<p><strong>Note:</strong> This code example demonstrates the core functionality. Before using it in your project, make sure to update the file paths (<code>input.pdf</code>, <code>watermark.png</code>, <code>output.pdf</code>) to match your actual file locations, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the <a href="https://docs.groupdocs.cloud/watermark/">official documentation</a> or reach out to the <a href="https://forum.groupdocs.cloud/c/watermark/29">support team</a> for assistance.</p>
</blockquote>
<h2 id="apply-image-watermark-to-pdf-documents-via-curl-and-rest-api">Apply Image Watermark to PDF Documents via cURL and REST API</h2>
<p>Below are the REST calls you can use with cURL to achieve the same result without writing Java code.</p>
<ol>
<li>
<p><strong>Obtain an access token</strong></p>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl -X POST <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/auth/token&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Content-Type: application/json&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -d <span style="color:#e6db74">&#39;{&#34;client_id&#34;:&#34;YOUR_CLIENT_ID&#34;,&#34;client_secret&#34;:&#34;YOUR_CLIENT_SECRET&#34;}&#39;</span>
</span></span></code></pre></div><!--[CODE_SNIPPET_END]-->  
<p>The response contains an <code>access_token</code> used in subsequent calls.</p>
</li>
<li>
<p><strong>Upload the source PDF</strong></p>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl -X POST <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/storage/upload?path=input.pdf&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Authorization: Bearer YOUR_ACCESS_TOKEN&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -F <span style="color:#e6db74">&#34;file=@/path/to/input.pdf&#34;</span>
</span></span></code></pre></div><!--[CODE_SNIPPET_END]-->
</li>
<li>
<p><strong>Upload the watermark image</strong></p>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl -X POST <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/storage/upload?path=watermark.png&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Authorization: Bearer YOUR_ACCESS_TOKEN&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -F <span style="color:#e6db74">&#34;file=@/path/to/watermark.png&#34;</span>
</span></span></code></pre></div><!--[CODE_SNIPPET_END]-->
</li>
<li>
<p><strong>Add the image watermark</strong></p>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl -X POST <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/watermark/add&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Authorization: Bearer YOUR_ACCESS_TOKEN&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Content-Type: application/json&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -d <span style="color:#e6db74">&#39;{
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">           &#34;fileInfo&#34;: { &#34;filePath&#34;: &#34;input.pdf&#34; },
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">           &#34;imageWatermark&#34;: {
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">               &#34;imagePath&#34;: &#34;watermark.png&#34;,
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">               &#34;opacity&#34;: 0.5,
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">               &#34;scaleFactor&#34;: 0.3,
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">               &#34;horizontalAlignment&#34;: &#34;Center&#34;,
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">               &#34;verticalAlignment&#34;: &#34;Center&#34;,
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">               &#34;margin&#34;: { &#34;top&#34;: 10, &#34;right&#34;: 10, &#34;bottom&#34;: 10, &#34;left&#34;: 10 }
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">           },
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">           &#34;outputPath&#34;: &#34;output.pdf&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">         }&#39;</span>
</span></span></code></pre></div><!--[CODE_SNIPPET_END]-->  
<p>This request mirrors the Java code logic, applying the same opacity, scaling and alignment settings.</p>
</li>
<li>
<p><strong>Download the watermarked PDF</strong></p>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl -X GET <span style="color:#e6db74">&#34;https://api.groupdocs.cloud/v2.0/storage/download?path=output.pdf&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -H <span style="color:#e6db74">&#34;Authorization: Bearer YOUR_ACCESS_TOKEN&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>     -o output.pdf
</span></span></code></pre></div><!--[CODE_SNIPPET_END]-->  
</li>
</ol>
<p>For more details on request bodies and supported parameters, see the <a href="https://reference.groupdocs.cloud/watermark/">official API documentation</a>.</p>
<h2 id="installing-and-configuring-groupdocswatermark-cloud-sdk-for-java">Installing and Configuring GroupDocs.Watermark Cloud SDK for Java</h2>
<p>Add the Maven dependency to your <code>pom.xml</code> (or the equivalent Gradle snippet). The library is hosted on Maven Central.</p>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#f92672">&lt;dependency&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&lt;groupId&gt;</span>com.groupdocs<span style="color:#f92672">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&lt;artifactId&gt;</span>groupdocs-watermark-cloud<span style="color:#f92672">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&lt;version&gt;</span>23.8<span style="color:#f92672">&lt;/version&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/dependency&gt;</span>
</span></span></code></pre></div><!--[CODE_SNIPPET_END]-->
<p>You also need a valid GroupDocs Cloud account. Retrieve your <strong>Client ID</strong> and <strong>Client Secret</strong> from the <a href="https://products.groupdocs.cloud/watermark/java/">GroupDocs portal</a>. No additional runtime installation is required because the SDK communicates with the cloud service.</p>
<h2 id="fine-tuning-image-watermark-options-for-pdf-documents">Fine-Tuning Image Watermark Options for PDF Documents</h2>
<p>The SDK exposes several properties that let you control the visual appearance of the watermark.</p>
<h3 id="adjust-opacity">Adjust Opacity</h3>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span>imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setOpacity</span><span style="color:#f92672">(</span>0<span style="color:#f92672">.</span><span style="color:#a6e22e">75</span><span style="color:#f92672">);</span> <span style="color:#75715e">// 75% opacity for a more visible watermark
</span></span></span></code></pre></div><!--[CODE_SNIPPET_END]-->  
<p>Opacity values range from 0.0 (fully transparent) to 1.0 (fully opaque).</p>
<h3 id="change-scale-factor">Change Scale Factor</h3>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span>imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setScaleFactor</span><span style="color:#f92672">(</span>0<span style="color:#f92672">.</span><span style="color:#a6e22e">5</span><span style="color:#f92672">);</span> <span style="color:#75715e">// Watermark occupies 50% of the page width
</span></span></span></code></pre></div><!--[CODE_SNIPPET_END]-->  
<p>The scale factor determines the watermark size relative to the page dimensions.</p>
<h3 id="set-alignment-and-margins">Set Alignment and Margins</h3>
<!--[CODE_SNIPPET_START]-->
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span>imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setHorizontalAlignment</span><span style="color:#f92672">(</span>HorizontalAlignment<span style="color:#f92672">.</span><span style="color:#a6e22e">RIGHT</span><span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setVerticalAlignment</span><span style="color:#f92672">(</span>VerticalAlignment<span style="color:#f92672">.</span><span style="color:#a6e22e">BOTTOM</span><span style="color:#f92672">);</span>
</span></span><span style="display:flex;"><span>imageWatermark<span style="color:#f92672">.</span><span style="color:#a6e22e">setMargin</span><span style="color:#f92672">(</span><span style="color:#66d9ef">new</span> Margin<span style="color:#f92672">(</span>20<span style="color:#f92672">,</span> 20<span style="color:#f92672">,</span> 20<span style="color:#f92672">,</span> 20<span style="color:#f92672">));</span>
</span></span></code></pre></div><!--[CODE_SNIPPET_END]-->  
<p>These settings place the watermark in the lower‑right corner with a 20‑point margin.</p>
<p>For a complete list of configurable properties, refer to the <a href="https://reference.groupdocs.cloud/watermark/">API reference</a>.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Adding an image watermark to PDF documents in Java is a straightforward task when you use the <a href="https://products.groupdocs.cloud/watermark/java/">GroupDocs.Watermark Cloud SDK for Java</a>. The SDK handles all low‑level PDF manipulation, letting you focus on the visual aspects such as opacity, scaling and positioning. Whether you prefer a native Java implementation or a cloud‑based cURL workflow, the same high‑quality results are achievable without sacrificing performance. Remember to obtain a proper license for production use; pricing details are available on the product page and a <a href="https://purchase.groupdocs.cloud/temporary-license/">temporary license page</a> can be used for evaluation.</p>
<h2 id="faqs">FAQs</h2>
<ul>
<li>
<p><strong>How do I add image watermark to PDF in Java without losing quality?</strong><br>
Use the <code>scaleFactor</code> property to size the watermark relative to the page and keep the original DPI of the source PDF. The SDK preserves the PDF&rsquo;s resolution, so the watermark appears crisp at any zoom level.</p>
</li>
<li>
<p><strong>Can I add multiple watermarks to the same PDF?</strong><br>
Yes. Create separate <code>ImageWatermark</code> objects with different configurations and add them sequentially by calling <code>addWatermark</code> multiple times or by adding them to a list in the request.</p>
</li>
<li>
<p><strong>What are the supported image formats for the watermark?</strong><br>
The API accepts common image types such as <a href="https://docs.fileformat.com/image/png/">PNG</a>, <a href="https://docs.fileformat.com/image/jpg/">JPG</a>, <a href="https://docs.fileformat.com/image/bmp/">BMP</a>, <a href="https://docs.fileformat.com/image/gif/">GIF</a> and TIFF. PNG is recommended for lossless quality and transparency support.</p>
</li>
<li>
<p><strong>Is there a way to preview the watermark before applying it?</strong><br>
You can use the GroupDocs.Watermark Cloud SDK for Java to generate a temporary PDF with the watermark and download it for review. This uses the same <code>addWatermark</code> call with an output path pointing to a temporary location.</p>
</li>
</ul>
<h2 id="read-more">Read More</h2>
<ul>
<li><a href="https://blog.groupdocs.cloud/watermark/add-watermark-to-images-using-java/">Add Watermark to Images using Java</a></li>
<li><a href="https://blog.groupdocs.cloud/watermark/add-watermark-to-word-in-java-watermark-creator/">Add Watermark to Word in Java - Watermark Creator</a></li>
<li><a href="https://blog.groupdocs.cloud/watermark/insert-watermark-to-pdf-in-csharp/">Add Image Watermark to PDF | How to Add Watermark to PDF Documents Using .NET</a></li>
</ul>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
