예제 #1
0
        public static void PostScriptEmitter(StringBuilder PSheader, PrintFile memoryfile, string psoutputfile,
            int xstart, int ystart, int linespacing, string frontul = "none", string backul = "none")
        {
            try
            {
                if (!File.Exists(psoutputfile))
                {
                    using (StreamWriter psout = File.CreateText(psoutputfile))
                    {
                        psout.WriteLine("%!PS-Mark-1.0");
                        if (frontul != "none")
                        {
                            // add underlay
                            if (File.Exists(frontul))
                            {
                                string fulbuffer = File.ReadAllText(frontul);
                                psout.Write(fulbuffer);
                            }
                        }
                        if (backul != "none")
                        {
                            // add underlay
                            if (File.Exists(backul))
                            {
                                string bulbuffer = File.ReadAllText(backul);
                                psout.Write(bulbuffer);
                            }
                        }
                        psout.WriteLine(PSheader);

                        foreach (Page page in memoryfile.Pages)
                        {
                            int ystartval = ystart;
                            foreach (StringBuilder line in page.Lines)
                            {
                                psout.WriteLine(String.Format("{0} {1} moveto", xstart, ystartval));
                                psout.WriteLine(String.Format("({0}) show", line));

                                ystartval = ystartval - linespacing;
                            }
                            // TODO if there are underlays put them in here
                            if (frontul != "none")
                            {
                                // add front underlay
                                psout.WriteLine(String.Format("save"));
                                psout.WriteLine(String.Format("  1 1 scale"));
                                psout.WriteLine(String.Format("  1 1 translate"));
                                psout.WriteLine(String.Format("FPForm execform"));
                                psout.WriteLine(String.Format("restore"));
                            }
                            if (backul != "none")
                            {
                                psout.WriteLine(String.Format("showpage"));
                                // add back underlay
                                psout.WriteLine(String.Format("save"));
                                psout.WriteLine(String.Format("  1 1 scale"));
                                psout.WriteLine(String.Format("  1 1 translate"));
                                psout.WriteLine(String.Format("BPForm execform"));
                                psout.WriteLine(String.Format("restore"));
                                psout.WriteLine(String.Format("showpage"));
                            }
                            else
                            {
                                psout.WriteLine(String.Format("showpage"));
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("File Exists !");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("There was an error : {0}", e);
            }
        }
예제 #2
0
        public static List<Page> StorePage(string infile, int[] linebreakchars, int[] pagebreakchars, int linecount)
        {
            int lastbyte = 0;
            int bytein = 0;
            int numlines = 0;

            var lines = new List<StringBuilder>();
            var linebuffer = new StringBuilder();

            var thispage = new Page();

            var pages = new List<Page>();
            var thisfile = new PrintFile();

            try
            {
                using (StreamReader reader = new StreamReader(infile))
                {
                    while (reader.EndOfStream != true)
                    {
                        bytein = reader.Read();

                        // while not the end of a page, build the lines on the page list

                        // Console.WriteLine("value of bytein HEX : {0:x2}  DEC : {1}  CHAR : {2}", bytein, bytein, (char) bytein);
                        // Console.WriteLine("value of bytein HEX : {0:x2}  DEC : {1}", bytein, bytein);

                        if (linecount == 0 && pagebreakchars != null) // we are not using line count
                        {
                            // is it the end of a line
                            if ((bytein == linebreakchars[0] && reader.Peek() == linebreakchars[1]) || (lastbyte != linebreakchars[0] && bytein == linebreakchars[1]))
                            {
                                lines.Add(linebuffer);

                                if (bytein == linebreakchars[0] && reader.Peek() == linebreakchars[1])
                                {
                                    // move past the 0x0D
                                    // bytein = reader.Read();
                                    // move past the 0x0A
                                    bytein = reader.Read();
                                }

                                // finalize the values of the stringbuffer
                                lastbyte = bytein;
                                linebuffer = new StringBuilder();
                            }

                            else if (bytein == pagebreakchars[0] && reader.Peek() == pagebreakchars[1])
                            {
                                thispage = new Page(lines);
                                pages.Add(thispage);
                                lines = new List<StringBuilder>();
                                bytein = reader.Read();
                                lastbyte = bytein;
                            }

                            // is not the end of a line or page, build linebuffer
                            else
                            {
                                linebuffer.Append((char)bytein);
                                lastbyte = bytein;
                            }
                        }
                        else // we are using linecount
                        {
                            if ((numlines < linecount) && (bytein == linebreakchars[0] && reader.Peek() == linebreakchars[1]) || (lastbyte != linebreakchars[0] && bytein == linebreakchars[1]))
                            {
                                lines.Add(linebuffer);
                                numlines++;

                                if (bytein == linebreakchars[0] && reader.Peek() == linebreakchars[1])
                                {
                                    // move past the 0x0D
                                    // bytein = reader.Read();
                                    // move past the 0x0A
                                    bytein = reader.Read();
                                }

                                // finalize the values of the stringbuffer
                                lastbyte = bytein;
                                linebuffer = new StringBuilder();

                                if (numlines == linecount)
                                {
                                    thispage = new Page(lines);
                                    pages.Add(thispage);
                                    lines = new List<StringBuilder>();
                                    numlines = 0;
                                }
                            }

                            else
                            {
                                linebuffer.Append((char)bytein);
                                lastbyte = bytein;
                            }
                        }
                    }

                    // did the file end in a 0C ? if so we don't want to add an extra page
                    // if it is not a 0C then the file ends otherwise, and we want one more page
                    lines.Add(linebuffer);
                    linebuffer = new StringBuilder();
                    thispage = new Page(lines);
                    pages.Add(thispage);
                    return pages;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error reading file : {0}", e.Message);
                return pages;
            }
        }
예제 #3
0
        public static void XMLEmitter(PrintFile memoryfile, string psoutputfile, string frontul = "none", string backul = "none")
        {
            try
            {
                string xmloutputfile = Path.ChangeExtension(psoutputfile, "xml"); ;

                if (!File.Exists(xmloutputfile))
                {
                    XmlWriterSettings xmloutsettings = new XmlWriterSettings();
                    xmloutsettings.Indent = true;
                    xmloutsettings.IndentChars = ("\t");
                    xmloutsettings.NewLineOnAttributes = true;
                    xmloutsettings.WriteEndDocumentOnClose = true;

                    using ( XmlWriter xmlout = XmlWriter.Create(xmloutputfile, xmloutsettings))
                    {
                        xmlout.WriteStartDocument();
                        xmlout.WriteStartElement("JobData");

                        if (frontul != "none")
                        {
                            // add underlay
                            // stored in xml as <![CDATA[datagoeshere]]>
                            if (File.Exists(frontul))
                            {
                                string fulbuffer = File.ReadAllText(frontul);
                                xmlout.WriteStartElement("frontul");
                                xmlout.WriteCData(fulbuffer);
                                xmlout.WriteEndElement();
                            }
                        }
                        if (backul != "none")
                        {
                            // add underlay
                            if (File.Exists(backul))
                            {
                                string bulbuffer = File.ReadAllText(backul);
                                xmlout.WriteStartElement("backul");
                                xmlout.WriteCData(bulbuffer);
                                xmlout.WriteEndElement();
                            }
                        }

                        foreach (Page page in memoryfile.Pages)
                        {
                            xmlout.WriteStartElement("page");
                            foreach (StringBuilder line in page.Lines)
                            {
                                xmlout.WriteElementString("line", line.ToString());
                            }
                            xmlout.WriteEndElement();
                        }
                    }
                }
                else
                {
                    Console.WriteLine("File Exists !");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("There was an error : {0}", e);
            }
        }
예제 #4
0
        public static void Main(string[] args)
        {
            if (args == null)
            {
                Console.WriteLine("usage : <command> <arg1 mainframe input filename> <arg2 postscript output filename> <optional pagesize>");
                Environment.Exit(1);
            }

            if (args.Length < 2)
            {
                Console.WriteLine("You need to provide an input and output filename");
                Environment.Exit(1);
            }

            // prep the Encapsulated PS files generated by Adobe (.eps)
            string fuleps = ConfigurationManager.AppSettings["fuleps"];
            string buleps = ConfigurationManager.AppSettings["buleps"];
            string fulps = ConfigurationManager.AppSettings["fulps"];
            string bulps = ConfigurationManager.AppSettings["bulps"];

            UnderLayPrep(fuleps, buleps, fulps, bulps);

            string InFile = args[0];
            string OutFile = args[1];
            int[] pagesize = { Convert.ToInt32(ConfigurationManager.AppSettings["xpoints"]), Convert.ToInt32(ConfigurationManager.AppSettings["ypoints"]) };
            string jobfont = ConfigurationManager.AppSettings["jobfont"];
            int jobfontsize = Convert.ToInt32(ConfigurationManager.AppSettings["jobfontsize"]);
            int linecount = Convert.ToInt32(ConfigurationManager.AppSettings["linecount"]);

            int[] linebreakchars = { Convert.ToInt32(ConfigurationManager.AppSettings["linechar0"], 16), Convert.ToInt32(ConfigurationManager.AppSettings["linechar1"], 16) };

            int[] pagebreakchars = new int[2];
            if (ConfigurationManager.AppSettings["pagechar0"] != "none" || ConfigurationManager.AppSettings["pagechar1"] != "none")
            {
                pagebreakchars[0] = Convert.ToInt32(ConfigurationManager.AppSettings["pagechar0"], 16);
                pagebreakchars[1] = Convert.ToInt32(ConfigurationManager.AppSettings["pagechar1"], 16);
            }

            PrintFile MemoryFile = new PrintFile(StorePage(InFile, linebreakchars, pagebreakchars, linecount));

            if (MemoryFile.Pages == null)
            {
                Console.WriteLine("File returned null, something went wrong");
                Environment.Exit(1);
            }

            StringBuilder PSHeader = PostScriptHeader(MemoryFile.Pages.Count, pagesize, jobfont, jobfontsize, Path.GetFileName(InFile), Path.GetFileName(OutFile));

            int xstart = Convert.ToInt32(ConfigurationManager.AppSettings["xstart"]);
            int ystart = Convert.ToInt32(ConfigurationManager.AppSettings["ystart"]);
            int linespacing = Convert.ToInt32(ConfigurationManager.AppSettings["linespacing"]);

            // underlay must be none if not in use
            PostScriptEmitter(PSHeader, MemoryFile, OutFile, xstart, ystart, linespacing, fulps, bulps);

            //optional output XML
            if(ConfigurationManager.AppSettings["outputXML"] == "YES")
            {
                XMLEmitter(MemoryFile, OutFile, fulps, bulps);
            }
        }