Ejemplo n.º 1
0
        /// <summary>
        /// Draws the next page
        /// </summary>
        public void NextPage()
        {
            int increment = 1;
            int request   = 1;

            FOldPage = -1;
            if (AutoScale == AutoScaleType.EntirePage)
            {
                increment = FPagesDrawn;
                request   = FPage + increment + FEntirePageCount - 1;
            }
            else
            {
                request = FPage + increment;
            }
            if (FMetaFile != null)
            {
                FMetaFile.RequestPage(request);
                if ((FPage + increment) < FMetaFile.Pages.CurrentCount)
                {
                    Page = FPage + increment;
                }
                else
                {
                    if (FPage != (FMetaFile.Pages.CurrentCount - FPagesDrawn))
                    {
                        Page = FMetaFile.Pages.CurrentCount - 1;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void pd_QueryPageSettingsEvent(object sender, QueryPageSettingsEventArgs e)
        {
            doprint = true;
            if (FMeta.Finished)
            {
//				if (doc.PrinterSettings.ToPage > FMeta.Pages.CurrentCount)
            }
            //   throw new Exception("Imprimiendo por: " + e.PageSettings.PrinterSettings.PrinterName);
            while ((FCurrentPage + 1) < doc.PrinterSettings.FromPage)
            {
                FCurrentPage++;
            }
            UpdateHardMargins();
            if ((FCurrentPage + 1) > doc.PrinterSettings.ToPage)
            {
                doprint = false;
            }
            if (doprint)
            {
                FMeta.RequestPage(FCurrentPage + 1);
                if (FMeta.Pages.CurrentCount > FCurrentPage)
                {
                    FPrintPage = FCurrentPage;
                    MetaPage apage = (MetaPage)FMeta.Pages[FCurrentPage];

                    if (apage.UpdatedPageSize)
                    {
                        // Check for page size
                        int nwidth  = apage.PhysicWidth;
                        int nheight = apage.PhysicHeight;
                        if (FMeta.Orientation == OrientationType.Landscape)
                        {
                            nwidth  = apage.PhysicHeight;
                            nheight = apage.PhysicWidth;
                        }
                        e.PageSettings.PaperSize = FindPaperSize(apage.PageDetail.Index, nwidth, nheight);
                        if (apage.Orientation == OrientationType.Default)
                        {
                            e.PageSettings.Landscape = doc.DefaultPageSettings.Landscape;
                        }
                        else
                        if (apage.Orientation == OrientationType.Landscape)
                        {
                            e.PageSettings.Landscape = true;
                        }
                        else
                        {
                            e.PageSettings.Landscape = false;
                        }
                    }
                    else
                    {
                        e.PageSettings = doc.DefaultPageSettings;
                    }
                }
            }
            docancel = false;
            FCurrentPage++;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generate the PDF file in a single pass
        /// </summary>
        /// <param name="meta"></param>
        override public bool Print(MetaFile meta)
        {
            bool aresult      = base.Print(meta);
            int  FCurrentPage = FromPage - 1;

            meta.RequestPage(FCurrentPage);
            if (meta.Pages.CurrentCount < FromPage)
            {
                return(false);
            }
            SetPageSize(meta.Pages[0].PageDetail);
            SetOrientation(meta.Orientation);
            MetaPage apage;

            while (meta.Pages.CurrentCount > FCurrentPage)
            {
                apage = meta.Pages[FCurrentPage];
                if (apage.PageDetail.Custom)
                {
                    SetPageSize(apage.PageDetail);
                }
                if (FCurrentPage >= FromPage)
                {
                    NewPage(meta, apage);
                }
                DrawPage(meta, apage);
                FCurrentPage++;
                if (FCurrentPage > (ToPage - 1))
                {
                    break;
                }
                meta.RequestPage(FCurrentPage);
            }
            EndDocument(meta);
            return(aresult);
        }
Ejemplo n.º 4
0
        protected override void RenderContents(HtmlTextWriter output)
        {
            if (DesignMode)
            {
                base.RenderContents(output);
                return;
            }
            Bitmap bm;
            // Execute the report and save the memory stream and
            // the mimetype on cache
            string cacheid = GetCacheId();
            // Check if there is a metafile
            MetaFile meta = GetMetaFile();

            Monitor.Enter(meta);
            try
            {
                PrintOutNet prdriver = (PrintOutNet)Page.Cache[cacheid + "PrintOut"];
                if (prdriver == null)
                {
                    prdriver = new PrintOutNet();
                }

                if (meta != null)
                {
                    int pagenum = CurrentPage;
                    meta.RequestPage(pagenum);
                    if (meta.Pages.CurrentCount <= pagenum)
                    {
                        pagenum = meta.Pages.CurrentCount - 1;
                        Page.Cache.Insert(cacheid + "LastPage", pagenum, null,
                                          DateTime.Now.AddMinutes(30), TimeSpan.Zero);
                    }
                    else
                    {
                        Page.Cache.Remove(cacheid + "LastPage");
                    }
                    if (pagenum < meta.Pages.CurrentCount)
                    {
                        System.Drawing.Imaging.Metafile metaf;
                        MetaPage metap = meta.Pages[pagenum];
                        if (metap.WindowsMetafile == null)
                        {
                            bm = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
                            prdriver.Output = bm;
                            prdriver.DrawPage(meta, metap);
                            metaf = metap.WindowsMetafile;
                            if (metaf == null)
                            {
                                throw new Exception("No se pudo crear el metafile");
                            }
                        }
                        else
                        {
                            metaf = metap.WindowsMetafile;
                        }
                        string       mimetype;
                        MemoryStream mems = new MemoryStream();
                        try
                        {
                            switch (Format)
                            {
                            case "WMF":
                                GraphicUtils.WriteWindowsMetaFile(metaf,
                                                                  mems, PreviewScale / metap.WindowsMetafileScale);
                                mimetype = "application/x-msMetafile";
                                break;

                            default:
                                GraphicUtils.WriteWindowsMetaFileCodec(metaf,
                                                                       mems, PreviewScale / metap.WindowsMetafileScale,
                                                                       Format, out mimetype);
                                break;
                            }
                            Page.Cache.Insert(cacheid + "mimetype", mimetype, null,
                                              DateTime.Now.AddMinutes(10), TimeSpan.Zero);
                            Page.Cache.Insert(cacheid + "memstream", mems, null,
                                              DateTime.Now.AddMinutes(10), TimeSpan.Zero);
                        }
                        catch
                        {
                            mems.Dispose();
                            throw;
                        }
                    }
                }
            }
            finally
            {
                Monitor.Exit(meta);
            }
            base.RenderContents(output);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Generate the excel file
        /// </summary>
        /// <param name="meta"></param>
        override public bool Print(MetaFile meta)
        {
            npage   = 0;
            nrecord = 0;
            nmeta   = meta;
            mmfirst = System.DateTime.Now;
            bool aresult   = base.Print(meta);
            int  PageLimit = ToPage - 1;
            int  FirstPage = FromPage - 1;
            Type objClassType;

            objClassType = Type.GetTypeFromProgID("Excel.Application");
            object excel = Activator.CreateInstance(objClassType);

            object[] param1 = new object[1];
            object   wbs    = excel.GetType().InvokeMember("Workbooks",
                                                           System.Reflection.BindingFlags.GetProperty, null, excel, null);
            object wb = wbs.GetType().InvokeMember("Add",
                                                   System.Reflection.BindingFlags.InvokeMethod, null, wbs, null);
            int    shcount = 1;
            object shs     = wb.GetType().InvokeMember("Sheets",
                                                       System.Reflection.BindingFlags.GetProperty, null, wb, null);

            param1[0] = 1;
            object sh = shs.GetType().InvokeMember("Item",
                                                   System.Reflection.BindingFlags.GetProperty, null, shs, param1);
            object cells = sh.GetType().InvokeMember("Cells",
                                                     System.Reflection.BindingFlags.GetProperty, null, sh, null);
            object shfont = cells.GetType().InvokeMember("Font",
                                                         System.Reflection.BindingFlags.GetProperty, null, cells, null);
            string FontName = System.Convert.ToString(shfont.GetType().InvokeMember("Name",
                                                                                    System.Reflection.BindingFlags.GetProperty, null, shfont, null));
            int FontSize = System.Convert.ToInt32(shfont.GetType().InvokeMember("Size",
                                                                                System.Reflection.BindingFlags.GetProperty, null, shfont, null));


            int FCurrentPage = FirstPage;

            meta.RequestPage(int.MaxValue - 1);
            if (meta.Pages.CurrentCount <= FirstPage)
            {
                return(false);
            }
            if (ToPage > (meta.Pages.CurrentCount - 1))
            {
                PageLimit = meta.Pages.CurrentCount - 1;
            }
            SetPageSize(meta.Pages[0].PageDetail);
            SetOrientation(meta.Orientation);
            int dpix = GraphicUtils.DefaultDPI;
            int dpiy = dpix;

            SortedList columns = new SortedList();
            SortedList rows    = new SortedList();
            MetaPage   apage;
            int        i, index;

            // First pass to determine columns
            for (i = FirstPage; i <= PageLimit; i++)
            {
                apage = meta.Pages[i];

                foreach (MetaObject obj1 in apage.Objects)
                {
                    if ((obj1.MetaType == MetaObjectType.Text) || (obj1.MetaType == MetaObjectType.Image))
                    {
                        string leftstring = ((double)obj1.Left / Precision).ToString("0000000000");
                        index = columns.IndexOfKey(leftstring);
                        if (index < 0)
                        {
                            columns.Add(leftstring, null);
                        }
                    }
                }
            }
            int rowinit = 0;

            // Second pass determine rows
            for (i = FirstPage; i <= PageLimit; i++)
            {
                npage = i;
                if (!OneSheet)
                {
                    rowinit = 0;
                    int shcountactual = System.Convert.ToInt32(shs.GetType().InvokeMember("Count",
                                                                                          System.Reflection.BindingFlags.GetProperty, null, shs, null));
                    if (shcountactual < shcount)
                    {
                        param1[0] = shcountactual;
                        object lastsh = shs.GetType().InvokeMember("Item",
                                                                   System.Reflection.BindingFlags.GetProperty, null, shs, param1);

                        object[] param4 = new object[4];
                        param4[0] = DBNull.Value;
                        param4[1] = lastsh;
                        param4[2] = 1;
                        param4[3] = DBNull.Value;
                        sh        = shs.GetType().InvokeMember("Add",
                                                               System.Reflection.BindingFlags.InvokeMethod, null, shs, param4);
                    }
                    else
                    {
                        param1[0] = shcount;
                        sh        = shs.GetType().InvokeMember("Item",
                                                               System.Reflection.BindingFlags.GetProperty, null, shs, param1);
                    }
                }
                else
                {
                    rowinit = rowinit + rows.Count;
                }

                shcount++;
                rows.Clear();

                apage = meta.Pages[i];
                // Calculate rows
                nrecord = 0;
                foreach (MetaObject obj2 in apage.Objects)
                {
                    if ((obj2.MetaType == MetaObjectType.Text) || (obj2.MetaType == MetaObjectType.Image))
                    {
                        string topstring = ((double)obj2.Top / Precision).ToString("0000000000");
                        index = rows.IndexOfKey(topstring);
                        if (index < 0)
                        {
                            rows.Add(topstring, null);
                        }
                    }
                }
                // Finally, draw objects
                foreach (MetaObject obj in apage.Objects)
                {
                    if ((obj.MetaType == MetaObjectType.Text) || (obj.MetaType == MetaObjectType.Image))
                    {
                        PrintObject(sh, apage, obj, dpix, dpiy,
                                    rows, columns, FontName, FontSize, rowinit, Precision);
                    }
                    nrecord++;
                    CheckProgress(false);
                }
            }
            EndDocument(meta);
            CheckProgress(true);


            if (FileName.Length > 0)
            {
                object[] paramssav = null;
                if (!CheckVersion2010Up(excel))
                {
                    paramssav = new object[1];
                }
                else
                {
                    paramssav = new object[2];
                    // Excel 97 format
                    ExcelFileFormat nformat = ExcelFormat;
                    if (nformat == ExcelFileFormat.Auto)
                    {
                        nformat = FileFormatFromFilename(FileName);
                    }
                    paramssav[1] = (int)nformat;
                }
                paramssav[0] = FileName;
                // If xlsx extension, force WorkBookNormal
                wb.GetType().InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, wb, paramssav);
            }
            if (!Visible)
            {
                object[] paramclose = new object[1];
                paramclose[0] = false;
                wb.GetType().InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, wb, paramclose);

                excel.GetType().InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, excel, null);
                excel = null;
                wb    = null;
                shs   = null;
                sh    = null;
            }
            else
            {
                param1[0] = Visible;
                excel.GetType().InvokeMember("Visible", System.Reflection.BindingFlags.SetProperty,
                                             null, excel, param1);
            }
            return(aresult);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Assign events to the PrintDocument and assign page settings
        /// </summary>
        override public bool PreparePrint(MetaFile meta)
        {
            FBlackLines   = 0;
            FWhiteLines   = 0;
            FPagesPrinted = 0;

            if (overridedriver != null)
            {
                if (!overridedriver.PreparePrint(meta))
                {
                    return(false);
                }
            }
            else
            {
                if (!base.PreparePrint(meta))
                {
                    return(false);
                }
            }

            if (doc == null)
            {
                doc = new PrintDocument();
            }
            InitPrinter(meta);

            if (!DisableForwardOnly)
            {
                meta.ForwardOnly = true;
            }
            PRINTOUT_MAX_PAGES = 32000;
            if (ToPage > 32000)
            {
                ToPage = 32000;
            }
            FCurrentPage      = 0;
            FCurrentPrintPage = 0;
            FMeta             = meta;
            meta.RequestPage(0);
            if (assigneddoc != doc)
            {
                doc.BeginPrint        += new PrintEventHandler(pd_BeginPrint);
                doc.PrintPage         += new PrintPageEventHandler(pd_PrintPage);
                doc.QueryPageSettings += new QueryPageSettingsEventHandler(pd_QueryPageSettingsEvent);
                assigneddoc            = doc;
            }
            if ((FMeta.Finished) && (FromPage > FMeta.Pages.CurrentCount))
            {
                doc.PrinterSettings.FromPage = FMeta.Pages.CurrentCount;
            }
            else
            {
                doc.PrinterSettings.FromPage = FromPage;
            }
            if ((FMeta.Finished) && (ToPage > FMeta.Pages.CurrentCount))
            {
                doc.PrinterSettings.ToPage = FMeta.Pages.CurrentCount;
            }
            else
            {
                doc.PrinterSettings.ToPage = ToPage;
            }
            doc.PrinterSettings.MinimumPage = 1;
            if (FMeta.Finished)
            {
                doc.PrinterSettings.MaximumPage = FMeta.Pages.CurrentCount;
            }
            else
            {
                doc.PrinterSettings.MaximumPage = MetaFile.MAX_NUMBER_PAGES;
            }
            doc.PrinterSettings.Collate = FMeta.CollateCopies;
            if (FMeta.Pages.Count > 0)
            {
                if (FMeta.Pages[0].PageDetail.PaperSource != 0)
                {
                    //PaperSource psource = new PaperSource();
                    //psource.RawKind = FMeta.Pages[0].PageDetail.PaperSource;
                    // Not working
                    //doc.PrinterSettings.DefaultPageSettings.PaperSource = psource;


                    foreach (PaperSource psource in doc.PrinterSettings.PaperSources)
                    {
                        if (psource.RawKind == FMeta.PaperSource)
                        {
                            doc.PrinterSettings.DefaultPageSettings.PaperSource = psource;
                            BrowsePaperSizes = true;
                            break;
                        }
                    }
                }
            }
            int nwidth  = meta.CustomX;
            int nheight = meta.CustomY;

            if (meta.Orientation == OrientationType.Landscape)
            {
                nwidth  = meta.CustomY;
                nheight = meta.CustomX;
            }
            PaperSize npapersize = FindPaperSize(meta.PageSizeIndex, nwidth, nheight);

            doc.PrinterSettings.DefaultPageSettings.PaperSize = npapersize;
            doc.DefaultPageSettings.PaperSize = npapersize;

#if REPMAN_MONO
#else
            doc.PrinterSettings.Duplex = DuplexIntToDuplex(FMeta.Duplex);
#endif
            if (FMeta.Orientation != OrientationType.Default)
            {
                doc.DefaultPageSettings.Landscape = (FMeta.Orientation == OrientationType.Landscape);
            }
            else
            {
                doc.DefaultPageSettings.Landscape = false;
            }
            if (Copies > 0)
            {
                doc.PrinterSettings.Copies = (short)Copies;
            }
            else
            {
                if (FMeta.Copies > 0)
                {
                    doc.PrinterSettings.Copies = (short)FMeta.Copies;
                }
            }
            return(true);
        }
Ejemplo n.º 7
0
        public static string ExportToCSV(MetaFile nmeta,
                                         bool allpages, int frompage, int topage, string separator, char delimiter, int precision)
        {
            int j, k;

            string[,] pmatrix;
            MetaPage apage;
            SortedList <string, int> columns  = new SortedList <string, int>();
            SortedList <string, int> rows     = new SortedList <string, int>();
            StringBuilder            nbuilder = new StringBuilder();
            int    index;
            string topstring;
            string leftstring;

            if (allpages)
            {
                nmeta.RequestPage(MetaFile.MAX_NUMBER_PAGES);
                frompage = 0;
                topage   = nmeta.Pages.CurrentCount - 1;
            }
            else
            {
                frompage = frompage - 1;
                topage   = topage - 1;
                nmeta.RequestPage(topage);
                if (topage > nmeta.Pages.CurrentCount - 1)
                {
                    topage = nmeta.Pages.Count - 1;
                }
            }
            // First distribute in columns
            columns.Clear();
            for (int i = frompage; i <= topage; i++)
            {
                apage = nmeta.Pages[i];
                for (j = 0; j < apage.Objects.Count; j++)
                {
                    MetaObject nobject = apage.Objects[j];
                    leftstring = (nobject.Left / precision).ToString("0000000000");
                    index      = columns.IndexOfKey(leftstring);
                    if (index < 0)
                    {
                        columns.Add(leftstring, 1);
                    }
                    else
                    {
                        columns[leftstring] = columns[leftstring] + 1;
                    }
                }
            }

            // Distribute in rows and columns
            for (int i = frompage; i <= topage; i++)
            {
                apage = nmeta.Pages[i];
                rows.Clear();
                for (j = 0; j < apage.Objects.Count; j++)
                {
                    MetaObject nobject = apage.Objects[j];
                    if (nobject.MetaType == MetaObjectType.Text)
                    {
                        topstring = (nobject.Top / precision).ToString("0000000000");
                        index     = rows.IndexOfKey(topstring);
                        if (index < 0)
                        {
                            rows.Add(topstring, 1);
                        }
                        else
                        {
                            rows[topstring] = rows[topstring] + 1;
                        }
                    }
                }
                pmatrix = new string[rows.Count, columns.Count];
                for (j = 0; j < apage.Objects.Count; j++)
                {
                    MetaObject nobject = apage.Objects[j];
                    PrintObject(pmatrix, apage, nobject,
                                precision, rows, columns);
                }
                for (j = 0; j < rows.Count; j++)
                {
                    for (k = 0; k < columns.Count; k++)
                    {
                        if (k != 0)
                        {
                            nbuilder.Append(separator);
                        }
                        string nvalue = pmatrix[j, k];
                        if (nvalue == null)
                        {
                            nvalue = "";
                        }
                        nbuilder.Append(StringUtil.CustomQuoteStr(nvalue, delimiter));
                    }
                    nbuilder.Append(System.Environment.NewLine);
                }
                // Page separator is new line
                nbuilder.Append(System.Environment.NewLine);
            }
            return(nbuilder.ToString());
        }