/// <summary>
 /// Close the printer file
 /// </summary>
 /// <param name="handle">PPD handle</param>
 private static void ClosePrinter(ref IntPtr handle)
 {
     try
     {
         if (handle != IntPtr.Zero)
         {
             LibcupsNative.ppdClose(handle);
         }
     }
     finally
     {
         handle = IntPtr.Zero;
     }
 }
Exemple #2
0
        /// <summary>
        /// Do a cups call to check if it is installed
        /// </summary>
        private static bool CheckCupsInstalled()
        {
            try
            {
                LibcupsNative.cupsGetDefault();
            }
            catch (DllNotFoundException)
            {
                System.Diagnostics.Debug.WriteLine("libcups not found. To have printing support, you need cups installed");
                return(false);
            }

            return(true);
        }
Exemple #3
0
 private static void CloseDests(ref IntPtr ptr, int count)
 {
     try
     {
         if (ptr != IntPtr.Zero)
         {
             LibcupsNative.cupsFreeDests(count, ptr);
         }
     }
     finally
     {
         ptr = IntPtr.Zero;
     }
 }
Exemple #4
0
 /// <summary>
 /// Open the printer's PPD file
 /// </summary>
 /// <param name="printer">Printer name, returned from cupsGetDests</param>
 private static IntPtr OpenPrinter(string printer)
 {
     try
     {
         IntPtr ptr          = LibcupsNative.cupsGetPPD(printer);
         string ppd_filename = Marshal.PtrToStringAnsi(ptr) !;
         IntPtr ppd_handle   = LibcupsNative.ppdOpenFile(ppd_filename);
         return(ppd_handle);
     }
     catch (Exception)
     {
         System.Diagnostics.Debug.WriteLine("There was an error opening the printer {0}. Please check your cups installation.");
     }
     return(IntPtr.Zero);
 }
Exemple #5
0
        // Unfortunately, PrinterSettings and PageSettings couldn't be referencing each other,
        // thus we need to pass them separately
        internal static IntPtr CreateGraphicsContext(PrinterSettings settings, PageSettings default_page_settings)
        {
            IntPtr graphics = IntPtr.Zero;
            string name;

            if (!settings.PrintToFile)
            {
                StringBuilder sb     = new StringBuilder(1024);
                int           length = sb.Capacity;
                LibcupsNative.cupsTempFd(sb, length);
                name    = sb.ToString();
                tmpfile = name;
            }
            else
            {
                name = settings.PrintFileName;
            }

            PaperSize psize = default_page_settings.PaperSize;
            int       width, height;

            if (default_page_settings.Landscape)
            { // Swap in case of landscape
                width  = psize.Height;
                height = psize.Width;
            }
            else
            {
                width  = psize.Width;
                height = psize.Height;
            }

            Gdip.GdipGetPostScriptGraphicsContext(name,
                                                  width * 72 / 100,
                                                  height * 72 / 100,
                                                  default_page_settings.PrinterResolution.X,
                                                  default_page_settings.PrinterResolution.Y, ref graphics);

            DOCINFO doc = default;

            doc.filename = name;
            doc.settings = settings;
            doc.default_page_settings = default_page_settings;
            doc_info.Add(graphics, doc);

            return(graphics);
        }
        /// <summary>
        /// Do a cups call to check if it is installed
        /// </summary>
        private static void CheckCupsInstalled()
        {
            try
            {
                LibcupsNative.cupsGetDefault();
            }
            catch (DllNotFoundException)
            {
#if NETCORE
                System.Diagnostics.Debug.WriteLine("libcups not found. To have printing support, you need cups installed");
#else
                Console.WriteLine("libcups not found. To have printing support, you need cups installed");
#endif
                cups_installed = false;
                return;
            }

            cups_installed = true;
        }
Exemple #7
0
        internal static bool EndDoc(GraphicsPrinter gr)
        {
            DOCINFO doc = (DOCINFO)doc_info[gr.Hdc];

            gr.Graphics.Dispose(); // Dispose object to force surface finish

            IntPtr options;
            int    options_count = GetCupsOptions(doc.settings, doc.default_page_settings, out options);

            LibcupsNative.cupsPrintFile(doc.settings.PrinterName, doc.filename, doc.title, options_count, options);
            LibcupsNative.cupsFreeOptions(options_count, options);
            doc_info.Remove(gr.Hdc);
            if (tmpfile != null)
            {
                try
                { File.Delete(tmpfile); }
                catch { }
            }
            return(true);
        }