how to strip print control codes (PCL type) from a document using a regular expression in C#
-
Thursday, September 13, 2012 4:54 PMI have an archive of PCL files. I would like to make a console app that would read a file, strip out all print control codes, and write the codes to a separate file, leaving the rest of the document in tack. I think I can do this with a regex(), but I'm not sure how to approach the task. My language of choice is C#. Any advice you can provide will be greatly appreciated.
Markmark larsen
All Replies
-
Friday, September 14, 2012 5:55 AM
Interesting task, do you have some samples?
Maybe this can help you:
http://openpcl.sourceforge.net/
I've also found this guide https://support.transfrm.com/attachments/token/ontu8wag731xpbi/?name=PCL.pdf over here
-
Friday, September 14, 2012 8:24 PM
sample:
(s0s0B&d@&k10.000H
DICT D&T: 02/15/11 1229 TRANS D&T: 02/18/11 2004 BY: CJR (s0s0B&d@&k10.000H
(s0s0B&d@&k10.000H
(s0s0B&d@&k10.000H
(s0s0B&d@&k10.000H
(s0s0B&d@&k10.000H
Run: 02/22/11-12:27 by DOE,JANE A(s0s0B&d@&k10.000H
(s0s0B&d@&k10.000H
PT PROGRESS NOTES - Additional copy Page 1 of 1(s0s0B&d@&k10.000H(8U(s0p12h10v3T)10U)s0p12h10v3T(s0s0B&d@&k10.000HI can now strip out the codes using
publicstaticstring RemoveBetween(string s, char begin, char end) { Regex regex = newRegex(string.Format("\\{0}.*?{1}", begin, end)); return regex.Replace(s, string.Empty); }
I try to capture the codes by callingpublicstaticstring[] getPclCodes(string line) { string pattern = "\\x1B.*?H"; string[] pclCodes = Regex.Split(line, pattern); return pclCodes; }
before RemoveBetween(), but the strings that should have commands in them appear to be empty.
mark larsen
- Edited by marklarsen85 Friday, September 14, 2012 8:25 PM
- Marked As Answer by marklarsen85 Tuesday, September 18, 2012 12:45 PM
-
Tuesday, September 18, 2012 11:20 AMModerator
Hi Mark,
Welcome to the MSDN Forum.
What kind of string do you want to get?
Thank you.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
Tuesday, September 18, 2012 12:42 PMI am looking to write 2 documents from each PCL file. One with just the document text, and the other with just the document print commands. I have a working output for the text document, but when I split each line into substrings, only the document text shows up. the regex.Split returns the proper amount of strings, but the strings that should contain the PCL codes are empty strings.
mark larsen
-
Tuesday, September 18, 2012 12:44 PM
My main question is how to remove the codes. I have solved that problem. My current issue is how to save those removed codes to another file.
mark larsen

