如何使用JWebBrowser禁用PDF打印选项

时间:2019-03-19 18:06:16

标签: java swing

我正在使用The DJ ProjectPDF文件打开到JFrame中。 使用下一个代码:

JPanel panel = new JPanel();
        setContentPane(panel);
        JWebBrowser browser = new JWebBrowser();

        browser.setBarsVisible(false);
        browser.setStatusBarVisible(false);
        browser.print(false);

        browser.setPreferredSize(new Dimension(800,600));
        panel.add(browser);
        browser.navigate("C:\\Users\\MyUser\\Desktop\\acta.pdf");
        pack();
        setVisible(true);
        setPreferredSize(new Dimension(800,600));

并且正在加载PDF文件,但是我想禁用以下选项:

enter image description here

printSave选项。我知道这是通过Web浏览器渲染的。 可以使用java删除这些选项吗?

1 个答案:

答案 0 :(得分:0)

我已经发现的唯一方法是,通过以下方式禁用所有组件和交互:

// An example Generic Interface
interface ISyncInterface<T>
{
    Task DoSync();
    IEnumerable<T> NewItems { get; }
}

// a manager-class that registers different classes implementing
// the generic interface.
// The code works - can it be done better?
class Manager
{
    private List<Object> _services = new List<Object>(); // <- works but is basically non generic
    // however the RegisterService() ensures that only correct types can be added.

    // would like to have something like below to indicate the Interface-Type
    // however: this would only allow _services2.Add to hold types of ISyncInterface<Object>
    //    - ISyncInterface<ServiceA_DTO> would fail.
    private List<ISyncInterface<Object>> _services2 = new List<ISyncInterface<Object>>();

    void RegisterService<T, U>(T service)
        where T : ISyncInterface<U>
    {
        _services.Add(service); // <- works e.g. for SyncServiceA 

        // _services2.Add(service); // <- FAILS for SyncServiceA - no conversion
        // _services2.Add((ISyncInterface<Object>) service); // <- FAILS also - no explicit cast
    }
}

// SETUP - The classes used above. Just to clarify.
class ServiceA_DTO { }
class ServiceB_DTO { }

class SyncServiceA : ISyncInterface<ServiceA_DTO>
{
    public Task DoSync() {}
    public IEnumerable<ServiceA_DTO> NewItems { get; }
}

class SyncServiceB : ISyncInterface<ServiceB_DTO>
{
    public Task DoSync() {}
    public IEnumerable<ServiceB_DTO> NewItems { get; } 
}

或禁用所有右键单击,例如:

browser.getNativeComponent().setEnabled(false)