You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何判断Dynamsoft.Forms.DSViewer表单是否为空?

Checking if a Dynamsoft.Forms.DSViewer Form is Empty

Hey there! I’ve run into similar undocumented small checks with Dynamsoft’s controls before, so I feel your pain. Let’s break down two common scenarios for determining if your DSViewer "form" is empty, depending on what you mean by that term:


Scenario 1: No document/form is loaded in the Viewer

If you’re checking whether the DSViewer control itself has no document loaded at all, you can use the built-in properties of the control:

// Check if no documents are loaded, or the current document is null
bool isViewerEmpty = dsViewerControl.DocumentCount == 0 || dsViewerControl.CurrentDocument == null;

if (isViewerEmpty)
{
    // Do something when the viewer has no content
    MessageBox.Show("The viewer has no form/document loaded!");
}

This is the simplest check and works for any type of content (images, PDFs, etc.) loaded into the DSViewer.


Scenario 2: Loaded PDF Form has no filled-in values

If you’re working with a fillable PDF form and want to check if all fields are empty, you’ll need to access the form fields directly from the loaded document:

bool isFormFieldsEmpty = true;

// First make sure a document is loaded
if (dsViewerControl.CurrentDocument != null)
{
    // Get all form fields from the current document
    var formFields = dsViewerControl.CurrentDocument.GetFormFields();
    
    // Loop through each field to check for values
    foreach (var field in formFields)
    {
        // Check if the field has a non-empty value
        if (!string.IsNullOrWhiteSpace(field.Value))
        {
            isFormFieldsEmpty = false;
            break; // No need to check further once we find a filled field
        }
    }
}

if (isFormFieldsEmpty)
{
    MessageBox.Show("The loaded form has no filled-in values!");
}

Notes to keep in mind:

  • If you’re dealing with scanned image forms (not fillable PDFs), this method won’t work—you’d need to use Dynamsoft’s OCR tools to detect text/content in the image, which is a more involved process.
  • Double-check that you’ve referenced the correct Dynamsoft assemblies (like Dynamsoft.PDF if working with PDFs) to access the GetFormFields() method.

内容的提问来源于stack exchange,提问作者muhammad shoaib

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:29:48