예제 #1
0
        public static void Alignment(string pdfOutputFile)
        {
            Document document = new Document();
            Section  section  = document.AddSection();

            section.PageSetup.LeftMargin  = 0;
            section.PageSetup.RightMargin = 0;
            Paragraph par = section.AddParagraph();

//      FillFormattedParagraph(par);
//      par.Format.Alignment = ParagraphAlignment.Left;

//      par = section.AddParagraph();
//      FillFormattedParagraph(par);
//      par.Format.Alignment = ParagraphAlignment.Right;

//      par = section.AddParagraph();
            FillFormattedParagraph(par);
            par.Format.Alignment = ParagraphAlignment.Center;
//
//      par = section.AddParagraph();
//      FillFormattedParagraph(par);
//      par.Format.Alignment = ParagraphAlignment.Justify;

            par.Format.FirstLineIndent = "-2cm";
            par.Format.LeftIndent      = "2cm";
            par.Format.RightIndent     = "3cm";
            PdfPrinter printer = new PdfPrinter();

            printer.Document = document;
            printer.PrintDocument();
            printer.PdfDocument.Save(pdfOutputFile);
        }
예제 #2
0
        public static void VerticalAlign(string outputFile)
        {
            Document document = new Document();
            Section  sec      = document.Sections.AddSection();

            sec.AddParagraph("A paragraph before.");
            Table table = sec.AddTable();

            table.Borders.Visible = true;
            table.AddColumn();
            table.AddColumn();
            Row row = table.AddRow();

            row.HeightRule        = RowHeightRule.Exactly;
            row.Height            = 70;
            row.VerticalAlignment = VerticalAlignment.Center;
            row[0].AddParagraph("First Cell");
            row[1].AddParagraph("Second Cell");
            sec.AddParagraph("A Paragraph afterwards.");


            PdfPrinter printer = new PdfPrinter();

            printer.Document = document;
            printer.PrintDocument();
            printer.PdfDocument.Save(outputFile);
        }
예제 #3
0
        public static void CellMerge(string outputFile)
        {
            Document document = new Document();
            Section  sec      = document.Sections.AddSection();

            sec.AddParagraph("A paragraph before.");
            Table table = sec.AddTable();

            table.Borders.Visible = true;
            table.AddColumn();
            table.AddColumn();
            Row  row  = table.AddRow();
            Cell cell = row.Cells[0];

            cell.MergeRight          = 1;
            cell.Borders.Visible     = true;
            cell.Borders.Left.Width  = 8;
            cell.Borders.Right.Width = 2;
            cell.AddParagraph("First Cell");

            row  = table.AddRow();
            cell = row.Cells[1];
            cell.AddParagraph("Last Cell within this row");
            cell.MergeDown            = 1;
            cell.Borders.Bottom.Width = 15;
            cell.Borders.Right.Width  = 30;
            cell.Shading.Color        = Colors.LightBlue;
            row = table.AddRow();
            sec.AddParagraph("A Paragraph afterwards");
            PdfPrinter printer = new PdfPrinter();

            printer.Document = document;
            printer.PrintDocument();
            printer.PdfDocument.Save(outputFile);
        }
예제 #4
0
 /// <summary>
 /// Generate a PDF file for the document.
 /// </summary>
 public void Generate()
 {
     try
     {
         UI.Log("Generating PDF file", ChmLogLevel.INFO);
         if (Project.PdfGeneration == ChmProject.PdfGenerationWay.OfficeAddin)
         {
             MSWord word = new MSWord();
             if (!word.SaveWordToPdf(MainSourceFilePath, Project.PdfPath))
             {
                 UI.Log("Warning: There was a time out waiting to close the word document", ChmLogLevel.WARNING);
             }
         }
         else
         {
             PdfPrinter pdfPrinter = new PdfPrinter();
             pdfPrinter.ConvertToPdf(MainSourceFilePath, Project.PdfPath);
         }
     }
     catch (Exception ex)
     {
         if (Project.PdfGeneration == ChmProject.PdfGenerationWay.OfficeAddin)
         {
             UI.Log("Something wrong happened with the PDF generation. Remember you must to have Microsoft Office 2007 and the" +
                    "pdf/xps generation add-in (http://www.microsoft.com/downloads/details.aspx?FamilyID=4D951911-3E7E-4AE6-B059-A2E79ED87041&displaylang=en)", ChmLogLevel.ERROR);
         }
         else
         {
             UI.Log("Something wrong happened with the PDF generation. Remember you must to have PdfCreator (VERSION " + PdfPrinter.SUPPORTEDVERSION +
                    " AND ONLY THIS VERSION) installed into your computer to " +
                    "generate a PDF file. You can download it from http://www.pdfforge.org/products/pdfcreator/download", ChmLogLevel.ERROR);
         }
         UI.Log(ex);
     }
 }
예제 #5
0
        public static void CellMerge(string outputFile)
        {
            Document document = new Document();
              Section sec = document.Sections.AddSection();
              sec.AddParagraph("A paragraph before.");
              Table table = sec.AddTable();
              table.Borders.Visible = true;
              table.AddColumn();
              table.AddColumn();
              Row row = table.AddRow();
              Cell cell = row.Cells[0];
              cell.MergeRight = 1;
              cell.Borders.Visible = true;
              cell.Borders.Left.Width = 8;
              cell.Borders.Right.Width = 2;
              cell.AddParagraph("First Cell");

              row = table.AddRow();
              cell = row.Cells[1];
              cell.AddParagraph("Last Cell within this row");
              cell.MergeDown = 1;
              cell.Borders.Bottom.Width = 15;
              cell.Borders.Right.Width = 30;
              cell.Shading.Color = Colors.LightBlue;
              row = table.AddRow();
              sec.AddParagraph("A Paragraph afterwards");
              PdfPrinter printer = new PdfPrinter();
              printer.Document = document;
              printer.PrintDocument();
              printer.PdfDocument.Save(outputFile);
        }
예제 #6
0
        public static void Alignment(string pdfOutputFile)
        {
            Document document = new Document();
              Section section = document.AddSection();
              section.PageSetup.LeftMargin = 0;
              section.PageSetup.RightMargin = 0;
              Paragraph par = section.AddParagraph();
            //      FillFormattedParagraph(par);
            //      par.Format.Alignment = ParagraphAlignment.Left;

            //      par = section.AddParagraph();
            //      FillFormattedParagraph(par);
            //      par.Format.Alignment = ParagraphAlignment.Right;

            //      par = section.AddParagraph();
            FillFormattedParagraph(par);
            par.Format.Alignment = ParagraphAlignment.Center;
            //
            //      par = section.AddParagraph();
            //      FillFormattedParagraph(par);
            //      par.Format.Alignment = ParagraphAlignment.Justify;

              par.Format.FirstLineIndent = "-2cm";
              par.Format.LeftIndent = "2cm";
              par.Format.RightIndent = "3cm";
              PdfPrinter printer = new PdfPrinter();
              printer.Document = document;
              printer.PrintDocument();
              printer.PdfDocument.Save(pdfOutputFile);
        }
예제 #7
0
        public static void TwoParagraphs(string outputFile)
        {
            Document doc = new Document();
            Section  sec = doc.Sections.AddSection();

            sec.PageSetup.TopMargin    = 0;
            sec.PageSetup.BottomMargin = 0;

            Paragraph par1 = sec.AddParagraph();

            TestParagraphRenderer.FillFormattedParagraph(par1);
            TestParagraphRenderer.GiveBorders(par1);
            par1.Format.SpaceAfter  = "2cm";
            par1.Format.SpaceBefore = "3cm";
            Paragraph par2 = sec.AddParagraph();

            TestParagraphRenderer.FillFormattedParagraph(par2);
            TestParagraphRenderer.GiveBorders(par2);
            par2.Format.SpaceBefore = "3cm";

            PdfPrinter printer = new PdfPrinter();

            printer.Document = doc;
            printer.PrintDocument();
            printer.PdfDocument.Save(outputFile);
        }
예제 #8
0
        static void Main(string[] args)
        {
            var printer = new PdfPrinter("Microsoft Print to PDF");

            printer.Print(printFile);
            Console.WriteLine("The file was succesfully printed.");
            Console.ReadKey();
        }
예제 #9
0
        static void Main(string[] args)
        {
            var printer = new PdfPrinter("Microsoft Print To PDF");

            printer.Print(printFile);
            printer.Print(printFile, documentName: "with name");
            Console.WriteLine("The files were succesfully printed.");
            Console.ReadKey();
        }
예제 #10
0
        static void Main(string[] args)
        {
            var printer = new PdfPrinter("PDF-XChange Standard");

            printer.Print(printFile);
            printer.Print(printFile, documentName: "with name");
            Console.WriteLine("The files were succesfully printed.");
            Console.ReadKey();
        }
예제 #11
0
        public static string GetDefaultPrinter()
        {
            string result = string.Empty;

            if (Globals.IsWindows())
            {
                var printer = new PdfPrinter();
                result = printer.Settings.PrinterName;
            }
            return(result);
        }
예제 #12
0
 public static void Formatted(string pdfOutputFile)
 {
   Document document = new Document();
   Section section = document.AddSection();
   Paragraph par = section.AddParagraph();
   FillFormattedParagraph(par);
   PdfPrinter printer = new PdfPrinter();
   printer.Document = document;
   printer.PrintDocument();
   printer.PdfDocument.Save(pdfOutputFile);
 }
예제 #13
0
        private void tsmiPrint_Click(object sender, EventArgs e)
        {
            var printingRulesFilePath = SavePrintingRuleFileWithDialog();

            if (printingRulesFilePath != null)
            {
                var pdfPrinter      = new PdfPrinter();
                var printOutputPath = $"{printingRulesFilePath}.pdf";
                pdfPrinter.Print(printOutputPath, printingRulesFilePath);
            }
        }
예제 #14
0
파일: Program.cs 프로젝트: karak/Geovanni
        private static void WritePdf(IEnumerable <string> aozoraText, string output, Layout layout)
        {
            ILatinWordMetric latinMetric = new PdfLatinWordMetric(fontSetting.LatinFont, layout.FontSize);
            var engine  = new LayoutEngine(layout, latinMetric);
            var printer = new PdfPrinter(output, layout, fontSetting);

            using (printer)
            {
                engine.SendTo(aozoraText, printer);
            }
        }
예제 #15
0
        public static void Formatted(string pdfOutputFile)
        {
            Document  document = new Document();
            Section   section  = document.AddSection();
            Paragraph par      = section.AddParagraph();

            FillFormattedParagraph(par);
            PdfPrinter printer = new PdfPrinter();

            printer.Document = document;
            printer.PrintDocument();
            printer.PdfDocument.Save(pdfOutputFile);
        }
예제 #16
0
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            var path = String.Format("{0}\\{1}.pdf",
                                     Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                                     DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"));

            PdfPrinter.Print(new List <Canvas> {
                canvasObj
            }, path);

            //PrintDialog pd = new PrintDialog();
            //if (pd.ShowDialog() ?? false)
            //  pd.PrintVisual(ViewboxObj, "Printing a UserControl");
        }
예제 #17
0
 public static void TextAndBlanks(string pdfOutputFile)
 {
   Document document = new Document();
   Section section = document.AddSection();
   Paragraph par = section.AddParagraph("Dies");
   for (int idx = 0; idx <= 40; ++idx)
   {
     par.AddCharacter(SymbolName.Blank);
     par.AddText(idx.ToString());
     par.AddCharacter(SymbolName.Blank);
     par.AddText((idx + 1).ToString());
     par.AddCharacter(SymbolName.Blank);
     par.AddText((idx + 2).ToString());
   }
   PdfPrinter printer = new PdfPrinter();
   printer.Document = document;
   printer.PrintDocument();
   printer.PdfDocument.Save(pdfOutputFile);
 }
예제 #18
0
        public static void Tabs(string pdfOutputFile)
        {
            Document document = new Document();
            Section  section  = document.AddSection();

            section.PageSetup.LeftMargin  = 0;
            section.PageSetup.RightMargin = 0;
            Paragraph par = section.AddParagraph();

            par.Format.TabStops.AddTabStop("20cm", TabAlignment.Right);
            par.AddText(" text before tab bla bla bla. text before tab bla bla bla. text before tab bla bla bla. text before tab bla bla bla.");
            //par.AddTab();
            par.AddText(" ............ after tab bla bla bla.");
            PdfPrinter printer = new PdfPrinter();

            printer.Document = document;
            printer.PrintDocument();
            printer.PdfDocument.Save(pdfOutputFile);
        }
예제 #19
0
 private void button12_Click(object sender, System.EventArgs e)
 {
     if (this.tbxDdlFile.Text != "")
     {
         try
         {
             Document   doc        = DdlReader.DocumentFromFile(tbxDdlFile.Text);
             PdfPrinter pdfPrinter = new PdfPrinter();
             pdfPrinter.Document = doc;
             pdfPrinter.PrintDocument();
             pdfPrinter.PdfDocument.Save("egal.pdf");
             System.Diagnostics.Process.Start("egal.pdf");
         }
         catch (Exception exc)
         {
             MessageBox.Show(exc.Message);
         }
     }
 }
예제 #20
0
        public static void A1000Paragraphs(string outputFile)
        {
            Document doc = new Document();
              Section sec = doc.Sections.AddSection();

              sec.PageSetup.TopMargin = 0;
              sec.PageSetup.BottomMargin = 0;

              for (int idx = 1; idx <= 1000; ++idx)
              {
            Paragraph par = sec.AddParagraph();
            par.AddText("Paragraph " + idx + ": ");
            TestParagraphRenderer.FillFormattedParagraph(par);
            TestParagraphRenderer.GiveBorders(par);
              }
              PdfPrinter printer = new PdfPrinter();
              printer.Document = doc;
              printer.PrintDocument();
              printer.PdfDocument.Save(outputFile);
        }
예제 #21
0
        public static void A1000Paragraphs(string outputFile)
        {
            Document doc = new Document();
            Section  sec = doc.Sections.AddSection();

            sec.PageSetup.TopMargin    = 0;
            sec.PageSetup.BottomMargin = 0;

            for (int idx = 1; idx <= 1000; ++idx)
            {
                Paragraph par = sec.AddParagraph();
                par.AddText("Paragraph " + idx + ": ");
                TestParagraphRenderer.FillFormattedParagraph(par);
                TestParagraphRenderer.GiveBorders(par);
            }
            PdfPrinter printer = new PdfPrinter();

            printer.Document = doc;
            printer.PrintDocument();
            printer.PdfDocument.Save(outputFile);
        }
예제 #22
0
        static void Main(string[] args)
        {
            var resultsFilePath       = @".\Results.txt";
            var printingRulesFilePath = @".\Printings.xml";

            var results    = File.ReadAllLines(resultsFilePath);
            var pdfPrinter = new PdfPrinter();

            foreach (var result in results)
            {
                var  nameAndPosition = result.Split(';');
                uint position        = Convert.ToUInt32(nameAndPosition[1]);
                var  replaceables    = new Dictionary <string, string>
                {
                    { "@Name", nameAndPosition[0] },
                    { "@Position", $"{position}{PositionPostfixProvider.Get(position)}" }
                };
                var printOutputPath = $".\\{position}. {nameAndPosition[0]}.pdf";
                pdfPrinter.Print(printOutputPath, printingRulesFilePath, replaceables);
            }
        }
예제 #23
0
        public static void TextAndBlanks(string pdfOutputFile)
        {
            Document  document = new Document();
            Section   section  = document.AddSection();
            Paragraph par      = section.AddParagraph("Dies");

            for (int idx = 0; idx <= 40; ++idx)
            {
                par.AddCharacter(SymbolName.Blank);
                par.AddText(idx.ToString());
                par.AddCharacter(SymbolName.Blank);
                par.AddText((idx + 1).ToString());
                par.AddCharacter(SymbolName.Blank);
                par.AddText((idx + 2).ToString());
            }
            PdfPrinter printer = new PdfPrinter();

            printer.Document = document;
            printer.PrintDocument();
            printer.PdfDocument.Save(pdfOutputFile);
        }
예제 #24
0
        public static void Fields(string outputFile)
        {
            Document  document = new Document();
            Section   section  = document.AddSection();
            Paragraph par      = section.AddParagraph();

            par.AddText("Section: ");
            par.AddSectionField().Format = "ALPHABETIC";
            par.AddLineBreak();

            par.AddText("SectionPages: ");
            par.AddSectionField().Format = "alphabetic";
            par.AddLineBreak();

            par.AddText("Page: ");
            par.AddPageField().Format = "ROMAN";
            par.AddLineBreak();

            par.AddText("NumPages: ");
            par.AddNumPagesField();
            par.AddLineBreak();

            par.AddText("Date: ");
            par.AddDateField();
            par.AddLineBreak();

            par.AddText("Bookmark: ");
            par.AddBookmark("Egal");
            par.AddLineBreak();

            par.AddText("PageRef: ");
            par.AddPageRefField("Egal");

            PdfPrinter printer = new PdfPrinter();

            printer.Document = document;
            printer.PrintDocument();
            printer.PdfDocument.Save(outputFile);
        }
예제 #25
0
        private static void PrintPDFWindows(string printerName, Stream fs)
        {
            Globals.Log($"PRINTING windows v2! {printerName} and ");
            try
            {
                Globals.Log($"PDF2: Loading file: MEMORY BUFFER");
                Globals.Log($"PDF2: Printing to: {printerName}");


                var printer = new PdfPrinter(printerName);
                printer.PageSettings.Color = false;
                printer.Print(fs);
                //printer.Print("C:/Temp/0000000208.pdf");


                Globals.Log($"PDF2: Done!");
            }
            catch (Exception e)
            {
                Globals.Log($"PDFError: {e.Message}");
            }
        }
예제 #26
0
        public static void TwoParagraphs(string outputFile)
        {
            Document doc = new Document();
              Section sec = doc.Sections.AddSection();

              sec.PageSetup.TopMargin = 0;
              sec.PageSetup.BottomMargin = 0;

              Paragraph par1 = sec.AddParagraph();
              TestParagraphRenderer.FillFormattedParagraph(par1);
              TestParagraphRenderer.GiveBorders(par1);
              par1.Format.SpaceAfter = "2cm";
              par1.Format.SpaceBefore = "3cm";
              Paragraph par2 = sec.AddParagraph();
              TestParagraphRenderer.FillFormattedParagraph(par2);
              TestParagraphRenderer.GiveBorders(par2);
              par2.Format.SpaceBefore = "3cm";

              PdfPrinter printer = new PdfPrinter();
              printer.Document = doc;
              printer.PrintDocument();
              printer.PdfDocument.Save(outputFile);
        }
예제 #27
0
 public static void initial(TestContext text)
 {
     printer = new PdfPrinter();
 }
예제 #28
0
 public Document()
 {
     _consolePrinter = new ConsolePrinter();
     _pdfPrinter     = new PdfPrinter();
 }
예제 #29
0
    public static void Fields(string outputFile)
    {
      Document document = new Document();
      Section section = document.AddSection();
      Paragraph par = section.AddParagraph();
      par.AddText("Section: ");
      par.AddSectionField().Format = "ALPHABETIC";
      par.AddLineBreak();

      par.AddText("SectionPages: ");
      par.AddSectionField().Format = "alphabetic";
      par.AddLineBreak();

      par.AddText("Page: ");
      par.AddPageField().Format = "ROMAN";
      par.AddLineBreak();
      
      par.AddText("NumPages: ");
      par.AddNumPagesField();
      par.AddLineBreak();

      par.AddText("Date: ");
      par.AddDateField();
      par.AddLineBreak();

      par.AddText("Bookmark: ");
      par.AddBookmark("Egal");
      par.AddLineBreak();

      par.AddText("PageRef: ");
      par.AddPageRefField("Egal");

      PdfPrinter printer = new PdfPrinter();
      printer.Document = document;
      printer.PrintDocument();
      printer.PdfDocument.Save(outputFile);
    }
예제 #30
0
        public static void Main()
        {
            string url         = "https://dotnetbrowser-support.teamdev.com/docs/guides/gs/printing.html";
            string pdfFilePath = Path.GetFullPath("result.pdf");

            uint viewWidth   = 1024;
            uint viewHeight  = 768;
            Size browserSize = new Size(viewWidth, viewHeight);

            try
            {
                using (IEngine engine = EngineFactory.Create(new EngineOptions.Builder
                {
                    RenderingMode = RenderingMode.OffScreen,
                    GpuDisabled = true
                }.Build()))
                {
                    Console.WriteLine("Engine created");

                    using (IBrowser browser = engine.CreateBrowser())
                    {
                        Console.WriteLine("Browser created");
                        // 1. Resize browser to the required dimension.
                        browser.Size = browserSize;

                        // 2. Load the required web page and wait until it is loaded completely.
                        Console.WriteLine("Loading " + url);
                        browser.Navigation.LoadUrl(url).Wait();


                        // 3. Configure print handlers.
                        browser.RequestPrintHandler =
                            new Handler <RequestPrintParameters, RequestPrintResponse>(p =>
                        {
                            return(RequestPrintResponse
                                   .Print());
                        });

                        TaskCompletionSource <string> printCompletedTcs = new TaskCompletionSource <string>();
                        browser.PrintHtmlContentHandler
                            = new Handler <PrintHtmlContentParameters, PrintHtmlContentResponse>(p =>
                        {
                            try
                            {
                                // Get the print job for the built-in PDF printer.
                                PdfPrinter <PdfPrinter.IHtmlSettings> pdfPrinter = p.Printers.Pdf;
                                IPrintJob <PdfPrinter.IHtmlSettings> printJob    = pdfPrinter.PrintJob;

                                // Apply the necessary print settings
                                printJob.Settings.Apply(s =>
                                {
                                    s.PaperSize = pdfPrinter.Capabilities
                                                  .PaperSizes
                                                  .FirstOrDefault(size => size.Name.Contains("A4"));
                                    s.PrintingHeaderFooterEnabled = true;
                                    // Specify the path to save the result.
                                    s.PdfFilePath = pdfFilePath;
                                });

                                string browserUrl        = p.Browser.Url;
                                printJob.PrintCompleted += (sender, args) =>
                                {
                                    printCompletedTcs.TrySetResult(browserUrl);
                                };

                                // Tell Chromium to use the built-in PDF printer for printing.
                                return(PrintHtmlContentResponse.Print(pdfPrinter));
                            }
                            catch (Exception e)
                            {
                                printCompletedTcs.TrySetException(e);
                                throw;
                            }
                        });

                        // 4. Initiate printing and wait until it is completed.
                        Console.WriteLine("URL loaded. Initiate printing");
                        browser.MainFrame.Print();
                        string printedUrl = printCompletedTcs.Task.Result;
                        Console.WriteLine("Printing completed for the URL: " + printedUrl);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
예제 #31
0
 public static void Tabs(string pdfOutputFile)
 {
   Document document = new Document();
   Section section = document.AddSection();
   section.PageSetup.LeftMargin = 0;
   section.PageSetup.RightMargin = 0;
   Paragraph par = section.AddParagraph();
   par.Format.TabStops.AddTabStop("20cm", TabAlignment.Right);
   par.AddText(" text before tab bla bla bla. text before tab bla bla bla. text before tab bla bla bla. text before tab bla bla bla.");
   //par.AddTab();
   par.AddText(" ............ after tab bla bla bla.");
   PdfPrinter printer = new PdfPrinter();
   printer.Document = document;
   printer.PrintDocument();
   printer.PdfDocument.Save(pdfOutputFile);
 }
예제 #32
0
        public static void VerticalAlign(string outputFile)
        {
            Document document = new Document();
              Section sec = document.Sections.AddSection();
              sec.AddParagraph("A paragraph before.");
              Table table = sec.AddTable();
              table.Borders.Visible = true;
              table.AddColumn();
              table.AddColumn();
              Row row = table.AddRow();
              row.HeightRule = RowHeightRule.Exactly;
              row.Height = 70;
              row.VerticalAlignment = VerticalAlignment.Center;
              row[0].AddParagraph("First Cell");
              row[1].AddParagraph("Second Cell");
              sec.AddParagraph("A Paragraph afterwards.");

              PdfPrinter printer = new PdfPrinter();
              printer.Document = document;
              printer.PrintDocument();
              printer.PdfDocument.Save(outputFile);
        }
예제 #33
0
 private void PrintRecipts( )
 {
     PdfPrinter.PrintRecipts(vReciptHeader, vReciptFooter, vReciptItemTotal, vReciptDetails, vReciptItems);
 }