public static void FontsNotEmbedded()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Printing();

            // Create PdfViewer object
            PdfViewer viewer = new PdfViewer();

            // Open input PDF file
            viewer.BindPdf(dataDir + "input.pdf");

            // Set attributes for printing
            viewer.AutoResize      = true;    // Print the file with adjusted size
            viewer.AutoRotate      = true;    // Print the file with adjusted rotation
            viewer.PrintPageDialog = false;   // Do not produce the page number dialog when printing

            // Create objects for printer and page settings and PrintDocument
            System.Drawing.Printing.PrinterSettings ps  = new System.Drawing.Printing.PrinterSettings();
            System.Drawing.Printing.PageSettings    pgs = new System.Drawing.Printing.PageSettings();

            // Set XPS/PDF printer name
            ps.PrinterName = "Microsoft XPS Document Writer";
            // Or set the PDF printer
            // Ps.PrinterName = "Adobe PDF";

            // Set PageSize (if required)
            pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);

            // Set PageMargins (if required)
            pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

            // ExStart:FontsNotEmbedded
            // Render all system fonts with native system approach (embed the fonts to output documents)
            viewer.RenderingOptions.SystemFontsNativeRendering = true;
            // ExEnd:FontsNotEmbedded

            // Print document using printer and page settings
            viewer.PrintDocumentWithSettings(pgs, ps);

            // Close the PDF file after priting
            viewer.Close();
        }
Exemplo n.º 2
0
        public static void ShowPrintDialog()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Printing();

            // Create PdfViewer object
            PdfViewer viewer = new PdfViewer();

            // Open input PDF file
            viewer.BindPdf(dataDir + "input.pdf");

            // Set attributes for printing
            viewer.AutoResize      = true;    // Print the file with adjusted size
            viewer.AutoRotate      = true;    // Print the file with adjusted rotation
            viewer.PrintPageDialog = false;   // Do not produce the page number dialog when printing

            // Create objects for printer and page settings and PrintDocument
            System.Drawing.Printing.PrinterSettings ps     = new System.Drawing.Printing.PrinterSettings();
            System.Drawing.Printing.PageSettings    pgs    = new System.Drawing.Printing.PageSettings();
            System.Drawing.Printing.PrintDocument   prtdoc = new System.Drawing.Printing.PrintDocument();

            // Set printer name
            ps.PrinterName = prtdoc.PrinterSettings.PrinterName;

            // Set PageSize (if required)
            pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);

            // Set PageMargins (if required)
            pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
            // ExStart:PrintDialog
            System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
            if (printDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // Document printing code goes here
                // Print document using printer and page settings
                viewer.PrintDocumentWithSettings(pgs, ps);
            }
            // ExEnd:PrintDialog

            // Close the PDF file after priting
            viewer.Close();
        }
Exemplo n.º 3
0
        // ExEnd:PrintingJobSettings
        public static void Run()
        {
            // ExStart:PrintPages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Printing();

            int    printingJobIndex = 0;
            string inPdf            = dataDir + "input.pdf";
            string output           = dataDir;
            IList <PrintingJobSettings> printingJobs = new List <PrintingJobSettings>();

            PrintingJobSettings printingJob1 = new PrintingJobSettings();

            printingJob1.FromPage   = 1;
            printingJob1.ToPage     = 3;
            printingJob1.OutputFile = output + "35925_1_3.xps";
            printingJob1.Mode       = Duplex.Default;

            printingJobs.Add(printingJob1);

            PrintingJobSettings printingJob2 = new PrintingJobSettings();

            printingJob2.FromPage   = 4;
            printingJob2.ToPage     = 6;
            printingJob2.OutputFile = output + "35925_4_6.xps";
            printingJob2.Mode       = Duplex.Simplex;

            printingJobs.Add(printingJob2);

            PrintingJobSettings printingJob3 = new PrintingJobSettings();

            printingJob3.FromPage   = 7;
            printingJob3.ToPage     = 7;
            printingJob3.OutputFile = output + "35925_7.xps";
            printingJob3.Mode       = Duplex.Default;

            printingJobs.Add(printingJob3);

            PdfViewer viewer = new PdfViewer();

            viewer.BindPdf(inPdf);
            viewer.AutoResize      = true;
            viewer.AutoRotate      = true;
            viewer.PrintPageDialog = false;

            PrinterSettings ps  = new PrinterSettings();
            PageSettings    pgs = new PageSettings();

            ps.PrinterName   = "Microsoft XPS Document Writer";
            ps.PrintFileName = Path.GetFullPath(printingJobs[printingJobIndex].OutputFile);
            ps.PrintToFile   = true;
            ps.FromPage      = printingJobs[printingJobIndex].FromPage;
            ps.ToPage        = printingJobs[printingJobIndex].ToPage;
            ps.Duplex        = printingJobs[printingJobIndex].Mode;
            ps.PrintRange    = PrintRange.SomePages;

            pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);
            ps.DefaultPageSettings.PaperSize = pgs.PaperSize;
            pgs.Margins      = new System.Drawing.Printing.Margins(0, 0, 0, 0);
            viewer.EndPrint += (sender, args) =>
            {
                if (++printingJobIndex < printingJobs.Count)
                {
                    ps.PrintFileName = Path.GetFullPath(printingJobs[printingJobIndex].OutputFile);
                    ps.FromPage      = printingJobs[printingJobIndex].FromPage;
                    ps.ToPage        = printingJobs[printingJobIndex].ToPage;
                    ps.Duplex        = printingJobs[printingJobIndex].Mode;
                    viewer.PrintDocumentWithSettings(pgs, ps);
                }
            };

            viewer.PrintDocumentWithSettings(pgs, ps);
            // ExEnd:PrintPages
        }
        public static void Run()
        {
            try
            {
                // ExStart:CheckPrintJobStatus
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Printing();

                // Instantiate PdfViewer object
                PdfViewer viewer = new PdfViewer();

                // Bind source PDF file
                viewer.BindPdf(dataDir + "input.pdf");
                viewer.AutoResize = true;

                // Hide printing dialog
                viewer.PrintPageDialog = false;

                // Create Printer Settings object
                System.Drawing.Printing.PrinterSettings ps     = new System.Drawing.Printing.PrinterSettings();
                System.Drawing.Printing.PageSettings    pgs    = new System.Drawing.Printing.PageSettings();
                System.Drawing.Printing.PrintDocument   prtdoc = new System.Drawing.Printing.PrintDocument();

                // Specify the printer anme
                ps.PrinterName = "Microsoft XPS Document Writer";

                // Resultant Printout name
                ps.PrintFileName = "ResultantPrintout.xps";

                // Print the output to file
                ps.PrintToFile = true;
                ps.FromPage    = 1;
                ps.ToPage      = 2;
                ps.PrintRange  = System.Drawing.Printing.PrintRange.SomePages;

                // Specify the page size of printout
                pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);
                ps.DefaultPageSettings.PaperSize = pgs.PaperSize;
                pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

                // Print the document with settings specified above
                viewer.PrintDocumentWithSettings(pgs, ps);

                // Check the print status
                if (viewer.PrintStatus != null)
                {
                    // An exception was thrown
                    Exception ex = viewer.PrintStatus as Exception;
                    if (ex != null)
                    {
                        // Get exception message
                    }
                }
                else
                {
                    // No errors were found. Printing job has completed successfully
                    Console.WriteLine("printing completed without any issue..");
                }
                // ExEnd:CheckPrintJobStatus
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }