Printer Interceptor

Print job watermarking library

developed and tested by Redwerk
×
Where do you want us to send our BlueCloud Case Study?
Please enter your business email isn′t a business email

BlueCloud Technologies provides IT services and solutions to enterprise organizations in EMEA. They specialize in enterprise architecture, app integration, and access management. Their products, including MailID, ScreenID, and OneGate, help companies streamline operations, improve efficiency, and enhance security.

All Customers

Desktop App Development

We used our profound knowledge of .NET technologies and Windows platforms to deliver a high-quality, efficient, and reliable library for our client’s desktop app. Our solution is fully compatible with a wide range of Windows versions (8, 10, 11) and architectures (32-bit, 64-bit), and it can handle complex workflows.

Learn more

Enterprise Software

We extended the functionality of ScreenID, one of BlueCloud’s signature enterprise apps. We developed a dynamic link library that can be integrated with diverse .NET apps. It intercepts and monitors print jobs, enabling features like watermark insertion, print job prevention, and real-time printer status tracking.

Learn more

Challenge

BlueCloud Technologies sought Redwerk’s expertise to enhance ScreenID, their screen watermarking software. Designed to protect employee monitors from unauthorized capture, ScreenID displays watermarks on all Windows applications and documents. While BlueCloud Technologies had developed Screen ID in-house, they were looking for a partner with deeper expertise in C++ and .NET application development.

This project required a solid understanding of .NET and native C++ development due to several key challenges:

  • XPS File Complexity: XPS (XML Paper Specification) files are intricate, requiring specialized libraries and APIs. Their structure, containing diverse resources like images, fonts, and pages, presented a hurdle for direct manipulation.
  • Watermark Detection and Application: Determining if a document already has a watermark and where to place a new one requires a deep understanding of how resources are stored within XPS files.
  • Watermark Processing and Positioning: Applying image and text watermarks precisely demanded intricate calculations for scaling and positioning based on document size and resolution.
  • File Handling: Transforming print spool files into XPS format for watermarking and then converting them back introduced challenges in handling large files, ZIP-like structures, and preventing data corruption.
  • Performance with Large Files: Large, multi-page, image-heavy documents threatened to create performance bottlenecks during processing, extraction, and repackaging.
  • Debugging & Error Handling: Ensuring flawless execution of complex file processing, watermarking, and XPS conversion with potentially malformed or unexpected file formats was a major concern. We had to ensure the interceptor gracefully handled errors and provided informative feedback to the caller application.
  • Cross-Compatibility between XPS Formats: OpenXPS and MS XPS formats have subtle differences in their schemas. We needed to ensure compatibility between these formats during conversions.
  • Concurrency & Multithreading: The main issue is managing multiple threads safely, as the code monitors multiple printers and jobs, spawning threads for each task. This requires synchronization to prevent race conditions where multiple threads might attempt to modify shared resources such as the printer list or event objects.
  • Printer & Job Notifications: Monitoring printer job notifications in real time is difficult due to the asynchronous nature of job submission, job completion, and printer changes. The program must detect these events efficiently without missing any notifications.

We had to ensure compatibility with a wide range of Windows versions (8, 10, 11) and architectures (32-bit, 64-bit), which can be challenging due to differences in API availability and behavior. We also had to ensure compatibility with .NET applications and the ability to integrate Printer Interceptor as a dynamic link library (DLL) or package. Finally, the library we needed to develop had to intercept print jobs initiated by any application, regardless of the specific software or printing device used.

Solution

We developed Printer Interceptor, a dynamic link library (DLL) that intercepts and modifies print jobs on Windows devices. DLLs can be used to share code between multiple applications, saving time and effort. Also, DLLs can help reduce applications’ size, making them easier to download and install. Finally, DLLs can be updated independently of the applications that use them, making it easier to keep them up-to-date.

Architecture

Printer Interceptor’s architecture consists of two modules. The first module handles printer-related tasks, such as retrieving printer information and monitoring print jobs. This module includes callback mechanisms for various events like printer notifications, job notifications, job interceptions, and exceptions. The second module is responsible for various operations related to printers, such as monitoring print jobs and applying watermarks. It also provides native integration into .NET projects.

Communication between the modules is event-based, using delegates. When the first module intercepts a print job, it triggers delegates handled by the second module. Additionally, the client application can handle delegates provided by the second module to receive notifications, logs, and exceptions. Event-based communication ensures a decoupled and flexible design, making it easier to add or modify features without affecting the core functionality.

Core Features

Here is a brief overview of Printer Interceptor’s functionality:

  • Printing Control: The solution provides the ability to stop, disable, and modify printing for certain users or jobs. The library allows intercepting of both physical devices (printer) and virtual jobs (Print to PDF, Print to XPS).
  • Watermark Customization: We implemented a flexible watermark customization system that allows for various text formats, image types (including logos and QR codes), and positioning options.
  • Statuses: The library tracks printer and job statuses. For printers, statuses indicate whether the printer is being intercepted, and watermark processing is applied. It also indicates whether the printer is no longer being intercepted, usually due to an exception, among other things. For jobs, statuses include initial spooling, processing, and completion with or without watermarks.

Tech Implementation & Problem Solving

To overcome the technical challenges, our developers implemented a series of tried-and-true solutions:

  • XPS File Complexity: To deal with the intricacies of these files, we implemented a clear separation between source, processed, and rendered files. We relied on libraries such as Microsoft XPS to manipulate XPS elements and apply transformations.
  • Watermark Detection and Application: We used a method that efficiently scans XPS documents for existing watermarks by reading page content, extracting images and fonts, and comparing their URIs to a predefined salt value. This ensures that new watermarks are not applied to pages that already have them, preventing duplication.
  • Watermark Processing and Positioning: The code uses page dimensions and DPI (dots per inch) calculations to scale the watermarks to the correct size. It also adjusts the position based on predefined enumerations for watermark placement (top left, center, and bottom right). Creating IXpsOMImageBrush and IXpsOMPath ensures that the watermark is drawn correctly on the page.
  • File Handling: Our solution carefully extracts the XPS content from the spool file, treating it like a compressed archive. We then make necessary changes to the XPS content to ensure compatibility and allow for watermarking. For spool files split into multiple parts, we combine them into a single complete file before processing.
  • Performance with Large Files: We mitigated performance issues through careful memory management. For example, the code streams image files directly from the disk instead of loading everything into memory at once. It also uses temporary files at different processing stages rather than trying to do everything in memory.
  • Debugging & Error Handling: We’ve created a system that allows developers to examine the files at various processing stages and catch potential problems early on. This helps identify and address issues quickly. All errors and exceptions are carefully recorded, providing valuable information for troubleshooting and improving the system’s stability.
  • Cross-Compatibility between XPS Formats: We used a method that systematically replaces OpenXPS namespaces with their Microsoft XPS counterparts. This ensures that XPS files created from the OpenXPS standard can be processed by the Microsoft XPS APIs used in this project. Using string substitutions for these URI schemas is a simple but effective solution to ensure compatibility.
  • Concurrency & Multithreading: To prevent race conditions and ensure data integrity, we utilize a combination of events and thread-specific data structures. Events will signal between threads, triggering actions like stopping monitoring or resuming paused tasks. Thread-specific information, such as printer or job details, is stored in a dedicated structure, facilitating communication and coordination.
  • Printer & Job Notifications: We focused on efficiency and memory safety. The program tracks printer job status changes using Windows APIs. It effectively manages notifications, including those that might be discarded. The code ensures proper memory management by carefully allocating and freeing resources.

Testing & Quality Assurance

Comprehensive testing was necessary to make sure we delivered a fully functional, stable solution. We tested the library with many different combinations of devices, operating systems, printers, and file types. We verified compatibility with various file formats, including PDF, DOCX, TXT, JPG, XLSX, PNG, and HTML, as well as popular software applications like Adobe Acrobat, Microsoft Word, Excel, Notepad, Microsoft Photos, and different web browsers. We also experimented with different watermark customization options, such as using text, images, or QR codes as watermarks, and adjusting the size and placement of these watermarks.

We developed a dedicated test console application to help us thoroughly test and debug Printer Interceptor’s functionality. We ensured compatibility with various apps, watermark parameters, Windows configurations, and printer models.

Documentation and Support

We prepared detailed documentation to clearly explain the interceptor’s core features, functionality, and usage. A comprehensive guide was created to assist developers in building the interceptor from source code, ensuring flexibility and customization.

A key benefit of our approach was the elimination of vendor lock-in. By writing thorough documentation, we empowered our client to maintain full control over their solution. This flexibility ensured that they could continue developing and customizing the interceptor in-house. At the same time, Redwerk’s commitment doesn’t end at delivery. We offer ongoing support and maintenance to keep our clients’ solutions up and running.

Result

By partnering with Redwerk, BlueCloud Technologies significantly enhanced ScreenID, leading to higher customer satisfaction and retention. With Printer Interceptor seamlessly integrated, ScreenID can now intercept printing jobs, apply customizable watermarks (text or image), and precisely control watermark placement and formatting.
Designed to minimize performance overhead, Printer Interceptor ensures printing jobs aren’t noticeably delayed.

Redwerk’s collaboration resulted in a powerful screen watermarking solution, strengthening BlueCloud Technologies’ competitive edge and delivering significant value to high-profile customers like Vodafone, National Bank of Egypt, Commercial International Bank, and Credit Agricole Group.

Looking to extend the functionality of your product?

Let’s talk

Technologies

.NET.NET
C++
Reach FrameworkReach Framework
Presentation FrameworkPresentation Framework
Microsoft XPSMicrosoft XPS
8test devices
3Windows OS versions supported
50+enterprise users
100%within scope and budget
800image-rich pages watermarked under 2 mins
﹤10secs to process average files

Redwerk Team Comment

Dmytro

Dmytro
Developer & Team Lead

This project provided a fantastic opportunity to refine my skills in system-level programming, particularly in real-time monitoring and managing external hardware resources such as printers, XPS document workflows, and file conversion processes. Our team developed a robust library for printer job interception and monitoring. It effectively inserts watermarks, prevents unwanted jobs, and monitors printer status in real time.

The library’s standout feature is its ability to simultaneously monitor multiple printers while handling job interception and interaction. I find its capacity to modify documents before printing, such as adding watermarks, a true value-add.

Media
Media

Related in Blog

TOP 10 Digital Transformation Trends for 2024

TOP 10 Digital Transformation Trends for 2024

The previous year was a banger for digital transformation as companies finally adopted AI, chatbots, and robotic process automation to propel efficiency to unprecedented heights. This year takes it even further by offering trends in digital transformation that can apply to busi...

Read More
Code Review Checklist from Redwerk – All Steps Included

Code Review Checklist from Redwerk – All Steps Included

Ever wondered if your IT vendor did a good job and built a high-quality app? It’s easy to verify it with an independent code review. Code reviews conducted by external experts bring a fresh and unbiased perspective on your product’s quality. They scrutinize the code purely on mer...

Read More

Impressed?

Hire us

Other Case Studies

Current

Current

United States

Developed this 100% ADA compliant e-government SaaS which is used by welfare divisions across the US

MarketBee

MarketBee

New Zealand

Built from scratch market assessment software for aggregates producers across 12 countries

Recruit Media

Recruit Media

United States

Developed a patent-pending recruitment SaaS from the ground-up, which was later acquired by HireQuest