How to get plt file's printable area
来源:互联网 发布:淘宝真人公仔 编辑:程序博客网 时间:2024/05/17 07:17
Plt file is described by HPGL, which is the primary printer control language used by Hewlett-Packard plotters. Sometimes we want to get the printable area of a PLT file, how to do it?
My solution is to extract the coordinates in PLT file and find out the boundary rectangle.
Following is the sample code by C#:
string filename = @"C:/Documents/test.PLT";//make sure you have this file
StreamReader sr = new StreamReader(filename);
string input = sr.ReadToEnd(); sr.Close(); //use regular expression to extract the coordinates boundary
Regex reg = new Regex("PDPA[//d+,//d+]+;");
MatchCollection matches = reg.Matches(input);
// if following coordinates are divided by 400, the unit will be mm
int xMax = 0;
int xMin = 0;
int yMax = 0;
int yMin = 0;
//find out the coordinates boundary
foreach (Match m in matches) {
//remove 'PDPA'
string v = m.Value.Substring(4,m.Value.Length-5);
string[] coords = v.Split(',');
IEnumerable<string> xCoords = coords.Where((s, i) => i%2 == 0);
IEnumerable<string> yCoords = coords.Where((s, i) => i % 2 != 0);
int LocalXMax = xCoords.Max((s)=>Int32.Parse(s));
int LocalXMin = xCoords.Min((s) => Int32.Parse(s));
int LocalYMax = yCoords.Max((s) => Int32.Parse(s));
int LocalYMin = yCoords.Min((s) => Int32.Parse(s)); xMax = xMax >= LocalXMax ? xMax : LocalXMax; xMin = xMin <= LocalXMin ? xMin : LocalXMin; yMax = yMax >= LocalYMax ? yMax : LocalYMax; yMin = yMin <= LocalYMax ? yMin : LocalYMin; } //draw the boundary
string outFileName = filename + "out.plt";
string pt1 = "PA" + xMin +"," + yMin + ";";
string pt2 = "PA" + xMin + "," + yMax + ";";
string pt3 = "PA" + xMax + "," + yMax + ";";
string pt4 = "PA" + xMax + "," + yMin + ";";
string appendingText = pt1 + "PD;" + pt2 + pt3 + pt4 + pt1 + "PU;SP;PG1";
string text = input.Replace("PG1",appendingText);
StreamWriter sw = new StreamWriter(outFileName);
sw.Write(text); sw.Flush(); sw.Close();
- How to get plt file's printable area
- How to get the file's icon using C++ - 用C++如何获取文件的图标
- How to get file from classpath
- how to make&get trace file
- How to get new record's id
- How to Get Table’s Generated Ids
- how to test a file 's existence
- How to get the file's extend name in C++ - 在C++中如何获取文件的扩展名
- How-to launch browser print dialog when showing printable page
- How to get trace file from getbfno.sql gettrcname.sql
- How to get file extension from string in C++
- [cernRoot]How to get tree name from root file
- How to get file path in onActivityResult in Android 4.4
- How To get the usbdisk's drive letter properly
- [JNI] How to get the java's native method body?
- Android LruCache : how to put and get user's data
- How To Get Application Path,And How To Get The Path's Directory,File Name,And Type Info(如何得到运行程序的路径,以及如何得到路径的文件夹,文件名,以及类型等等信息)
- How to generate dot file from IDA's GDL format
- C#处理跨进程copy
- JAVA之——List,Set,Map
- RPG游戏引擎的设计原理
- Intermediate Language 及Just In Time
- Win7中的PB中文乱码问题!
- How to get plt file's printable area
- 数据结构——如何定义与建立
- 无限级树算法(递归)
- I Think I Need a Houseboat
- 把握现在,畅享人生!
- PL/SQL Developer如何支持多个Oracle安装
- ffmpeg API 笔记:使用libavcodec/libavformat/libswscale
- classification of net 'mid-box'
- CLR