1. Problem Statement and Functional Goal
On a single-machine monitoring installation based on Siemens WinCC Flexible 2005 Advanced SP1 + HF7 running on Windows XP Professional, the existing PrintScreen system function already pushes the currently selected area of a process trend to the default Windows printer. The functional requirement extends this: capture a trend view automatically, render it as a PDF, and persist the file to a fixed location (local hard drive or attached USB mass-storage) without any operator interaction and without granting the operator a generic Windows shell or file-explorer session.
Two field-validated solutions exist for this scenario and both keep the operator inside the WinCC Flexible runtime:
- Method A — Printer-Driver Redirect: install a virtual PDF printer (for example, PDF Creator) as the default Windows printer, drive the PrintScreen system function from a tag-triggered subroutine, and let the printer driver write the file with an auto-generated name.
- Method B — BMP-to-PDF VB Class: capture the trend view as a .BMP image using the PrintScreen function, then convert that bitmap into a single-page PDF using a VB class instantiated from inside the WinCC Flexible script environment.
Method A is the smaller code path. Method B keeps the PDF writer logic inside WinCC Flexible itself, which avoids re-installing or re-binding a printer driver per panel PC.
2. Environment and Prerequisites
| Component | Specification / Version | Notes |
|---|---|---|
| Engineering system | WinCC Flexible 2005 Advanced SP1 + HF7 | Hotfix HF7 resolves several VB Script runtime issues from the SP1 release |
| Runtime target | Windows XP Professional SP3 | Single-machine / panel PC, no client/server split |
| License | WinCC Flexible 2005 Advanced (RT) | Standard or higher — "Compact" does not support VB Script |
| Trend object | Trend View with configured archive tags | Archive backing required if historical depth is needed |
| Storage target | Local NTFS volume or mapped USB drive | Folder must exist before runtime starts |
| Method A only | PDF Creator virtual printer (current 1.x line for XP) | Install once, set as default printer on the panel PC |
| Method B only | VB class library registered on the panel PC | Custom-built wrapper; no Windows API surface exposed to the operator |
Confirm the runtime version on the panel PC by reading the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Siemens\WinCC Flexible\Runtime\Version; the value should report the build corresponding to SP1 + HF7 before any scripting changes are deployed.
3. Architecture and Data Flow
The same logical flow applies to either method. The trend view is rendered on screen, the PrintScreen system function emits the pixels, and a downstream component writes the PDF.
+----------------+ +-----------------+ +-------------------+
| Trigger Tag |---->| Subroutine on |---->| PrintScreen() |
| (bool, edge) | | tag-change | | system function |
+----------------+ +-----------------+ +---------+---------+
|
v
+---------------------------+
| Method A: PDF Creator |
| Method B: VB PDF class |
+-------------+-------------+
|
v
+--------------------+
| C:\Trends\PDF\ |
| or E:\ (USB) |
+--------------------+
The button on the HMI does not call PrintScreen directly. The button only sets a boolean tag. The tag change is the event source. This indirection is what allows the script to run inside the WinCC Flexible runtime scheduler instead of from the button-click handler, which avoids blocking the UI thread during the PDF write.
4. Method A — PDF Creator (Printer-Driver Redirect)
4.1 Install and configure the virtual printer
- Install PDF Creator on the panel PC as an administrator.
- Open Printers and Faxes, right-click PDFCreator, and choose Set as Default Printer.
- Open PDFCreator Options > Auto-save, enable the auto-save profile, and set the output folder (for example
C:\Trends\PDF\) plus the filename pattern. A usable token-based pattern that produces unique, sortable names:\li>
Trend_<COMPUTERNAME>_<DATE>_<TIME>.pdf
- In the same dialog, set After saving: open document = OFF and Show progress dialog = OFF so no UI surfaces to the operator.
- Apply and close the printer properties.
4.2 WinCC Flexible configuration
- Create an internal tag
PDF_Triggerof typeBool, initial value0, length 1 bit. - Create the subroutine below in the project Scripts area (VBScript):
' WinCC Flexible VBScript — Method A
Sub PDF_Trend(tag_name, tag_value)
If tag_value = False Then Exit Sub
' Select the trend view that should be captured.
' ChangeScreenWithNumber references the screen by its process ID.
ChangeScreenWithNumber 11, , , , , , , , ,
' Small delay to let the trend redraw before the snapshot.
Wait 500
' PrintScreen(Printername, Mode, Area)
' Mode 1 = print current screen content to the default printer (PDFCreator).
PrintScreen "PDFCreator", 1, 0
' Reset the trigger so the next rising edge fires the routine again.
SmartTags("PDF_Trigger") = False
End Sub
- Wire the tag change event: select
PDF_Triggerin the project tree, open Properties > Events > Change Value, and bind it to thePDF_Trendsubroutine. - Place a button on any screen and configure its Press event with the single line:
SmartTags("PDF_Trigger") = True
The flow becomes: operator presses the button, the boolean flips to True, the tag-change event calls PDF_Trend, the screen containing the trend is activated, the PrintScreen system function routes the bitmap through PDFCreator, and the file is written to C:\Trends\PDF\ with the configured name pattern.
ChangeScreenWithNumber call before the screenshot is mandatory unless the operator is already on the trend view when pressing the button.
5. Method B — VB Class with BMP-to-PDF Conversion
Method B is preferred where the customer policy prohibits third-party printer drivers on the runtime PC or where the PDF must carry project-specific metadata (logo, batch header, footer with operator name) that a generic printer driver cannot inject.
5.1 Build the helper class
Outside of WinCC Flexible, build a COM-visible VB6 (or .NET COM-interop) DLL called, for example, TrendPDF.dll, that exposes the single function:
' Public surface of TrendPDF.cls
Public Function BMPtoPDF(sBMPPath As String, sPDFPath As String, _
sTitle As String, sFooter As String) As Boolean
' 1. Load BMP into memory.
' 2. Compose a single-page PDF with the BMP as a full-bleed image.
' 3. Inject Title (PDF metadata) and Footer (text annotation).
' 4. Write file to sPDFPath. No UI, no dialog.
' 5. Return True on success.
End Function
Register the DLL with regsvr32 TrendPDF.dll on the panel PC.
5.2 WinCC Flexible subroutine
' WinCC Flexible VBScript — Method B
Const BMP_FOLDER = "C:\Trends\BMP\"
Const PDF_FOLDER = "C:\Trends\PDF\"
Sub PDF_Trend_Class(tag_name, tag_value)
If tag_value = False Then Exit Sub
Dim sBMP, sPDF, sName
sName = "Trend_" & Year(Now) & Right("0" & Month(Now),2) _
& Right("0" & Day(Now),2) & "_" _
& Right("0" & Hour(Now),2) _
& Right("0" & Minute(Now),2) _
& Right("0" & Second(Now),2)
sBMP = BMP_FOLDER & sName & ".bmp"
sPDF = PDF_FOLDER & sName & ".pdf"
' Force redraw of the trend view.
ChangeScreenWithNumber 11
Wait 500
' Redirect the printer output to a file by routing to a
' "Microsoft Print to PDF" or a local file printer driver that
' accepts a path argument — or use the WinCC Flexible PrintScreen
' to a BMP-only file printer first, then run the class below.
PrintScreen "BMP_Printer", 1, 0
' Invoke the registered COM class.
Dim oPDF
Set oPDF = CreateObject("TrendPDF.BMPtoPDF")
If oPDF.BMPtoPDF(sBMP, sPDF, "Process Trend Export", _
"Operator: HMI") Then
' Optional: delete the intermediate BMP.
' Kill sBMP
End If
Set oPDF = Nothing
SmartTags("PDF_Trigger") = False
End Sub
The class eliminates the need for a system-wide PDF printer driver and lets the project team put the title, footer, and file naming convention under full source control.
6. Automatic Filename Convention
Both methods converge on the same output naming convention. The pattern below produces sortable, collision-free file names using local system time:
| Token | Sample output | Purpose |
|---|---|---|
YYYYMMDD_HHMMSS |
Trend_20240115_142307.pdf |
Chronological sort in Windows Explorer |
Trend_<Computer> |
Trend_PanelPC01_... |
Disambiguate multi-panel sites |
TagValue_Suffix |
Trend_TempA_20240115_142307.pdf |
When the button is per-trend |
Keep the filename ASCII-only. Some legacy PDF readers used in regulated industries refuse Unicode file names. Time zone offsets, when added, must follow ISO 8601 to avoid ambiguity in the audit trail.
7. Storage Targets and Operator Restrictions
Three storage patterns are acceptable in this scenario:
-
Internal fixed volume:
C:\Trends\PDF\. Create the folder during panel PC image deployment. NTFS permissions: deny Users on delete, allow Users on write. Operator cannot delete or rename exports. -
USB mass storage: the drive letter is volatile (typically
E:\orF:\). Probe the drive withDir("E:\", vbDirectory)before writing; if missing, fall back to the local volume and write a warning tag. - Network share: acceptable only if the customer accepts the operator's runtime user having write access to the share. In the typical regulated scenario this is excluded.
PDF_LastPath of type String that stores the absolute file path of the most recent export. The HMI can display this value on a status screen so the operator always knows where the latest file was written — without exposing a file browser.
8. Trigger Pattern: Why a Tag, not the Button Directly
The community discussion emphasizes that a tag-change trigger is preferred over binding the script directly to the button-press event for three reasons:
-
Debouncing: the button can fire on a noisy contact; the tag routine resets itself to
Falseat the end, guaranteeing one PDF per rising edge. - Re-entrancy: the WinCC Flexible runtime serializes tag-change events on the same tag, avoiding two concurrent PrintScreen calls.
- External trigger sources: the same tag can be flipped by a recipe-end, an alarm, or a scheduler — the export logic stays in one place.
Trigger sources --------------- HMI button ----+ Recipe end ----+----> [PDF_Trigger : Bool] ----> PDF_Trend() Alarm "Batch OK" ----+ Scheduler ----+
9. Verification Procedure
- Open the project in the WinCC Flexible 2005 Advanced SP1 + HF7 engineering station and start the runtime simulator with the project.
- Navigate to the trend screen, then press the export button.
- Confirm the
PDF_Triggertag toggles toTrueand back toFalsewithin one second (visible in the tag simulator). - Inspect the configured output folder. A new PDF file with the timestamp-based name should appear within 2–4 seconds.
- Open the PDF and verify the trend curve, axes, legend, and current time stamp.
- Repeat 10 times in rapid succession. Verify that exactly 10 distinct files are written and no filenames collide.
- Remove the USB drive while running. Verify the routine falls back to the local volume or logs an error tag.
- Open a Windows Explorer session as the operator user and confirm that the export folder is accessible in write-only mode (no delete, no rename).
10. Troubleshooting Matrix
| Symptom | Likely cause | Diagnostic | Resolution |
|---|---|---|---|
| No PDF appears; no error tag | Trigger tag never reached True
|
Cross-reference the tag in the tag simulator | Verify the button event writes SmartTags("PDF_Trigger") = True
|
| PDF appears but is blank | Wrong active screen at PrintScreen time | Add a debug tag set right before PrintScreen that writes the active screen number | Insert explicit ChangeScreenWithNumber before PrintScreen
|
| PDF prints to paper instead of disk | Default printer is not the virtual PDF printer | Open Printers and Faxes on the runtime PC | Set PDFCreator (or equivalent) as default |
| File name collides, second export overwrites first | Filename pattern has second resolution but no milliseconds | List files in target folder with millisecond precision | Add Timer-based millisecond token or append a sequence counter |
Method B: CreateObject fails with error 429 |
DLL not registered, or registered under wrong user | Run regsvr32 /i TrendPDF.dll as administrator |
Re-register and verify the CLSID in HKEY_CLASSES_ROOT\TrendPDF.BMPtoPDF
|
| Operator can delete exported PDFs | NTFS ACLs allow Users: Modify | Run icacls "C:\Trends\PDF"
|
Set Users: Write only, deny Delete and Delete subfolders and files |
| Trend view captures only part of the curve | Trend is scrolled horizontally; visible window does not match archive range | Trigger from a recipe-end event instead of a button when the archive is at rest | Reset trend zoom to "all" before capture |
HF7 missing, VBScript crashes on Wait
|
Hotfix not applied | Read registry version, compare to SP1 build number | Install HF7 (or later cumulative hotfix) and redeploy |
11. Field Constraints and Documented Limitations
- The PrintScreen system function captures pixels, not vector data. Resampled curves may look pixelated in the exported PDF when the source resolution is low. Always run the panel PC at its native resolution.
- Method A couples the export pipeline to the Windows print spooler. A stalled spooler stops exports even if the rest of the runtime is healthy. Monitor
Spoolerservice status from a WinCC Flexible script if uptime matters. - Method B requires the COM helper DLL to remain registered. Patch cycles that reimage the panel PC must include the DLL registration step.
- WinCC Flexible 2005 reaches end of life; long-term support projects should plan a migration path to TIA Portal WinCC Comfort/Advanced before scripting APIs drift. The pattern (button → trigger tag → subroutine → file write) is portable, but the specific
PrintScreenAPI surface differs in TIA Portal V16 and later. - Trend archive depth is bounded by the configured ring buffer. Exports taken outside the buffered window show gaps. Configure the archive size to match the longest expected "look-back" before exporting.
12. Related Patterns Worth Keeping in the Toolbox
Once the export path works for PDF, the same trigger tag and subroutine pattern is reused for:
- CSV export of the underlying archive using the WinCC Flexible archive export API combined with the trend's data source.
- Audit-log stamping: write a one-line entry to a fixed
.logfile each time a PDF is written, with operator ID, trend name, and timestamp. - Multi-trend consolidation: capture several trend views into a single multi-page PDF by extending the helper class to accept an array of BMPs and emit a page per element.
Can I export a WinCC Flexible trend to PDF without installing a third-party printer driver?
Yes. Use Method B: capture the trend view with the PrintScreen system function, route the bitmap to a file-only printer (or BMP-only output path), then convert the BMP to PDF inside a COM helper DLL called from the WinCC Flexible VBScript. No system-wide printer driver is required.
Why is the button not bound directly to the export script?
Binding the script to a tag-change event (a boolean trigger tag flipped by the button) guarantees single execution per rising edge, allows external sources (alarms, recipes, schedulers) to reuse the same routine, and serializes calls inside the runtime scheduler so two prints never overlap.
How do I prevent the operator from deleting exported PDFs?
Set NTFS permissions on the export folder to allow Users: Create Files / Write Data only and explicitly deny Delete and Delete Subfolders and Files. Verify with icacls on the panel PC after deployment.
What filename pattern gives sortable, unique PDF names?
Use the system time formatted as YYYYMMDD_HHMMSS, optionally prefixed with the panel PC name and the trend tag name. For example Trend_PanelPC01_TempA_20240115_142307.pdf. Add milliseconds or a sequence counter if sub-second bursts are possible.
Does this pattern survive a migration from WinCC Flexible 2005 to TIA Portal WinCC?
The architectural pattern (button → trigger tag → subroutine → file write) transfers cleanly, but the specific PrintScreen system function and SmartTags collection are replaced by TIA Portal equivalents. Plan a re-implementation pass during any migration; do not assume a 1:1 script port.