<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: KomoPDF</title>
    <description>The latest articles on DEV Community by KomoPDF (@komopdf).</description>
    <link>https://dev.to/komopdf</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4229869%2Fb616a5fa-7458-488f-b225-9ee76fba9580.png</url>
      <title>DEV Community: KomoPDF</title>
      <link>https://dev.to/komopdf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/komopdf"/>
    <language>en</language>
    <item>
      <title>Prepare a PDF before paying to translate it</title>
      <dc:creator>KomoPDF</dc:creator>
      <pubDate>Fri, 27 Nov 2026 15:41:11 +0000</pubDate>
      <link>https://dev.to/komopdf/prepare-a-pdf-before-paying-to-translate-it-5823</link>
      <guid>https://dev.to/komopdf/prepare-a-pdf-before-paying-to-translate-it-5823</guid>
      <description>&lt;p&gt;A translated application arrives with the old address still in the source and an empty signature field. Sending it for translation again costs another processing pass, and the translated copy may not behave like the original form. Prepare the source first, then translate a separate version for reading.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://komopdf.com" rel="noopener noreferrer"&gt;KomoPDF&lt;/a&gt; combines browser PDF editing with an optional connection to KolmoPDF for translation. Its homepage says local files stay on your device. Translation is a separate service: requesting it uploads the current PDF version to KolmoPDF and uses KolmoPDF credits. Choose the workflow according to what the document is allowed to leave your device.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decide which copy is the deliverable
&lt;/h2&gt;

&lt;p&gt;Start with the recipient's instructions. A translated copy may help someone understand a document while the recipient still expects the original-language form. If editable fields or a digital signature are required, confirm the accepted format before replacing the form with a translated PDF.&lt;/p&gt;

&lt;p&gt;Keep the original file unchanged. Give the working copy and the translated output distinct names, such as &lt;code&gt;application-working.pdf&lt;/code&gt; and &lt;code&gt;application-translated.pdf&lt;/code&gt;. This makes it easier to return to the source when a name, date or page selection needs correction.&lt;/p&gt;

&lt;p&gt;A translation is not a certified translation merely because a tool produced it. For legal, medical or official submissions, check the recipient's requirements and arrange a qualified review where needed. Names, numbers, addresses and dates deserve a separate check even for an informal handoff.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepare the source before translation
&lt;/h2&gt;

&lt;p&gt;Open the PDF in KomoPDF and make the edits you need in the source-language document. The editor has controls for content editing, form filling and page organization. Confirm that the version you intend to translate contains the correct pages and completed information. Save a working copy before moving on.&lt;/p&gt;

&lt;p&gt;If the form must remain interactive, check its fields after export. A viewer can display a form value differently from another viewer, and a translated document should not be assumed to preserve the source form's interactive behavior. Keep the editable source for corrections. Our &lt;a href="https://dev.to/komopdf/before-you-send-a-filled-pdf-reopen-the-exported-file-4jmo"&gt;export checklist&lt;/a&gt; covers reopening the saved file and checking its fields.&lt;/p&gt;

&lt;p&gt;For sensitive information, removing pages from the copy can reduce what is submitted for translation. Read the remaining pages as well: extracting pages does not redact personal information that remains on them. Follow your organization's rules for external processing before sending anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose the translation settings
&lt;/h2&gt;

&lt;p&gt;The Translate panel connects to KolmoPDF with a separate account and API key. Select the target language and choose a translated PDF or a bilingual side-by-side version. The panel also includes options for image text, tables and a glossary. Use a glossary when a term needs a consistent translation, then review the output in context.&lt;/p&gt;

&lt;p&gt;The interface states a rate of 2 KolmoPDF credits per page. As a planning example, a 10-page document at that displayed rate would use 20 credits for one pass. A second full pass would add another 20 credits at the same rate. Confirm the current charge in the interface before submitting; page selection and service terms can affect the actual job.&lt;/p&gt;

&lt;p&gt;Do the page selection and corrections before starting the paid operation. When a correction is needed later, compare the cost of another translation with the importance of having the correction in the translated copy. Do not silently edit a translated legal document and present it as a certified result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Review both versions
&lt;/h2&gt;

&lt;p&gt;Open the saved output separately from the editor session. Check the first and last pages, page order, headings and any tables that carry totals or dates. Compare names, reference numbers and amounts against the source. For bilingual output, check that the corresponding passages line up well enough for the intended review.&lt;/p&gt;

&lt;p&gt;Test any field the recipient expects to fill. If the translated output is for reference, label it accordingly and retain the original form for submission. If the document was already digitally signed, keep the signed original intact and verify its signature in the recipient's chosen software. A visible signature image and a validated cryptographic signature serve different purposes.&lt;/p&gt;

&lt;p&gt;The original file is not replaced by the optional translation operation. Keep the source, working copy and output together under your normal retention rules so a reviewer can trace a questionable phrase back to the source.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>productivity</category>
      <category>webdev</category>
      <category>tools</category>
    </item>
    <item>
      <title>Why rapid zoom breaks a PDF.js canvas render</title>
      <dc:creator>KomoPDF</dc:creator>
      <pubDate>Thu, 26 Nov 2026 15:38:52 +0000</pubDate>
      <link>https://dev.to/komopdf/why-rapid-zoom-breaks-a-pdfjs-canvas-render-525p</link>
      <guid>https://dev.to/komopdf/why-rapid-zoom-breaks-a-pdfjs-canvas-render-525p</guid>
      <description>&lt;p&gt;A user clicks zoom twice, and the PDF page disappears. The console reports that the same canvas is already in use by another render operation. A viewer can hit this when a new zoom, rotation, or page selection starts drawing before the previous PDF.js render has finished.&lt;/p&gt;

&lt;p&gt;The tricky part is that &lt;code&gt;cancel()&lt;/code&gt; starts cancellation; it does not make every asynchronous step in your viewer disappear. You still need to wait for the render task's promise to settle before reusing that canvas. You also need to ignore older page requests that finish loading after a newer request has arrived.&lt;/p&gt;

&lt;h2&gt;
  
  
  A race with two different clocks
&lt;/h2&gt;

&lt;p&gt;Suppose the user selects page 3, then immediately selects page 4. Both &lt;code&gt;getPage()&lt;/code&gt; calls run asynchronously. Page 4 can become available first, while the older page 3 request is still pending. If the older request starts a render when it eventually returns, the canvas can show the wrong page or collide with a render already in progress.&lt;/p&gt;

&lt;p&gt;Zoom creates the same problem even if the page number stays fixed. Each request has a different viewport, and resetting the canvas dimensions while an earlier task is drawing can corrupt the result. A boolean such as &lt;code&gt;isRendering&lt;/code&gt; alone does not tell you which of several pending requests is the latest.&lt;/p&gt;

&lt;p&gt;A PDF.js maintainer described cancellation as asynchronous in &lt;a href="https://github.com/mozilla/pdf.js/issues/9456" rel="noopener noreferrer"&gt;issue #9456&lt;/a&gt;. The project's &lt;a href="https://github.com/mozilla/pdf.js/pull/9853" rel="noopener noreferrer"&gt;subsequent fix and regression test&lt;/a&gt; also show a render being cancelled, its promise settling, and the canvas being reused. That issue concerned an older PDF.js version; it is useful evidence for the lifecycle, not a claim that its specific bug still exists today.&lt;/p&gt;

&lt;h2&gt;
  
  
  Serialize work for one canvas
&lt;/h2&gt;

&lt;p&gt;The following controller owns one canvas. It cancels the active render as soon as a new request arrives, serializes access to the canvas, and uses a generation number to discard requests that became stale while waiting. It assumes &lt;code&gt;pdf&lt;/code&gt; is an already loaded PDF.js document and that the canvas has a 2D context.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;makePageRenderer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;generation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pageNumber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;generation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;work&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="n"&gt;generation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;pdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pageNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="n"&gt;generation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;viewport&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getViewport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;canvasContext&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2d'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;promise&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'RenderingCancelledException'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Keep the queue usable after a failure; the caller still receives it.&lt;/span&gt;
    &lt;span class="n"&gt;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Call &lt;code&gt;show(3, 1.5)&lt;/code&gt; on a page or zoom change, and attach an error handler to the returned promise. Each invocation advances the generation immediately. A queued request checks its generation both before and after &lt;code&gt;getPage()&lt;/code&gt;, so an older page load cannot start drawing after a newer selection. When an active render is cancelled, the queue waits for that task's promise before the next request can resize or render into the canvas.&lt;/p&gt;

&lt;p&gt;The empty catch belongs only to the internal queue tail: it lets later requests run even if one failed. The returned &lt;code&gt;work&lt;/code&gt; promise still rejects for unexpected errors. Surface those errors in the UI or logs instead of treating all failures as normal cancellation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the lifecycle, not just the final page
&lt;/h2&gt;

&lt;p&gt;Use a multi-page PDF and rapidly alternate page numbers and zoom levels. The last selection should be the one displayed. Watch for unhandled promise rejections and same-canvas errors, and repeat with a deliberately slow page load so that an older &lt;code&gt;getPage()&lt;/code&gt; resolves after a newer selection.&lt;/p&gt;

&lt;p&gt;Also test leaving the viewer while work is pending. A component should invalidate pending requests and cancel its active task during teardown; wait for that task to settle before destroying or reusing its canvas. If the application can switch documents, give the new document its own controller and retire the old one before handing over the canvas.&lt;/p&gt;

&lt;p&gt;This example uses one bitmap pixel per viewport unit for clarity. A production viewer may use a device-pixel-ratio transform for sharper output, subject to a canvas memory budget. Text and annotation layers need their own lifecycle and should be updated only for the current request as well. Keeping those layers in sync matters: a sharp bitmap with stale selectable text or misplaced form controls is still the wrong page.&lt;/p&gt;

&lt;p&gt;For the related coordinate problem, see &lt;a href="https://dev.to/komopdf/why-pdf-annotations-move-when-you-rotate-or-zoom-a-page-5ap2"&gt;why PDF annotations move when you rotate or zoom a page&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Send the right pages from a PDF without losing the original</title>
      <dc:creator>KomoPDF</dc:creator>
      <pubDate>Wed, 25 Nov 2026 15:38:24 +0000</pubDate>
      <link>https://dev.to/komopdf/send-the-right-pages-from-a-pdf-without-losing-the-original-19p</link>
      <guid>https://dev.to/komopdf/send-the-right-pages-from-a-pdf-without-losing-the-original-19p</guid>
      <description>&lt;p&gt;An application packet contains the two pages you need to return and a dozen pages of instructions. Sending the whole PDF adds clutter; deleting pages from the only copy makes it harder to check those instructions later. Keep the original, then create a separate PDF for the pages the recipient requested.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://komopdf.com" rel="noopener noreferrer"&gt;KomoPDF&lt;/a&gt; has page organization and extraction controls in its browser editor. Its homepage says local files stay on your device, and you can start without registering. The optional translation service is a separate operation and uploads the current PDF when you request a translation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decide which pages belong in the copy
&lt;/h2&gt;

&lt;p&gt;Read the submission instructions before opening the page tools. A cover page, consent page or attachment list can be easy to miss if you only look for fields that need filling. Make a short list of the pages to return, including any page that carries a required signature or a referenced attachment.&lt;/p&gt;

&lt;p&gt;Check the page numbers in the viewer against the numbers printed on the paper. A cover sheet can make PDF page 3 display a printed page number of 1. When the instructions say "page 3," resolve that ambiguity against the document itself before removing anything. Also check whether a two-sided form has a back page with terms or another signature field.&lt;/p&gt;

&lt;p&gt;In KomoPDF, choose &lt;strong&gt;Open PDF&lt;/strong&gt; and select the source file. Use &lt;strong&gt;Organize pages&lt;/strong&gt; or &lt;strong&gt;Extract pages&lt;/strong&gt; for the pages you want to keep, then export the result as a separate file. The exact selection controls depend on the editor view. Before exporting, review the page previews and order rather than relying on the filename alone.&lt;/p&gt;

&lt;p&gt;Give the exported copy a name that distinguishes it from the original, for example &lt;code&gt;application-return.pdf&lt;/code&gt;. Keep the original in its existing location until the recipient has accepted the submission. This also gives you a way back if an instruction page turns out to be required.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fill first or extract first?
&lt;/h2&gt;

&lt;p&gt;If only the requested pages need fields completed, extracting a copy first can make the working document easier to review. If instructions or fields refer to other pages, keep the full document open while you work. Either way, inspect the exported result: page operations and form handling vary across PDF editors and viewers.&lt;/p&gt;

&lt;p&gt;A PDF form can store field values separately from the appearances a viewer draws on the page. A page can therefore look correct in the editor and look different after export or in another viewer. Open the exported copy afresh, check the values and try the fields you expect to remain editable. If a recipient needs editable fields, ask which format and viewer they support before submitting a flattened or printed copy.&lt;/p&gt;

&lt;p&gt;Our guide to &lt;a href="https://dev.to/komopdf/before-you-send-a-filled-pdf-reopen-the-exported-file-4jmo"&gt;reopening a filled PDF after export&lt;/a&gt; covers that final review in more detail. A page extraction test should include a filled example, not just an empty template.&lt;/p&gt;

&lt;h2&gt;
  
  
  Treat signed files differently
&lt;/h2&gt;

&lt;p&gt;A visible handwritten-style signature and a cryptographic PDF signature are different things. A digital signature can protect specific bytes of the document, so changing or extracting pages may invalidate it or produce a copy that does not retain the original signature's verification properties. Keep the signed original unchanged. If the recipient requires a digitally signed document, confirm the permitted workflow with them and validate the final file in their chosen verifier.&lt;/p&gt;

&lt;p&gt;For a document that still needs signing, settle the page order and contents before applying the signature. After signing, open the final copy and check both the visible pages and the signature status. A signature image alone does not prove a cryptographic signature is valid.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the handoff
&lt;/h2&gt;

&lt;p&gt;Open the exported file from its saved location, not the editor tab that still contains your working session. Count the pages, check their order and read the first and last page. Confirm that text, form values and signatures appear where expected. If possible, repeat the check in the viewer the recipient uses.&lt;/p&gt;

&lt;p&gt;Removing a page from an exported copy is a way to limit the pages you send. It is not a substitute for redacting sensitive content that remains on a page. Review the remaining pages and metadata under your organization's disclosure rules before sharing.&lt;/p&gt;

&lt;p&gt;KomoPDF's local editing and its optional translation connection have different data paths. Choosing translation sends the current PDF version to KolmoPDF using a separate account and API key, and uses KolmoPDF credits. If the packet must stay on the device, use the local editing workflow and do not request translation.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>productivity</category>
      <category>webdev</category>
      <category>tools</category>
    </item>
    <item>
      <title>Why PDF annotations move when you rotate or zoom a page</title>
      <dc:creator>KomoPDF</dc:creator>
      <pubDate>Tue, 24 Nov 2026 15:38:22 +0000</pubDate>
      <link>https://dev.to/komopdf/why-pdf-annotations-move-when-you-rotate-or-zoom-a-page-5ap2</link>
      <guid>https://dev.to/komopdf/why-pdf-annotations-move-when-you-rotate-or-zoom-a-page-5ap2</guid>
      <description>&lt;p&gt;A PDF viewer can put a signature in the wrong place even when the pointer coordinates look correct. The page might be rotated, zoomed, or displayed at a different size from its canvas bitmap. An overlay that happens to line up at 100% zoom can drift as soon as the user changes the view.&lt;/p&gt;

&lt;p&gt;The fix starts with keeping two coordinate systems separate. Store an annotation in PDF page coordinates. Convert it to viewport coordinates when displaying it, and convert a pointer position back when the user edits it. PDF.js exposes both conversions on its page viewport.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reproduce the offset
&lt;/h2&gt;

&lt;p&gt;Use a page with a visible corner mark. Place an annotation near that mark, zoom in, then rotate the page by 90 degrees. Reopen the saved file in another viewer. If the annotation moves away from the mark, inspect how the placement was converted before blaming the export.&lt;/p&gt;

&lt;p&gt;PDF page coordinates traditionally have their origin at the lower left and increase upward. A browser element's coordinates start at the upper left and increase downward. A PDF.js viewport accounts for that difference as well as the selected scale and rotation. Manually flipping Y with &lt;code&gt;pageHeight - y&lt;/code&gt; can work for a simple unrotated page, but it does not handle all of those transformations.&lt;/p&gt;

&lt;p&gt;PDF.js provides &lt;code&gt;convertToViewportPoint(x, y)&lt;/code&gt; and &lt;code&gt;convertToPdfPoint(x, y)&lt;/code&gt; on the viewport returned by &lt;code&gt;page.getViewport(...)&lt;/code&gt;. See the &lt;a href="https://github.com/mozilla/pdf.js/blob/master/src/display/display_utils.js" rel="noopener noreferrer"&gt;PDF.js viewport implementation&lt;/a&gt; and its &lt;a href="https://mozilla.github.io/pdf.js/examples/" rel="noopener noreferrer"&gt;rendering example&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Map a pointer through the viewport
&lt;/h2&gt;

&lt;p&gt;The following example assumes that &lt;code&gt;pageElement&lt;/code&gt; is the untransformed HTML element whose content box exactly matches the displayed PDF viewport. It has no border or padding, and the entire page is visible inside it. &lt;code&gt;viewport&lt;/code&gt; is the same viewport used to render the page. The scale factors account for a page element displayed at a different CSS size from the viewport dimensions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;pointerToPdf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pageElement&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pageElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;viewportX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;clientX&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;left&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;viewportY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;clientY&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;top&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;convertToPdfPoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewportX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;viewportY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;pdfToCss&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdfX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pdfY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pageElement&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;convertToViewportPoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdfX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pdfY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pageElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Position an overlay relative to the same page element, using the returned &lt;code&gt;left&lt;/code&gt; and &lt;code&gt;top&lt;/code&gt; as CSS pixels. Save the PDF point, not the CSS coordinates. When zoom or rotation changes, create the viewport for the new view and run &lt;code&gt;pdfToCss&lt;/code&gt; again. If the page is inside a scrolling container, &lt;code&gt;clientX&lt;/code&gt; and &lt;code&gt;getBoundingClientRect()&lt;/code&gt; are already in the same browser viewport coordinate space; do not add the scroll offset a second time.&lt;/p&gt;

&lt;p&gt;A canvas can have a larger backing bitmap than its CSS size on a high-density display. That changes rendering resolution, not the coordinates returned by &lt;code&gt;getBoundingClientRect()&lt;/code&gt;. Do not multiply the pointer by &lt;code&gt;devicePixelRatio&lt;/code&gt; before this conversion. PDF.js's example separates the output scale used for canvas rendering from the viewport used to describe the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Points are easier than rectangles
&lt;/h2&gt;

&lt;p&gt;A signature or text box has width and height as well as an anchor. Under rotation, the top-left screen corner is not necessarily the lower-left PDF corner. Convert all four corners through the viewport, then calculate the PDF-space bounding box from their minimum and maximum X and Y values. Keep the intended orientation separately if your export code needs it; a bounding box alone cannot describe every rotated object.&lt;/p&gt;

&lt;p&gt;Test each supported page rotation, including the page's own rotation combined with any rotation the user applies. Build the viewport using the rotation actually displayed. A page with a nonzero crop box or a nondefault origin is another useful fixture: its visible corner is a safer test than assuming the page starts at &lt;code&gt;(0, 0)&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the saved file
&lt;/h2&gt;

&lt;p&gt;Run a round-trip check for representative points: convert PDF to viewport and back, then compare within a small floating-point tolerance. That catches mismatched viewports but cannot prove that an exporter writes an annotation correctly. Save a copy, close the viewer, and inspect the mark in a second PDF reader at multiple zoom levels.&lt;/p&gt;

&lt;p&gt;Also test near each edge, after scrolling, and on a high-density screen. If the overlay aligns in the browser but the exported mark moves, log the stored PDF coordinates and inspect the export library's placement conventions. Some APIs accept coordinates in a transformed page space or apply their own rotation. Keep an untouched original while testing, especially for signed documents: writing an annotation can change signature validation.&lt;/p&gt;

&lt;p&gt;For a related rendering issue, see &lt;a href="https://dev.to/komopdf/why-pdf-previews-go-blank-on-high-density-screens-1n44"&gt;why PDF previews go blank on high-density screens&lt;/a&gt;. That article covers canvas memory; this coordinate mapping uses CSS dimensions regardless of the canvas bitmap's resolution.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Before you send a filled PDF, reopen the exported file</title>
      <dc:creator>KomoPDF</dc:creator>
      <pubDate>Mon, 23 Nov 2026 15:38:34 +0000</pubDate>
      <link>https://dev.to/komopdf/before-you-send-a-filled-pdf-reopen-the-exported-file-4jmo</link>
      <guid>https://dev.to/komopdf/before-you-send-a-filled-pdf-reopen-the-exported-file-4jmo</guid>
      <description>&lt;p&gt;A completed PDF can look right in the browser tab and still arrive as the wrong file. The common failure is a workflow mistake: editing the document, sending an earlier download, and discovering the missing changes only after submission. A second problem appears when a recipient opens the exported form in a different viewer and sees an empty field.&lt;/p&gt;

&lt;p&gt;A short export check catches both problems without requiring an account. This walkthrough uses &lt;a href="https://komopdf.com" rel="noopener noreferrer"&gt;KomoPDF&lt;/a&gt; for local editing, then checks the saved copy separately. Use a test document without sensitive information for the first pass.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepare a copy with an identifiable change
&lt;/h2&gt;

&lt;p&gt;Open the editor and choose &lt;strong&gt;Open PDF&lt;/strong&gt;. Select a form or document you are allowed to edit. If the task is to complete a form, use &lt;strong&gt;Fill &amp;amp; forms&lt;/strong&gt;; for existing page content, choose &lt;strong&gt;Edit content&lt;/strong&gt;. The available operation depends on the document. A scanned page, for example, can be an image rather than editable text.&lt;/p&gt;

&lt;p&gt;Make one recognizable change, such as entering a unique test value in a form field. If the document has several pages, note which page holds the change. You will use that detail to check the exported file rather than relying on a thumbnail or filename alone.&lt;/p&gt;

&lt;p&gt;Keep the original file. A separate working copy gives you a reference if the exported result loses something important. It also lets you distinguish an editing problem from a later export or viewer problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Export and reopen the actual download
&lt;/h2&gt;

&lt;p&gt;Use &lt;strong&gt;Export&lt;/strong&gt; to save the edited PDF. Give it a distinct filename, such as &lt;code&gt;application-edited.pdf&lt;/code&gt;, instead of relying on the browser's automatic numbered downloads. The exact save dialog depends on the browser and device; confirm where the file was saved.&lt;/p&gt;

&lt;p&gt;Close or leave the editing view and open that saved file from its download location. Check the page and the test value. For a form, click the field and confirm the value is still there. Checkboxes deserve a separate look: a visible mark and the value a form processor reads can behave differently across tools.&lt;/p&gt;

&lt;p&gt;If the saved copy is missing the change, return to the working document and check the edit before exporting again. If it is present in one viewer and missing in another, keep both copies for diagnosis. Record the viewers and versions, the affected field, and whether the value is visible, selectable, or absent. Avoid repeatedly submitting new files while the cause is unclear.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the recipient's view
&lt;/h2&gt;

&lt;p&gt;Open the exported copy in the viewer the recipient expects, if you have access to it. If you do not, try a second PDF viewer and ask the recipient which format they accept. A visual pass should cover every edited field, including long text that could be clipped and checkboxes that might use a different on-state.&lt;/p&gt;

&lt;p&gt;For a machine-ingested form, a visual check alone is insufficient. Confirm with the recipient that the fields remain interactive and that their process reads the expected values. Printing a form to PDF may make its appearance easier to share, but can remove interactive fields and other document features. Only use a flattened or printed copy when the recipient accepts it, and retain the editable version.&lt;/p&gt;

&lt;p&gt;Some forms use dynamic XFA rather than ordinary AcroForm fields. A browser may show a placeholder instead of the form. If that happens, obtain a compatible version or use the software specified by the sender rather than assuming a blank preview is an empty form. The related guides cover &lt;a href="https://dev.to/komopdf/why-filled-pdf-forms-open-blank-in-some-viewers-and-how-to-fix-it-1d9i"&gt;blank form appearances&lt;/a&gt; and &lt;a href="https://dev.to/komopdf/acroform-vs-xfa-why-dynamic-pdf-forms-show-please-wait-in-modern-browsers-and-how-to-handle-2amm"&gt;XFA compatibility&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep translation and signatures separate
&lt;/h2&gt;

&lt;p&gt;KomoPDF's homepage says local editing keeps files on the device. Its optional KolmoPDF translation connection is a separate online operation: requesting translation uploads the current PDF version to that service and uses KolmoPDF credits. Decide whether that upload is appropriate for the document before connecting; ordinary local editing does not require the translation service.&lt;/p&gt;

&lt;p&gt;Finally, distinguish a visible signature mark from a cryptographic digital signature. Editing a digitally signed PDF can affect signature validation, even when the signature still appears on the page. Preserve the signed original and follow the recipient's instructions for permitted changes. For the underlying byte-range and incremental-update details, see &lt;a href="https://dev.to/komopdf/why-modifying-a-signed-pdf-breaks-digital-signatures-and-how-incremental-updates-work-1g81"&gt;modifying a signed PDF&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The file to send is the exported copy you actually reopened and checked. Keep the original and editable version until the recipient confirms the submission is usable.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>productivity</category>
      <category>webdev</category>
      <category>tools</category>
    </item>
    <item>
      <title>Why PDF previews go blank on high-density screens</title>
      <dc:creator>KomoPDF</dc:creator>
      <pubDate>Sun, 22 Nov 2026 15:38:38 +0000</pubDate>
      <link>https://dev.to/komopdf/why-pdf-previews-go-blank-on-high-density-screens-1n44</link>
      <guid>https://dev.to/komopdf/why-pdf-previews-go-blank-on-high-density-screens-1n44</guid>
      <description>&lt;p&gt;A PDF preview can look fine on a laptop and go blank on a high-density phone. The file may be small on disk, yet the viewer allocates a large canvas for every rendered page. Zoom and device pixel ratio multiply both canvas dimensions, so memory grows with the square of the scale.&lt;/p&gt;

&lt;p&gt;A &lt;a href="https://github.com/mozilla/pdf.js/issues/17343" rel="noopener noreferrer"&gt;PDF.js issue&lt;/a&gt; describes a failure with large scanned drawings on high-resolution screens. That report concerns a particular setup, not a universal browser limit. It is a useful prompt to separate the size of a PDF file from the size of the pixels used to display it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Count pixels before rendering
&lt;/h2&gt;

&lt;p&gt;Suppose a page occupies 800 by 1,035 CSS pixels. With a device pixel ratio of 2, a full-resolution backing canvas is 1,600 by 2,070 pixels. At four bytes per RGBA pixel, the raw pixel buffer alone is about 12.6 MiB. At a ratio of 3, it is about 28.4 MiB. Five such pages at ratio 3 would need roughly 142 MiB for those buffers alone.&lt;/p&gt;

&lt;p&gt;Those are estimates, not measurements of total browser memory. Decoded images, PDF structures, GPU copies and text layers can add to the footprint. A browser may also impose separate maximum dimensions or area limits, and those limits vary by device.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://mozilla.github.io/pdf.js/examples/" rel="noopener noreferrer"&gt;PDF.js rendering example&lt;/a&gt; distinguishes CSS dimensions from the larger backing canvas and applies an output transform for high-density screens. A custom viewer can add a per-page budget before assigning canvas dimensions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;chooseOutputScale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dpr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;maxPixels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8_000_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Example budget, not a browser guarantee.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;maxSide&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8192&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        &lt;span class="c1"&gt;// Test and tune for your supported devices.&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;dpr&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;maxPixels&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;maxSide&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;maxSide&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;renderPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cssWidth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getViewport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;viewport&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getViewport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cssWidth&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;outputScale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;chooseOutputScale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;devicePixelRatio&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;outputScale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;outputScale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`${viewport.width}px`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`${viewport.height}px`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;canvasContext&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2d'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;outputScale&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;outputScale&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;promise&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a sizing example for a custom PDF.js canvas integration. It assumes valid, positive viewport dimensions and one render at a time for the canvas. The values are application budgets, not claims about what a browser can allocate. A smaller output scale can make text look soft; keep the CSS page size stable and communicate when a preview has reduced resolution. For very large pages or high zoom, tiled rendering is another option, with more implementation work.&lt;/p&gt;

&lt;p&gt;The built-in PDF.js viewer has its own canvas sizing controls; check the version you ship before adding a second layer of limits. The discussion on the issue links to its &lt;code&gt;maxCanvasPixels&lt;/code&gt; setting. A cap on the output canvas also does not bound every embedded image allocation during decoding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep only the pages a reader needs
&lt;/h2&gt;

&lt;p&gt;A per-page cap still permits a large total if a viewer holds dozens of canvases. Render visible pages and a small buffer around them, then release canvases that are far away. Keep placeholders at the correct page dimensions so removing pixels does not collapse the scroll position. Documents with mixed page sizes need per-page placeholder dimensions.&lt;/p&gt;

&lt;p&gt;Scrolling and zooming can overlap with rendering. Cancel or wait for the old render task before reusing its canvas; the PDF.js example explicitly avoids drawing two pages into the same canvas at once. Discard stale results after a zoom or document switch, and render a fresh page when it returns to the visible window. Releasing a canvas means clearing references as well as removing it from the page; memory reclamation timing remains up to the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the failure on real devices
&lt;/h2&gt;

&lt;p&gt;Record the CSS page size, output scale, backing dimensions and number of live page canvases when a preview fails. Compare a phone and desktop at the same zoom, then test a long document, a wide drawing and mixed portrait/landscape pages. Scroll away and back, resize the window, and zoom while a page is still rendering.&lt;/p&gt;

&lt;p&gt;Check that text selection and form controls still align with the displayed page. Those layers may use the CSS viewport even when the canvas backing resolution is reduced. A canvas budget can make the picture cheaper without changing the coordinates used by the interactive layers.&lt;/p&gt;

&lt;p&gt;For another source of memory growth in a document viewer, see &lt;a href="https://dev.to/komopdf/pdf-previews-keep-growing-in-memory-when-to-revoke-blob-urls-2f0l"&gt;when to revoke PDF preview blob URLs&lt;/a&gt;. Blob URL lifetime and canvas pixel memory are separate costs, so both deserve a look when a tab keeps growing.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>performance</category>
    </item>
    <item>
      <title>Why a PDF range request downloads the whole file</title>
      <dc:creator>KomoPDF</dc:creator>
      <pubDate>Tue, 17 Nov 2026 15:38:43 +0000</pubDate>
      <link>https://dev.to/komopdf/why-a-pdf-range-request-downloads-the-whole-file-51ca</link>
      <guid>https://dev.to/komopdf/why-a-pdf-range-request-downloads-the-whole-file-51ca</guid>
      <description>&lt;p&gt;A PDF viewer asks for the first 64 KiB of a 40 MiB file, but the network panel shows a 40 MiB response. The request included &lt;code&gt;Range: bytes=0-65535&lt;/code&gt;; the server replied &lt;code&gt;200 OK&lt;/code&gt; and sent the whole file. The viewer may still display the document, while the bandwidth and startup behavior differ from what the developer expected.&lt;/p&gt;

&lt;p&gt;Range support is an agreement between the client, the server, and any proxy or CDN in between. Here's how to check the actual response before changing viewer code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read the status and byte range together
&lt;/h2&gt;

&lt;p&gt;Request a small slice from the deployed URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sS -D - -o /dev/null -H &lt;span class="s1"&gt;'Range: bytes=0-65535'&lt;/span&gt; &lt;span class="s1"&gt;'https://example.com/document.pdf'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a file at least 65,536 bytes long, a successful single-range response can look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;206&lt;/span&gt; &lt;span class="nc"&gt;Partial&lt;/span&gt; &lt;span class="nc"&gt;Content&lt;/span&gt;
&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Range&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;65535&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;41943040&lt;/span&gt;
&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;65536&lt;/span&gt;
&lt;span class="nc"&gt;Accept&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Ranges&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The endpoints in &lt;code&gt;Content-Range&lt;/code&gt; are inclusive. &lt;code&gt;Content-Length&lt;/code&gt; here describes the response body, while the number after the slash describes the full representation. A smaller file can produce a shorter range. An &lt;code&gt;Accept-Ranges: bytes&lt;/code&gt; header is useful evidence, but check a real GET too: headers from a HEAD request alone don't prove that your deployed path will return the expected bytes.&lt;/p&gt;

&lt;p&gt;A server may ignore &lt;code&gt;Range&lt;/code&gt; and return &lt;code&gt;200&lt;/code&gt; with the complete representation. Treat that as a full download, not as the requested chunk. A &lt;code&gt;416 Range Not Satisfiable&lt;/code&gt; response means the requested range cannot be satisfied; its &lt;code&gt;Content-Range&lt;/code&gt; can report the current size as &lt;code&gt;bytes */41943040&lt;/code&gt;. See &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Range_requests" rel="noopener noreferrer"&gt;MDN's range request guide&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Range" rel="noopener noreferrer"&gt;Content-Range reference&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the last bytes and a second request
&lt;/h2&gt;

&lt;p&gt;A PDF reader may need data from different parts of the file. Verify a suffix request as well as a request near the start:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sS -D - -o /dev/null -H &lt;span class="s1"&gt;'Range: bytes=-1024'&lt;/span&gt; &lt;span class="s1"&gt;'https://example.com/document.pdf'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a file larger than 1,024 bytes, compare the returned interval and length with the full size. Test the same public URL the browser uses, including redirects and authentication where applicable. A storage origin may support ranges while a proxy, signed URL, or cache in the actual path changes the behavior. Avoid putting credentials or sensitive signed URLs in shared logs.&lt;/p&gt;

&lt;p&gt;A range-capable server doesn't guarantee that the viewer will fetch only the first page. Its parser, document layout, prefetch settings, and server responses all influence requests. Look at transferred bytes and request timing for the actual document instead of assuming a fixed bandwidth saving.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check cross-origin visibility
&lt;/h2&gt;

&lt;p&gt;A request can succeed in the network panel while JavaScript cannot read every response header. When the viewer and PDF are on different origins, configure the PDF server's CORS policy for the viewer origin. If the application needs to inspect range metadata, expose the relevant headers, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="nc"&gt;Access&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Control&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Allow&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//viewer.example&lt;/span&gt;
&lt;span class="nc"&gt;Access&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Control&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Expose&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Accept&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Ranges&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Range&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ETag&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the policy to the responses the browser receives, including partial responses and relevant error responses. Credentialed requests need a compatible explicit origin and credential policy. A terminal &lt;code&gt;curl&lt;/code&gt; test doesn't enforce browser CORS, so repeat the check in the browser's network and console panels. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Expose-Headers" rel="noopener noreferrer"&gt;MDN documents header exposure&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep chunks from the same version
&lt;/h2&gt;

&lt;p&gt;A file can change between requests. Combining bytes from an old version with bytes from a new one can produce a corrupt document, even when both requests returned &lt;code&gt;206&lt;/code&gt;. Prefer immutable, versioned URLs for a document. For resumable requests, conditional range requests with an appropriate validator allow the server to return the complete current representation when the saved version no longer matches. On a &lt;code&gt;200&lt;/code&gt; response, discard old partial data instead of appending the new body to it. See &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/If-Range" rel="noopener noreferrer"&gt;MDN on If-Range&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, test a genuinely out-of-range offset, a cross-origin request, and a file replacement at the same URL. Record status, &lt;code&gt;Content-Range&lt;/code&gt;, transferred bytes, and the version validator for each request. Those observations separate a viewer parsing problem from a delivery path that silently sent the entire file.&lt;/p&gt;

&lt;p&gt;This article continues the PDF viewer compatibility series. For local previews and their memory lifetime, see &lt;a href="https://dev.to/komopdf/pdf-previews-keep-growing-in-memory-when-to-revoke-blob-urls-2f0l"&gt;when to revoke blob URLs&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>webdev</category>
      <category>http</category>
      <category>performance</category>
    </item>
    <item>
      <title>PDF previews keep growing in memory: when to revoke blob URLs</title>
      <dc:creator>KomoPDF</dc:creator>
      <pubDate>Mon, 16 Nov 2026 15:38:44 +0000</pubDate>
      <link>https://dev.to/komopdf/pdf-previews-keep-growing-in-memory-when-to-revoke-blob-urls-2f0l</link>
      <guid>https://dev.to/komopdf/pdf-previews-keep-growing-in-memory-when-to-revoke-blob-urls-2f0l</guid>
      <description>&lt;p&gt;A PDF preview can work perfectly on the first upload and still consume more memory each time a user replaces the file. One common cause is creating a new blob URL for every preview and never releasing the old one. The opposite shortcut, revoking the URL immediately after assigning it to an iframe, can leave the viewer trying to load a URL that no longer resolves.&lt;/p&gt;

&lt;p&gt;For a browser PDF editor, the useful boundary is the lifetime of the preview: keep its URL while the viewer or download link needs it, then release it when that preview is replaced or closed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a blob URL holds
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;URL.createObjectURL(file)&lt;/code&gt; returns a &lt;code&gt;blob:&lt;/code&gt; URL that refers to a &lt;code&gt;File&lt;/code&gt; or &lt;code&gt;Blob&lt;/code&gt;. It is a browser-managed reference, not a network address for the original file. Each call creates a distinct URL, even for the same object. An active object URL can keep its underlying object reachable, so repeatedly creating URLs can retain resources longer than intended. The browser releases object URLs when the document unloads, but a long-lived editing tab should clean up as it goes.&lt;/p&gt;

&lt;p&gt;Revoke a URL with &lt;code&gt;URL.revokeObjectURL(url)&lt;/code&gt; once all consumers have finished with it. This releases the URL's reference; it does not promise that all memory disappears immediately. A PDF viewer, JavaScript variable, canvas or other component may still hold its own data.&lt;/p&gt;

&lt;h2&gt;
  
  
  A preview with an explicit close action
&lt;/h2&gt;

&lt;p&gt;The following minimal example assumes an &lt;code&gt;&amp;lt;iframe id="preview"&amp;gt;&lt;/code&gt; and a file input. Only this function owns the iframe's object URL. Call &lt;code&gt;closePreview()&lt;/code&gt; when the user closes the preview or the component is removed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;frame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'#preview'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;currentUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;showPdf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;nextUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createObjectURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;previousUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;currentUrl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;currentUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nextUrl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nextUrl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;previousUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;revokeObjectURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;previousUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;closePreview&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'src'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;currentUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;revokeObjectURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;currentUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;currentUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This revokes the previous URL after the iframe is pointed at the replacement. It intentionally keeps the current URL alive beyond the iframe's &lt;code&gt;load&lt;/code&gt; event: an embedded viewer may need the document again for actions such as print, download or reload. If another part of the interface uses the same URL, give it a separate URL or coordinate ownership before revoking it. Check replacement and close behavior in each browser your application supports; embedded PDF viewers differ.&lt;/p&gt;

&lt;p&gt;For a React or other component-based interface, the same rule belongs in the lifecycle cleanup. Avoid creating an object URL during render: a render can run more than once, and an unused render still creates a URL. Create it in an effect or event handler, and revoke the exact URL created by that operation in its cleanup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Large files have more than one memory cost
&lt;/h2&gt;

&lt;p&gt;Revoking a blob URL fixes one source of retention. It does not release a PDF parser's page cache or a canvas still attached to the page. A single RGBA canvas needs approximately &lt;code&gt;width × height × 4&lt;/code&gt; bytes for its pixel buffer before other allocations. For example, a 2,000 by 3,000 pixel canvas needs about 24,000,000 bytes, or 22.9 MiB, for that buffer alone. Higher device pixel ratios increase both dimensions and therefore the pixel count.&lt;/p&gt;

&lt;p&gt;If a preview renders every page at full resolution, reducing the number of live canvases may save more memory than changing the file URL. Render visible pages first, release off-screen render resources according to the viewer library's API, and cancel obsolete render tasks when a user switches files. Keep a separate copy of the original file only when the workflow needs one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the failure cases
&lt;/h2&gt;

&lt;p&gt;Use two test PDFs of different sizes and switch between them repeatedly. Confirm that the final preview is the expected file, that closing it removes access to its old URL, and that printing or downloading still works while the preview remains open. Include a rapid sequence of file selections: asynchronous parsing can finish out of order, so the application should ignore results from an older selection after a newer one has started.&lt;/p&gt;

&lt;p&gt;Inspect browser memory across several open, replace and close cycles. Garbage collection and the built-in viewer can make readings noisy; look for a sustained trend across repeated cycles rather than expecting an immediate drop after each revoke. Repeat with a long document to separate retained file references from rendered page buffers.&lt;/p&gt;

&lt;p&gt;For the broader editing workflow, &lt;a href="https://komopdf.com" rel="noopener noreferrer"&gt;KomoPDF&lt;/a&gt; provides browser-based PDF editing and page organization. Its local editing workflow keeps files on the device; its optional KolmoPDF translation connection uploads the current PDF when translation is requested. For a related document compatibility issue, see &lt;a href="https://dev.to/komopdf/why-filled-pdf-forms-open-blank-in-some-viewers-and-how-to-fix-it-1d9i"&gt;why filled PDF forms can open blank in another viewer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;References: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static" rel="noopener noreferrer"&gt;MDN: createObjectURL&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL_static" rel="noopener noreferrer"&gt;MDN: revokeObjectURL&lt;/a&gt;, and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/blob" rel="noopener noreferrer"&gt;MDN: blob URLs&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>performance</category>
    </item>
    <item>
      <title>Why Translating a PDF Before Filling Forms Breaks Fields and Doubles Credit Costs</title>
      <dc:creator>KomoPDF</dc:creator>
      <pubDate>Fri, 13 Nov 2026 15:40:12 +0000</pubDate>
      <link>https://dev.to/komopdf/why-translating-a-pdf-before-filling-forms-breaks-fields-and-doubles-credit-costs-30ng</link>
      <guid>https://dev.to/komopdf/why-translating-a-pdf-before-filling-forms-breaks-fields-and-doubles-credit-costs-30ng</guid>
      <description>&lt;p&gt;Sending a raw 25-page vendor packet to a document translator before fixing it locally causes two avoidable problems. First, at 2 credits per page, translating eight appendix pages you meant to delete costs 16 extra credits, and spotting an outdated address afterward means paying to run the whole file a second time. Second, editing text or filling AcroForm fields after translation often breaks because translated PDFs frequently carry tightly subsetted fonts and altered content streams.&lt;/p&gt;

&lt;p&gt;Handling page cleanup, text edits, form filling, and signing in the browser first produces a clean PDF version before anything leaves your device.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Why form values disappear if you only update /V
&lt;/h2&gt;

&lt;p&gt;When you type into an interactive PDF form, the viewer stores the logical string in the field dictionary's &lt;code&gt;/V&lt;/code&gt; entry. That alone does not guarantee another tool or rendering pipeline will draw it on the page.&lt;/p&gt;

&lt;p&gt;Under ISO 32000-1 (§12.7.3.3), each widget annotation uses an appearance stream (&lt;code&gt;/AP&lt;/code&gt; -&amp;gt; &lt;code&gt;/N&lt;/code&gt;) to store the actual vector drawing instructions (&lt;code&gt;BT ... ET&lt;/code&gt;) for what appears inside the box. Some desktop tools set &lt;code&gt;/NeedAppearances true&lt;/code&gt; in the &lt;code&gt;/AcroForm&lt;/code&gt; dictionary and leave &lt;code&gt;/AP&lt;/code&gt; empty, expecting the next viewer to regenerate the drawing instructions on open.&lt;/p&gt;

&lt;p&gt;Many browser PDF engines, headless converters, and translation pipelines ignore &lt;code&gt;/NeedAppearances&lt;/code&gt; and read existing &lt;code&gt;/AP&lt;/code&gt; streams or page content streams directly. If you send a filled form without refreshed &lt;code&gt;/AP&lt;/code&gt; streams, the recipient or downstream processor can end up with blank boxes even though &lt;code&gt;/V&lt;/code&gt; still holds your text. Our earlier guide explains &lt;a href="https://dev.to/komopdf/why-filled-pdf-forms-open-blank-in-some-viewers-and-how-to-fix-it-1d9i"&gt;why filled PDF forms open blank across viewers&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Subset fonts and why post-translation text edits break
&lt;/h2&gt;

&lt;p&gt;Most PDF generators embed subsetted fonts rather than complete font files. A page rendered after layout-preserving translation typically embeds a font subset such as &lt;code&gt;ABCDEF+NotoSans&lt;/code&gt; that contains only the glyphs needed for the translated paragraphs on that page.&lt;/p&gt;

&lt;p&gt;If you decide to fix a street address or replace a company name after translation, the editor may not find the characters &lt;code&gt;Q&lt;/code&gt;, &lt;code&gt;7&lt;/code&gt;, or specific accented letters inside that page's embedded font program. You either get fallback glyphs with mismatched metrics, overlapping words, or an error when rewriting the text operator. Running find and replace on the source document before translating avoids patching inside a stripped font subset.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Preparing a clean byte buffer in JavaScript
&lt;/h2&gt;

&lt;p&gt;In a client-side pipeline using &lt;code&gt;pdf-lib&lt;/code&gt;, preparing a document before sending it over the network means pruning unwanted pages from the document tree and writing explicit &lt;code&gt;/AP&lt;/code&gt; appearance streams before saving. Modifying the loaded &lt;code&gt;PDFDocument&lt;/code&gt; directly with &lt;code&gt;removePage()&lt;/code&gt; preserves the Catalog &lt;code&gt;/AcroForm&lt;/code&gt; field registry, whereas copying pages into a brand new document leaves &lt;code&gt;/AcroForm&lt;/code&gt; behind.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;PDFDocument&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'pdf-lib'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;preparePdfForTranslation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sourceBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dropIndexesDesc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unicodeFont&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pdfDoc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sourceBytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Drop unwanted appendix pages in descending 0-based index order&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pageIndex&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;dropIndexesDesc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;pdfDoc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removePage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pageIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pdfDoc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// Write explicit /AP /N streams for every filled field before saving&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getFields&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;updateFieldAppearances&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;unicodeFont&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;pdfDoc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pass an embedded TrueType font to &lt;code&gt;updateFieldAppearances(unicodeFont)&lt;/code&gt; when field values include non-ASCII characters, as covered in our post on &lt;a href="https://dev.to/komopdf/why-non-ascii-pdf-form-values-render-as-boxes-or-crash-pipelines-winansi-vs-type0-fonts-386m"&gt;WinAnsi vs. Type0 PDF form encoding&lt;/a&gt;. Calling &lt;code&gt;removePage()&lt;/code&gt; drops unneeded sheets from the &lt;code&gt;/Pages&lt;/code&gt; tree locally, and calling &lt;code&gt;updateFieldAppearances()&lt;/code&gt; before &lt;code&gt;save()&lt;/code&gt; ensures form values do not depend on &lt;code&gt;/NeedAppearances&lt;/code&gt; support downstream.&lt;/p&gt;

&lt;p&gt;If a signed form must stay locked after you place a handwritten or image signature, calling &lt;code&gt;form.flatten()&lt;/code&gt; moves widget appearances into each page's &lt;code&gt;/Contents&lt;/code&gt; stream so downstream viewers cannot drop or shift widget layers.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Staging local edits and optional translation in KomoPDF
&lt;/h2&gt;

&lt;p&gt;For everyday office files where you want to clean up the document without writing code or creating an account for local editing, &lt;a href="https://komopdf.com" rel="noopener noreferrer"&gt;KomoPDF&lt;/a&gt; puts the local steps and the optional translation handoff in one browser interface.&lt;/p&gt;

&lt;p&gt;Start with &lt;strong&gt;Open PDF&lt;/strong&gt; on &lt;a href="https://komopdf.com" rel="noopener noreferrer"&gt;komopdf.com&lt;/a&gt;. While you stay in the local editor, your file remains on your device and requires no sign-up:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use &lt;strong&gt;Organize pages&lt;/strong&gt; or &lt;strong&gt;Extract pages&lt;/strong&gt; to remove blank sheets or appendices you do not need to share or translate.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;Edit content&lt;/strong&gt; and find and replace to fix outdated addresses, dates, or contact names before any font subsetting changes.&lt;/li&gt;
&lt;li&gt;Open &lt;strong&gt;Fill &amp;amp; forms&lt;/strong&gt; to enter field values, then switch to &lt;strong&gt;Sign&lt;/strong&gt; to place your signature.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Export&lt;/strong&gt; if you want a clean local copy stored on disk right away.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you also need a translated copy, open the &lt;strong&gt;Translate&lt;/strong&gt; panel after finishing those local edits. That panel connects to &lt;a href="https://www.kolmopdf.com" rel="noopener noreferrer"&gt;KolmoPDF&lt;/a&gt; using a separate KolmoPDF account and API key, which the browser holds only for your current session.&lt;/p&gt;

&lt;p&gt;Triggering a translation uploads your current edited PDF version to KolmoPDF and consumes KolmoPDF credits at 2 credits per page, while leaving your original local file untouched. Inside the panel, you can pick the target language, choose between a translated PDF or a bilingual side-by-side layout, and toggle options for image text translation, table translation, or a glossary CSV.&lt;/p&gt;

&lt;p&gt;If a document must stay on your machine, complete your edits and stop at local &lt;strong&gt;Export&lt;/strong&gt; or &lt;strong&gt;Print&lt;/strong&gt;. When you do need a translated version, trimming pages, fixing text, and filling forms locally first keeps unused pages out of the upload and avoids paying twice for corrected drafts.&lt;/p&gt;

&lt;p&gt;You can read the &lt;a href="https://dev.to/komopdf/komopdf-edit-and-fill-pdfs-in-your-browser-without-signing-up-3neb"&gt;KomoPDF product overview&lt;/a&gt; or browse the &lt;a href="https://dev.to/komopdf/series/46349"&gt;KomoPDF: Product Guides &amp;amp; Updates&lt;/a&gt; series for related guides.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Why Non-ASCII PDF Form Values Render as Boxes or Crash Pipelines: WinAnsi vs. Type0 Fonts</title>
      <dc:creator>KomoPDF</dc:creator>
      <pubDate>Thu, 12 Nov 2026 15:41:54 +0000</pubDate>
      <link>https://dev.to/komopdf/why-non-ascii-pdf-form-values-render-as-boxes-or-crash-pipelines-winansi-vs-type0-fonts-386m</link>
      <guid>https://dev.to/komopdf/why-non-ascii-pdf-form-values-render-as-boxes-or-crash-pipelines-winansi-vs-type0-fonts-386m</guid>
      <description>&lt;p&gt;A customer types a name like &lt;code&gt;Łukasz&lt;/code&gt;, &lt;code&gt;Doamnă&lt;/code&gt;, or &lt;code&gt;田中太郎&lt;/code&gt; into a PDF onboarding form. Your script writes that value to the AcroForm text field and calls save, and the job crashes with &lt;code&gt;Error: WinAnsi cannot encode "沒" (0x6c92)&lt;/code&gt; (documented in &lt;a href="https://github.com/Hopding/pdf-lib/issues/1152" rel="noopener noreferrer"&gt;pdf-lib #1152&lt;/a&gt;). Other PDF writers skip encoding checks and emit the file anyway, leaving Adobe Acrobat, Chrome PDFium, and macOS Preview rendering empty boxes, question marks, or corrupted Latin characters.&lt;/p&gt;

&lt;p&gt;When you inspect the saved file afterward, &lt;code&gt;field.getText()&lt;/code&gt; still returns the exact Unicode string. The text is stored inside the document, yet the visible box displays garbage or refuses to serialize. PDF separates a form field's logical data value from its drawn appearance stream, and those two structures obey different encoding rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two encoding systems in one form field
&lt;/h2&gt;

&lt;p&gt;Under ISO 32000-1, every AcroForm text field, dropdown, and option list maintains its state in two separate places.&lt;/p&gt;

&lt;p&gt;The logical value sits in the field dictionary's &lt;code&gt;/V&lt;/code&gt; entry as a PDF text string. ISO 32000-1 §7.9.2.2 allows text strings to use &lt;code&gt;PDFDocEncoding&lt;/code&gt; (a single-byte encoding for code points 0 to 255) or UTF-16BE prefixed with the byte-order mark &lt;code&gt;0xFE 0xFF&lt;/code&gt;. In hex notation inside a PDF object, &lt;code&gt;"田中"&lt;/code&gt; is stored as &lt;code&gt;&amp;lt;FEFF75304E2D&amp;gt;&lt;/code&gt;. Any compliant PDF parser can store and extract arbitrary Unicode strings in &lt;code&gt;/V&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The visual text on the page lives in the widget's normal appearance stream (&lt;code&gt;/AP -&amp;gt; /N&lt;/code&gt;), which is a Form XObject content stream. Under ISO 32000-1 §12.7.3.3 (Variable Text), viewers paint the field box by running content-stream operators inside &lt;code&gt;/Tx BMC ... EMC&lt;/code&gt; using the Default Appearance (&lt;code&gt;/DA&lt;/code&gt;) string and the AcroForm Default Resources (&lt;code&gt;/DR&lt;/code&gt;) font dictionary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/Tx BMC
  q
    BT
      /Helv 12 Tf
      0 g
      2 6 Td
      (M\374ller) Tj
    ET
  Q
EMC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Content streams do not recognize UTF-16BE or &lt;code&gt;PDFDocEncoding&lt;/code&gt;. The string operands passed to &lt;code&gt;Tj&lt;/code&gt; or &lt;code&gt;TJ&lt;/code&gt; are raw character codes decoded strictly through the &lt;code&gt;/Encoding&lt;/code&gt; of whichever font &lt;code&gt;/Helv&lt;/code&gt; points to in &lt;code&gt;/DR&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why default /Helv fields break outside WinAnsi
&lt;/h2&gt;

&lt;p&gt;Most form templates generated by desktop editors initialize &lt;code&gt;/DA&lt;/code&gt; to &lt;code&gt;/Helv 12 Tf 0 g&lt;/code&gt; and bind &lt;code&gt;/Helv&lt;/code&gt; in &lt;code&gt;/AcroForm -&amp;gt; /DR -&amp;gt; /Font&lt;/code&gt; to the Standard 14 Helvetica font with &lt;code&gt;/Encoding /WinAnsiEncoding&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;WinAnsiEncoding&lt;/code&gt; maps single bytes to Windows-1252, covering 218 Latin characters such as ASCII plus Western European accented letters (&lt;code&gt;ü&lt;/code&gt;, &lt;code&gt;é&lt;/code&gt;, &lt;code&gt;ñ&lt;/code&gt;). It lacks code points for Polish &lt;code&gt;ł&lt;/code&gt;, Romanian &lt;code&gt;ț&lt;/code&gt;, Greek, Cyrillic, Arabic, and CJK ideographs.&lt;/p&gt;

&lt;p&gt;Three failure modes show up when non-WinAnsi text enters a &lt;code&gt;/Helv&lt;/code&gt; field:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Strict libraries throw an encoding error when rebuilding &lt;code&gt;/AP -&amp;gt; /N&lt;/code&gt; because the code point has no WinAnsi byte. That is why &lt;code&gt;pdf-lib&lt;/code&gt; fails on &lt;code&gt;save()&lt;/code&gt; if the default Helvetica appearance provider runs.&lt;/li&gt;
&lt;li&gt;Permissive writers substitute &lt;code&gt;?&lt;/code&gt; (&lt;code&gt;0x3F&lt;/code&gt;) into &lt;code&gt;/AP&lt;/code&gt; or dump raw UTF-8 bytes into a single-byte stream. The viewer reads each UTF-8 byte as a separate WinAnsi character, turning multi-byte Unicode text into broken Latin pairs.&lt;/li&gt;
&lt;li&gt;Within bytes &lt;code&gt;0x80&lt;/code&gt; to &lt;code&gt;0x9F&lt;/code&gt;, &lt;code&gt;WinAnsiEncoding&lt;/code&gt; and &lt;code&gt;PDFDocEncoding&lt;/code&gt; disagree. Byte &lt;code&gt;0x97&lt;/code&gt; represents an em dash in WinAnsi and &lt;code&gt;Š&lt;/code&gt; in &lt;code&gt;PDFDocEncoding&lt;/code&gt;, so mixing the two corrupts punctuation across viewers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Setting &lt;code&gt;/NeedAppearances true&lt;/code&gt; on &lt;code&gt;/AcroForm&lt;/code&gt; sometimes hides the bug in Adobe Acrobat, which regenerates missing appearances with system fonts on open. Chrome PDFium, Safari, and mobile viewers either rely on &lt;code&gt;/AP&lt;/code&gt; or ignore &lt;code&gt;/NeedAppearances&lt;/code&gt; (deprecated in PDF 2.0), as covered in &lt;a href="https://dev.to/komopdf/why-filled-pdf-forms-open-blank-in-some-viewers-and-how-to-fix-it-1d9i"&gt;why filled PDF forms open blank in some viewers&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Type0 composite fonts and Identity-H work
&lt;/h2&gt;

&lt;p&gt;To render non-Latin or mixed-script text reliably inside &lt;code&gt;/AP -&amp;gt; /N&lt;/code&gt; across viewers, the font referenced by &lt;code&gt;/DA&lt;/code&gt; and the appearance stream's &lt;code&gt;/Resources&lt;/code&gt; must be a Type0 composite font (&lt;code&gt;/Subtype /Type0&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;A Type0 font dictionary combines &lt;code&gt;/Encoding /Identity-H&lt;/code&gt; (horizontal writing) with a &lt;code&gt;/DescendantFonts&lt;/code&gt; &lt;code&gt;CIDFont&lt;/code&gt; pointing to an embedded TrueType or OpenType font program and a &lt;code&gt;/ToUnicode&lt;/code&gt; CMap stream:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;25 0 obj
&amp;lt;&amp;lt;
  /Type /Font
  /Subtype /Type0
  /BaseFont /NotoSansCJK-Regular
  /Encoding /Identity-H
  /DescendantFonts [26 0 R]
  /ToUnicode 27 0 R
&amp;gt;&amp;gt;
endobj
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of single-byte WinAnsi literals like &lt;code&gt;(Hello) Tj&lt;/code&gt;, the &lt;code&gt;/AP -&amp;gt; /N&lt;/code&gt; stream emits two-byte glyph or character IDs as hex strings (&lt;code&gt;&amp;lt;00280045&amp;gt; Tj&lt;/code&gt;). Because the font program and &lt;code&gt;/ToUnicode&lt;/code&gt; CMap travel inside the PDF, every viewer renders the exact glyphs and preserves text copy-paste without relying on local OS font fallback.&lt;/p&gt;

&lt;h2&gt;
  
  
  Embedding a Unicode font for forms in JavaScript
&lt;/h2&gt;

&lt;p&gt;In &lt;code&gt;pdf-lib&lt;/code&gt;, filling non-ASCII forms requires registering &lt;code&gt;@pdf-lib/fontkit&lt;/code&gt; (or &lt;code&gt;@cantoo/fontkit&lt;/code&gt;), embedding a font that covers the target script, and passing that &lt;code&gt;PDFFont&lt;/code&gt; instance to &lt;code&gt;form.updateFieldAppearances(unicodeFont)&lt;/code&gt; after setting field values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;PDFDocument&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'pdf-lib'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;fontkit&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@pdf-lib/fontkit'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fillUnicodeForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdfBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fontBytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pdfDoc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdfBytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;pdfDoc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;registerFontkit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fontkit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Embed a TTF/OTF font containing the target Unicode glyphs&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;unicodeFont&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;pdfDoc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;embedFont&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fontBytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pdfDoc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTextField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ApplicantName'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Łukasz Müller'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTextField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'LocalAddress'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'東京都渋谷区 1-2-3'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Rebuild /AP streams using the embedded Type0 font&lt;/span&gt;
  &lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;updateFieldAppearances&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;unicodeFont&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Updated fields are now clean; skip the default Helvetica pass&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;pdfDoc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;updateFieldAppearances&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The call order determines whether the pipeline succeeds. Calling &lt;code&gt;form.updateFieldAppearances(unicodeFont)&lt;/code&gt; before &lt;code&gt;setText()&lt;/code&gt; or &lt;code&gt;select()&lt;/code&gt; fails, because mutating a field marks it dirty again and &lt;code&gt;pdfDoc.save()&lt;/code&gt; runs &lt;code&gt;form.updateFieldAppearances()&lt;/code&gt; with no arguments by default, falling back to &lt;code&gt;StandardFonts.Helvetica&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  File size and editability tradeoffs
&lt;/h2&gt;

&lt;p&gt;Embedding a full CJK or pan-Unicode font adds several megabytes to each PDF. Passing &lt;code&gt;{ subset: true }&lt;/code&gt; to &lt;code&gt;pdfDoc.embedFont(fontBytes, { subset: true })&lt;/code&gt; strips unused glyphs when flattening forms or shipping read-only files.&lt;/p&gt;

&lt;p&gt;Keep the full font embedded without subsetting if recipients still need to edit fields interactively. A subsetted Type0 font contains only the glyphs present when saved, so typing new characters after download produces missing boxes or inconsistent font fallback.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>unicode</category>
    </item>
    <item>
      <title>Deleting or Extracting PDF Pages Without Uploading a 50MB File: How Browser /Pages Tree Copying Works</title>
      <dc:creator>KomoPDF</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:39:13 +0000</pubDate>
      <link>https://dev.to/komopdf/deleting-or-extracting-pdf-pages-without-uploading-a-50mb-file-how-browser-pages-tree-copying-mo9</link>
      <guid>https://dev.to/komopdf/deleting-or-extracting-pdf-pages-without-uploading-a-50mb-file-how-browser-pages-tree-copying-mo9</guid>
      <description>&lt;p&gt;If you need to drop two confidential pages from a 50MB legal contract or pull three sheets out of a scanned invoice bundle, uploading the entire file to a remote server just to reorder objects wastes bandwidth and exposes sensitive documents to third-party storage.&lt;/p&gt;

&lt;p&gt;A browser already has enough memory and compute to handle structural PDF edits locally. Editing pages inside the tab avoids network latency and keeps the file on your device.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. How the PDF page tree is structured
&lt;/h2&gt;

&lt;p&gt;Under ISO 32000-1 (§7.7.3), a PDF stores its pages in a tree structure rooted in the document Catalog (&lt;code&gt;/Root&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Catalog (/Root)
  └── Pages Tree (/Pages)
        ├── Page 1 (/Page) -&amp;gt; Object 10 0 R
        ├── Page 2 (/Page) -&amp;gt; Object 15 0 R
        └── Page 3 (/Page) -&amp;gt; Object 20 0 R
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each &lt;code&gt;/Pages&lt;/code&gt; node holds two main entries: &lt;code&gt;/Kids&lt;/code&gt;, an array of indirect references to child &lt;code&gt;/Page&lt;/code&gt; objects or intermediate &lt;code&gt;/Pages&lt;/code&gt; branch nodes, and &lt;code&gt;/Count&lt;/code&gt;, an integer tracking the total number of leaf pages beneath that node. When a viewer opens a PDF, it reads the trailer at the end of the file, follows &lt;code&gt;/Root&lt;/code&gt; to &lt;code&gt;/Pages&lt;/code&gt;, and resolves individual page dictionaries on demand instead of decoding the entire document upfront.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Reordering and extracting pages without re-encoding assets
&lt;/h2&gt;

&lt;p&gt;Extracting or deleting pages does not require decompressing, rendering, and re-encoding page content. Vector instructions, embedded fonts, and raster images live in separate indirect objects, while the &lt;code&gt;/Page&lt;/code&gt; dictionary only holds pointers to them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10 0 obj
&amp;lt;&amp;lt;
  /Type /Page
  /Parent 4 0 R
  /MediaBox [0 0 612 792]
  /Resources 12 0 R
  /Contents 14 0 R
&amp;gt;&amp;gt;
endobj
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Object &lt;code&gt;10 0 R&lt;/code&gt; points to &lt;code&gt;/Resources 12 0 R&lt;/code&gt; and &lt;code&gt;/Contents 14 0 R&lt;/code&gt; rather than storing the image bitmaps or font tables inline. To delete or reorder pages inside an existing document, a client-side editor updates the &lt;code&gt;/Kids&lt;/code&gt; array and &lt;code&gt;/Count&lt;/code&gt; integer in the &lt;code&gt;/Pages&lt;/code&gt; tree. To export a subset into a new file, it walks the selected &lt;code&gt;/Page&lt;/code&gt; dictionaries, copies only their reachable indirect objects, and writes a fresh cross-reference (&lt;code&gt;xref&lt;/code&gt;) table. Because embedded raster streams and font programs are copied as raw bytes, extraction typically finishes in milliseconds even on large scanned files.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Copying selected pages in JavaScript
&lt;/h2&gt;

&lt;p&gt;Using &lt;code&gt;pdf-lib&lt;/code&gt; inside a browser worker or main thread, extracting specific 0-based page indexes into a new &lt;code&gt;Uint8Array&lt;/code&gt; requires only a few calls:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;PDFDocument&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'pdf-lib'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;extractPagesLocally&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fileBuffer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pageIndexesToKeep&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sourcePdf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fileBuffer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;targetPdf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Copies the selected /Page dictionaries and their reachable object graph&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;copiedPages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;targetPdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;copyPages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sourcePdf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pageIndexesToKeep&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;copiedPages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;targetPdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;targetPdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything executes against an in-memory &lt;code&gt;ArrayBuffer&lt;/code&gt; or &lt;code&gt;Uint8Array&lt;/code&gt; inside the browser tab without sending the file over HTTP.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Three structural traps in browser page tools
&lt;/h2&gt;

&lt;p&gt;Moving &lt;code&gt;/Page&lt;/code&gt; objects across trees breaks in predictable ways if a parser copies dictionaries naively.&lt;/p&gt;

&lt;p&gt;Shared resource dictionaries cannot be pruned blindly. Two pages in the same document often point to the same embedded font subset or ICC color profile object. Deleting page 1 without checking whether page 2 still references &lt;code&gt;/Font 24 0 R&lt;/code&gt; will break text rendering on the remaining pages. A safe exporter builds a full reachability graph from the kept &lt;code&gt;/Kids&lt;/code&gt; before dropping unreferenced objects.&lt;/p&gt;

&lt;p&gt;Inherited page attributes also cause blank or clipped output. ISO 32000-1 lets &lt;code&gt;/MediaBox&lt;/code&gt;, &lt;code&gt;/CropBox&lt;/code&gt;, &lt;code&gt;/Rotate&lt;/code&gt;, and &lt;code&gt;/Resources&lt;/code&gt; live on an ancestor &lt;code&gt;/Pages&lt;/code&gt; node instead of each leaf &lt;code&gt;/Page&lt;/code&gt;. Copying a leaf &lt;code&gt;/Page&lt;/code&gt; out of a multi-level tree without resolving and flattening inherited attributes onto the leaf produces pages with missing fonts or unknown dimensions.&lt;/p&gt;

&lt;p&gt;Orphaned &lt;code&gt;/Outlines&lt;/code&gt; (bookmarks) and named destinations need cleanup. When pages are removed or reordered, bookmark entries in the document Catalog still point to old page object IDs. If an exporter leaves dangling destination references behind, desktop viewers can jump to the wrong page or fail validation when opening the file.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Organizing and extracting pages locally in KomoPDF
&lt;/h2&gt;

&lt;p&gt;For day-to-day document tasks where you want to drop an appendix, reorder scanned pages, or pull out a signed section without writing scripts or creating an account, &lt;a href="https://komopdf.com" rel="noopener noreferrer"&gt;KomoPDF&lt;/a&gt; runs those page operations directly in your browser.&lt;/p&gt;

&lt;p&gt;Open a file via &lt;strong&gt;Open PDF&lt;/strong&gt;, then switch to &lt;strong&gt;Organize pages&lt;/strong&gt; to reorder or delete sheets, or &lt;strong&gt;Extract pages&lt;/strong&gt; to save a subset as a separate PDF. The local editing workflow keeps the file on your device, and you can pair page cleanup with form filling, content edits, or signing before exporting. If you also need a translated copy afterward, the optional &lt;strong&gt;Translate&lt;/strong&gt; panel connects to &lt;a href="https://www.kolmopdf.com" rel="noopener noreferrer"&gt;KolmoPDF&lt;/a&gt; using a separate KolmoPDF API key and uploads only when you explicitly request translation.&lt;/p&gt;

&lt;p&gt;You can check the &lt;a href="https://dev.to/komopdf/komopdf-edit-and-fill-pdfs-in-your-browser-without-signing-up-3neb"&gt;KomoPDF product overview&lt;/a&gt; for a full walkthrough of the editor controls, or browse more guides in the &lt;a href="https://dev.to/komopdf/series/46349"&gt;KomoPDF: Product Guides &amp;amp; Updates&lt;/a&gt; series.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Why PDF Form Checkboxes Fail to Toggle Across Viewers: The /AP and Export Value Trap</title>
      <dc:creator>KomoPDF</dc:creator>
      <pubDate>Tue, 10 Nov 2026 15:40:33 +0000</pubDate>
      <link>https://dev.to/komopdf/why-pdf-form-checkboxes-fail-to-toggle-across-viewers-the-ap-and-export-value-trap-56ie</link>
      <guid>https://dev.to/komopdf/why-pdf-form-checkboxes-fail-to-toggle-across-viewers-the-ap-and-export-value-trap-56ie</guid>
      <description>&lt;p&gt;If you generate or process fillable PDF documents, you have likely run into this bug: a user clicks a checkbox or selects a radio button in a web-based PDF viewer, but the mark refuses to appear. Or worse, a backend script sets the field value to &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;"Yes"&lt;/code&gt;, yet when the customer downloads and opens the document in Adobe Acrobat or Apple Preview, the checkbox remains blank.&lt;/p&gt;

&lt;p&gt;Developers often assume the PDF viewer is broken or the field coordinates are misaligned. In most cases, the underlying problem is a subtle mismatch between the field's logical value dictionary and its visual appearance dictionary under ISO 32000-1.&lt;/p&gt;

&lt;p&gt;Understanding how the PDF specification binds binary toggle states to appearance streams explains why this happens and how to fix it in code.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. How AcroForm checkboxes and radio buttons store state
&lt;/h2&gt;

&lt;p&gt;In ISO 32000-1 (§12.7.4.2), button fields (&lt;code&gt;/Btn&lt;/code&gt;) handle pushbuttons, checkboxes, and radio buttons. Unlike an HTML &lt;code&gt;&amp;lt;input type="checkbox"&amp;gt;&lt;/code&gt; that toggles between a boolean state, a PDF checkbox or radio button manages three interrelated keys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/V&lt;/code&gt; (Value): The logical state of the field in the widget dictionary.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/AS&lt;/code&gt; (Appearance State): The currently active subdictionary key inside the &lt;code&gt;/AP&lt;/code&gt; (Appearance) dictionary.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/AP&lt;/code&gt; (Appearance Dictionary): A dictionary containing an &lt;code&gt;/N&lt;/code&gt; (Normal) entry, which points to a dictionary of appearance streams for each allowable state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is what a conforming checkbox widget looks like in the PDF object stream:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;&amp;lt;
  /Type /Annot
  /Subtype /Widget
  /FT /Btn
  /T (SubscribeNewsletter)
  /V /Yes
  /AS /Yes
  /AP &amp;lt;&amp;lt;
    /N &amp;lt;&amp;lt;
      /Off 12 0 R
      /Yes 13 0 R
    &amp;gt;&amp;gt;
  &amp;gt;&amp;gt;
&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that the stream dictionary for &lt;code&gt;/AP -&amp;gt; /N&lt;/code&gt; defines two specific names: &lt;code&gt;/Off&lt;/code&gt; and &lt;code&gt;/Yes&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;When a compliant viewer toggles the checkbox on:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It sets &lt;code&gt;/V&lt;/code&gt; to &lt;code&gt;/Yes&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It sets &lt;code&gt;/AS&lt;/code&gt; to &lt;code&gt;/Yes&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It renders the vector instructions inside object &lt;code&gt;13 0 R&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  2. The export value trap: &lt;code&gt;/Yes&lt;/code&gt; is not universal
&lt;/h2&gt;

&lt;p&gt;The most common failure occurs when authoring tools use custom export values instead of &lt;code&gt;/Yes&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example, many PDF form designers generate appearance states using arbitrary identifiers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/AP &amp;lt;&amp;lt;
  /N &amp;lt;&amp;lt;
    /Off 12 0 R
    /Choice1 13 0 R
  &amp;gt;&amp;gt;
&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If an automated backend process updates this field with a standard &lt;code&gt;/Yes&lt;/code&gt; name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/Yes'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two bugs commonly emerge depending on the viewer implementation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Desynchronized appearance&lt;/strong&gt;: The viewer sees &lt;code&gt;/V /Yes&lt;/code&gt;, but because &lt;code&gt;/Yes&lt;/code&gt; does not exist in the &lt;code&gt;/N&lt;/code&gt; dictionary, it falls back to &lt;code&gt;/Off&lt;/code&gt; or renders nothing. The underlying form data is technically populated, but the visual checkbox remains empty.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unresponsive UI clicks&lt;/strong&gt;: In lightweight in-browser JavaScript viewers, clicking a checkbox often runs a toggle handler hardcoded to flip between &lt;code&gt;/Off&lt;/code&gt; and &lt;code&gt;/Yes&lt;/code&gt;. Because the widget dictionary only defines &lt;code&gt;/Choice1&lt;/code&gt;, the viewer's state machine fails to resolve the appearance stream and drops the click entirely.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Radio button groups: Parent fields and widget kids
&lt;/h2&gt;

&lt;p&gt;Radio buttons introduce an additional layer of hierarchy. Under ISO 32000-1, a radio button group is usually structured as a single parent field with multiple child widget annotations (&lt;code&gt;/Kids&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Parent Field:
&amp;lt;&amp;lt;
  /FT /Btn
  /Ff 49152          % Flags: Pushbutton=0, Radio=1, NoToggleToOff=1
  /T (PaymentMethod)
  /V /CreditCard
&amp;gt;&amp;gt;

Child Widget 1 (Credit Card):
&amp;lt;&amp;lt;
  /Type /Annot
  /Subtype /Widget
  /Parent 20 0 R
  /AS /CreditCard
  /AP &amp;lt;&amp;lt; /N &amp;lt;&amp;lt; /Off 31 0 R /CreditCard 32 0 R &amp;gt;&amp;gt; &amp;gt;&amp;gt;
&amp;gt;&amp;gt;

Child Widget 2 (Bank Transfer):
&amp;lt;&amp;lt;
  /Type /Annot
  /Subtype /Widget
  /Parent 20 0 R
  /AS /Off
  /AP &amp;lt;&amp;lt; /N &amp;lt;&amp;lt; /Off 41 0 R /BankTransfer 42 0 R &amp;gt;&amp;gt; &amp;gt;&amp;gt;
&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When selecting "Bank Transfer":&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The parent field's &lt;code&gt;/V&lt;/code&gt; must be updated to &lt;code&gt;/BankTransfer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Child Widget 1's &lt;code&gt;/AS&lt;/code&gt; must be switched to &lt;code&gt;/Off&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Child Widget 2's &lt;code&gt;/AS&lt;/code&gt; must be switched to &lt;code&gt;/BankTransfer&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If an integration updates only the parent &lt;code&gt;/V&lt;/code&gt; without traversing &lt;code&gt;/Kids&lt;/code&gt; to synchronize each child's &lt;code&gt;/AS&lt;/code&gt;, Adobe Acrobat may reconstruct the appearance on load, while Chrome PDFium or mobile viewers will show both buttons selected or neither.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Inspecting export values programmatically
&lt;/h2&gt;

&lt;p&gt;Before programmatically updating a checkbox or radio button, inspect the &lt;code&gt;/AP&lt;/code&gt; dictionary to discover the exact on-state name defined by the authoring software:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;PDFName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;PDFDict&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'pdf-lib'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;fs&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'fs/promises'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getCheckboxExportValues&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdfPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fieldName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;fileBytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdfPath&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pdfDoc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fileBytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pdfDoc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fieldName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;widgets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;acroField&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getWidgets&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;exportValues&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;widget&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;widgets&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;widget&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PDFName&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'AP'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;apDict&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pdfDoc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lookup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;PDFDict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;normalAp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;apDict&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PDFName&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'N'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;normalAp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;normalDict&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pdfDoc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lookup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;normalAp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;PDFDict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;keys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;normalDict&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;asString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Filter out /Off to find the active state name&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;onStates&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'/Off'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;exportValues&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onStates&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;exportValues&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  5. Engineering takeaways for form pipelines
&lt;/h2&gt;

&lt;p&gt;Building a reliable PDF form pipeline comes down to respecting the relationship between logical fields and visual appearances:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Synchronize &lt;code&gt;/V&lt;/code&gt; and &lt;code&gt;/AS&lt;/code&gt; on every mutation. Updating only the logical value leaves rendering up to viewer-specific repair heuristics, which behave differently across Adobe Acrobat, Chrome PDFium, and Safari's native renderer.&lt;/li&gt;
&lt;li&gt;Query on-state tokens dynamically instead of hardcoding &lt;code&gt;/Yes&lt;/code&gt;. Inspecting &lt;code&gt;/AP -&amp;gt; /N&lt;/code&gt; prevents silent mismatches caused by designer export names like &lt;code&gt;/Choice1&lt;/code&gt; or &lt;code&gt;/1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For radio groups, manage the parent-child hierarchy explicitly. Update the parent &lt;code&gt;/V&lt;/code&gt;, set the active child's &lt;code&gt;/AS&lt;/code&gt; to the chosen export value, and switch inactive siblings in &lt;code&gt;/Kids&lt;/code&gt; back to &lt;code&gt;/Off&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>pdf</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
