Пример #1
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");
            PdfDocumentRenderer renderer = new PdfDocumentRenderer();
            renderer.Document = document;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(outputFile);
        }
Пример #2
0
 /// <summary>
 /// Tests AddFormattedText.
 /// </summary>
 public static void Formatted(string pdfOutputFile)
 {
     Document document = new Document();
     Section section = document.AddSection();
     Paragraph par = section.AddParagraph();
     FillFormattedParagraph(par);
     PdfDocumentRenderer printer = new PdfDocumentRenderer();
     printer.Document = document;
     printer.RenderDocument();
     printer.PdfDocument.Save(pdfOutputFile);
 }
Пример #3
0
        /// <summary>
        /// Render the PDF file
        /// </summary>
        /// <returns></returns>
        public PdfSharp.Pdf.PdfDocument RenderPdf()
        {
            // Create a renderer for the MigraDoc document.
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer();

            // Associate the MigraDoc document with a renderer
            pdfRenderer.Document = document;

            // Layout and render document to PDF
            pdfRenderer.RenderDocument();
            pdfRenderer.PdfDocument.PageLayout = PdfSharp.Pdf.PdfPageLayout.SinglePage;
            return(pdfRenderer.PdfDocument);
        }
Пример #4
0
        public void SaveToPdf(Result data, string filePath)
        {
            var document = PdfBuilderService.BuildDocument(data);

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var pdfRenderer = new PdfDocumentRenderer(true);

            pdfRenderer.Document = document;

            pdfRenderer.RenderDocument();

            pdfRenderer.PdfDocument.Save(filePath);
        }
Пример #5
0
        private static void GenerateFile(Document doc, EntryParameters parameters)
        {
            MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(doc, "MigraDoc.mdddl");
            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true)
            {
                Document = doc
            };

            renderer.RenderDocument();
            string fileName = Path.Combine(parameters.FinalPath ?? parameters.WorkPath, parameters.FileName);

            renderer.PdfDocument.Save(fileName);
        }
 private void Render()
 {
     try
     {
         renderer.RenderDocument();
         renderer.Save(nombre);
     }
     catch (Exception e)
     {
         Log.ShowAndLog(e);
     }
     Invoke(new ThreadStart(Close));
 }
Пример #7
0
        /// <summary>
        /// Tests AddFormattedText.
        /// </summary>
        public static void Formatted(string pdfOutputFile)
        {
            Document  document = new Document();
            Section   section  = document.AddSection();
            Paragraph par      = section.AddParagraph();

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

            printer.Document = document;
            printer.RenderDocument();
            printer.PdfDocument.Save(pdfOutputFile);
        }
Пример #8
0
        //paragraph.AddTab();

        public void SaveToFile(String filename)
        {
            MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);

            renderer.Document = document;

            renderer.RenderDocument();

            // Save the document...
            renderer.PdfDocument.Save(filename);
        }
Пример #9
0
        void saveDocument(String filename)
        {
        finishTable();
        MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");
        PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
        renderer.Document = document;

        renderer.RenderDocument();

        renderer.PdfDocument.Save(filename);
        // ...and start a viewer.
        Process.Start(filename);
        }
Пример #10
0
        public Form1()
        {
            InitializeComponent();
            #region Migradoc
            Document document = new Document();
            Section  section  = document.AddSection();
            section.AddParagraph("Lorem ipsum dolor sit amet, consectetur");
            Paragraph paragraph = section.AddParagraph();
            paragraph.Format.Font.Color = MigraDoc.DocumentObjectModel.Color.FromCmyk(100, 30, 20, 50);
            paragraph.AddFormattedText("Hello, World", TextFormat.Underline);
            FormattedText ft = paragraph.AddFormattedText("Small text", TextFormat.Bold);
            ft.Font.Size = 6;
            Table table = section.AddTable();
            table.Borders.Width   = 0.25;
            table.Rows.LeftIndent = 0;

            Column columnA = table.AddColumn("7cm");
            Column columnB = table.AddColumn("3cm");
            Column columnC = table.AddColumn("3cm");
            columnA.Format.Alignment = ParagraphAlignment.Center;
            Row row = table.AddRow();
            row.Cells[0].AddParagraph("Alarmtype");
            row.Cells[1].AddParagraph("Verdi");
            row.Cells[2].AddParagraph("Dato");

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(false);
            renderer.Document = document;
            renderer.RenderDocument();
            string filename = "migradoc.pdf";
            renderer.PdfDocument.Save(filename);
            Process.Start(filename);
            #endregion

            /*
             #region PDF Sharp
             * PdfDocument document = new PdfDocument();
             * document.Info.Title = "Created with PDFSharp";
             *
             * PdfPage page = document.AddPage();
             *
             * XGraphics gfx = XGraphics.FromPdfPage(page);
             *
             * XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
             *
             * gfx.DrawString("Hei på deg!", font, XBrushes.Black,new XRect(0,0,page.Width,page.Height), XStringFormats.Center);
             *
             * const string filename = "HelloWorld.pdf";
             * document.Save(filename);
             #endregion
             */
        }
        /// <summary>
        ///     Opens the Adobe Acrobat Reader print prompt
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void printPdf_click(object sender, RoutedEventArgs e)
        {
            //Create and save the pdf
            if (invoice == null)
            {
                MessageBox.Show("Invoice is not loaded!");
            }
            else
            {
                var document = createPdf();
                document.UseCmykColor = true;
                // Create a renderer for PDF that uses Unicode font encoding
                var pdfRenderer = new PdfDocumentRenderer(true);

                // Set the MigraDoc document
                pdfRenderer.Document = document;

                // Create the PDF document
                pdfRenderer.RenderDocument();

                // Save the PDF document...
                var filename = "Invoice.pdf";

                pdfRenderer.Save(filename);

                //open adobe acrobat
                var proc = new Process();
                proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                proc.StartInfo.Verb = "print";

                //Define location of adobe reader/command line
                //switches to launch adobe in "print" mode
                proc.StartInfo.FileName =
                    @"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
                proc.StartInfo.Arguments       = string.Format(@"/p {0}", filename);
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.CreateNoWindow  = true;

                proc.Start();
                proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                if (proc.HasExited == false)
                {
                    proc.WaitForExit(10000);
                }

                proc.EnableRaisingEvents = true;

                proc.Close();
            }
        }
Пример #12
0
        private void savePdf()
        {
            bool isUnicode = true;
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(!isUnicode);

            pdfRenderer.Document = m_Document;
            pdfRenderer.RenderDocument();
            Stream stream = null;

            using (stream = new FileStream(m_PdfPath, FileMode.Create))
            {
                pdfRenderer.PdfDocument.Save(stream);
            }
        }
Пример #13
0
        static void Main(string[] args)
        {
            // Create a MigraDoc document.
            var document = CreateDocument();

#if DEBUG
            MigraDoc.DocumentObjectModel.IO.Xml.DdlWriter.WriteToFile(document, "MigraDoc.xml");

            MigraDoc.DocumentObjectModel.Document document3 = null;

            using (StreamReader sr = File.OpenText("MigraDoc.xml"))
            {
                var errors = new MigraDoc.DocumentObjectModel.IO.DdlReaderErrors();
                var reader = new MigraDoc.DocumentObjectModel.IO.Xml.DdlReader(sr, errors);

                document3 = reader.ReadDocument();

                using (StreamWriter sw = new StreamWriter("MigraDoc.xml.error"))
                {
                    foreach (MigraDoc.DocumentObjectModel.IO.DdlReaderError error in errors)
                    {
                        sw.WriteLine("{0}:{1} {2} {3}", error.SourceLine, error.SourceColumn, error.ErrorLevel, error.ErrorMessage);
                    }
                }
            }
#endif


            // ----- Unicode encoding and font program embedding in MigraDoc is demonstrated here. -----

            // A flag indicating whether to create a Unicode PDF or a WinAnsi PDF file.
            // This setting applies to all fonts used in the PDF document.
            // This setting has no effect on the RTF renderer.
            const bool unicode = true;

            // Create a renderer for the MigraDoc document.
            var pdfRenderer = new PdfDocumentRenderer(unicode);

            // Associate the MigraDoc document with a renderer.
            pdfRenderer.Document = document3;

            // Layout and render document to PDF.
            pdfRenderer.RenderDocument();

            // Save the document...
            const string filename = "HelloWorld.pdf";
            pdfRenderer.PdfDocument.Save(filename);
            // ...and start a viewer.
            Process.Start(filename);
        }
        protected virtual PdfDocument Render()
        {
            // Create a MigraDoc document
            Document document = this.CreateDocument();

            // Add document infos
            document.Info.Title    = _title;
            document.Info.Author   = _author;
            document.Info.Subject  = _subject;
            document.Info.Keywords = _keywords;

            // Set default styles (actually not needed)
            document.Styles.Normal.Font.Name  = _pdfStyling.FontName;
            document.Styles.Normal.Font.Size  = _pdfStyling.FontSize;
            document.Styles.Normal.Font.Color = _pdfStyling.FontColor;

            document.UseCmykColor = true;

            // ===== Unicode encoding and font program embedding in MigraDoc is demonstrated here =====

            // A flag indicating whether to create a Unicode PDF or a WinAnsi PDF file.
            // This setting applies to all fonts used in the PDF document.
            // This setting has no effect on the RTF renderer.
            const bool unicode = false;

            // ========================================================================================

            // Create a renderer for the MigraDoc document.
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode)
            {
                // Associate the MigraDoc document with a renderer
                Document = document
            };

            // Layout and render document to PDF
            pdfRenderer.RenderDocument();

            PdfDocument pdf = pdfRenderer.PdfDocument;

            // Add pages
            if (Pages != null && Pages.Any())
            {
                foreach (IPdfPage page in Pages)
                {
                    page.Render(_pdfStyling, pdf);
                }
            }

            return(pdf);
        }
        public virtual void WriteReport(Report report, string filename)
        {
            Document doc = CreateDocument(report);

            const bool             unicode     = false;
            const PdfFontEmbedding embedding   = PdfFontEmbedding.Always;
            PdfDocumentRenderer    pdfRenderer = new PdfDocumentRenderer(unicode, embedding);

            pdfRenderer.Document = doc;

            pdfRenderer.RenderDocument();

            pdfRenderer.PdfDocument.Save(filename);
        }
Пример #16
0
        public byte[] ToPdf()
        {
            var documentRenderer = new PdfDocumentRenderer(true)
            {
                Document = _document
            };

            documentRenderer.RenderDocument();
            using (var documentStream = new MemoryStream())
            {
                documentRenderer.PdfDocument.Save(documentStream);
                return(documentStream.ToArray());
            }
        }
Пример #17
0
        public static OperationResult CreateCatalog(PdfGenParams pdfGenParams)
        {
            var result = new OperationResult();

            try
            {
                var toBeProcessedCount = Desene.DAL.GetCount(pdfGenParams.ForMovies, pdfGenParams.PDFGenType);

                var document = new Document();
                document.Info.Title  = "Movies Catalog";
                document.Info.Author = "Calin Marinescu";

                var formProgressIndicator = new FrmProgressIndicator("Movies Catalog generator", "Loading, please wait ...", toBeProcessedCount);
                formProgressIndicator.Argument = new KeyValuePair <Document, PdfGenParams>(document, pdfGenParams);
                formProgressIndicator.DoWork  += formPI_DoWork_GenerateMoviesCatalog;

                switch (formProgressIndicator.ShowDialog())
                {
                case DialogResult.Cancel:
                    result.Success            = false;
                    result.CustomErrorMessage = "Operation has been canceled";

                    return(result);

                case DialogResult.Abort:
                    result.Success            = false;
                    result.CustomErrorMessage = formProgressIndicator.Result.Error.Message;

                    return(result);

                case DialogResult.OK:
                    //var fillDoc = (Document)formProgressIndicator.Result.Result;
                    //MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "d:\\MigraDoc.pdf");

                    var pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);
                    pdfRenderer.Document = document;
                    pdfRenderer.RenderDocument();

                    pdfRenderer.PdfDocument.Save(pdfGenParams.FileName);

                    break;
                }
            }
            catch (Exception ex)
            {
                return(result.FailWithMessage(ex));
            }

            return(result);
        }
Пример #18
0
        public void Save(string filename, string password = null)
        {
            CreateDocument();

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true);

            renderer.Document = Pdf;
            renderer.RenderDocument();
            if (!string.IsNullOrEmpty(password))
            {
                SetPassword(renderer, password);
            }
            renderer.PdfDocument.Save(filename);
        }
Пример #19
0
        private PdfDocumentRenderer InitializeRenderer(string password)
        {
            CreateDocument();

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true);

            renderer.Document = Pdf;
            renderer.RenderDocument();
            if (!string.IsNullOrEmpty(password))
            {
                SetPassword(renderer, password);
            }
            return(renderer);
        }
Пример #20
0
 public void GeneratePDF(Factuur factuur)
 {
     this.factuur = factuur;
     // Create a new MigraDoc document
     CreateDocument();
     DefineStyles();
     CreatePage();
     FillContent();
     this.renderer     = new PdfDocumentRenderer();
     renderer.Document = document;
     renderer.RenderDocument();
     stream = new MemoryStream();
     renderer.PdfDocument.Save(stream, false);
 }
Пример #21
0
        public void CreateDocument(bool openDoc)//Lager et PDF DOKUMENT med MigraDoc biblioteket
        {
            Document doc     = new Document();
            Section  section = doc.AddSection();
            Table    table   = section.AddTable();

            table.Borders.Width   = 0.25;
            table.Rows.LeftIndent = 0;
            Column columnA = table.AddColumn("3cm");
            Column columnB = table.AddColumn("7cm");
            Column columnC = table.AddColumn("3cm");

            columnA.Format.Alignment = ParagraphAlignment.Center;
            columnB.Format.Alignment = ParagraphAlignment.Center;
            columnC.Format.Alignment = ParagraphAlignment.Center;
            Row row = table.AddRow();

            row.Cells[0].AddParagraph("Alarmtype");
            row.Cells[1].AddParagraph("Dato");
            row.Cells[2].AddParagraph("Verdi");

            for (int i = 0; i < dt.Rows.Count; i++)//en løkke som itererer igjennom alarm datatable og skriver alle aktive alarmer i et rutenett
            {
                row = table.AddRow();
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    if (j == 0)                                                   //Hvis det er første kolonne
                    {
                        AlarmType at = (AlarmType)Convert.ToInt32(dt.Rows[i][j]); //henter alarmtype med casting
                        row.Cells[j].AddParagraph(at.ToString());
                    }
                    else
                    {
                        row.Cells[j].AddParagraph(dt.Rows[i][j].ToString());
                    }
                }
            }

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(false);

            renderer.Document = doc;
            renderer.RenderDocument();
            filename = $"Alarmer{DateTime.Today.Day}_{DateTime.Today.TimeOfDay.Hours}.pdf";//Lager et filnavn

            renderer.PdfDocument.Save(filename);
            if (openDoc)
            {
                Process.Start(filename);//åpner dokumentet
            }
        }
Пример #22
0
        protected void SaveDocument(string migraDocName, string fileName)
        {
            DdlWriter.WriteToFile(_document, migraDocName);

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);

            renderer.Document = _document;

            renderer.RenderDocument();


            //  string filename = "HelloMigraDoc.pdf";
            renderer.PdfDocument.Save(fileName);
        }
Пример #23
0
        public PdfDocument BuildDocument(List <string> files)
        {
            _logger = LogManager.GetCurrentClassLogger();
            var document = new Document();
            var section  = document.AddSection();

            for (int i = 0; i < files.Count(); i++)
            {
                if (TryOpen(files[i], 3))
                {
                    var img = section.AddImage(files[i]);
                    img.LockAspectRatio = true;
                    img.Left            = -70;
                    if (img.Height > img.Width)
                    {
                        img.Height = document.DefaultPageSetup.PageHeight;
                    }
                    else
                    {
                        img.Width = document.DefaultPageSetup.PageWidth;
                    }

                    if (i < files.Count() - 1)
                    {
                        section.AddPageBreak();
                    }
                }
                else
                {
                    files.Remove(files[i]);
                }
            }

            var render = new PdfDocumentRenderer();

            render.Document = document;
            try
            {
                render.RenderDocument();
            }
            catch (Exception e)
            {
                _logger.Error(e.ToString());

                throw;
            }

            return(render.PdfDocument);
        }
        public byte[] CreateReport(DublinCore citation, List <RepositoryItemMetadata> items, RepositoryClientBase client)
        {
            // Get identification for all the DDI variables in the item list.
            var variableIDs = items
                              .Where(x => x.ItemType == DdiItemType.Variable)
                              .Select(x => x.CompositeId)
                              .ToIdentifierCollection();

            // Fetch all the variables.
            var allVariables = client.GetItems(variableIDs)
                               .OfType <Variable>();

            // Use the Colectica.Reporting MigraDoc helper to create a PDF that
            // simply lists all variables with their names, labels, and types.
            var document = new Document();

            document.Info.Title = "Sample Variable Summary";

            // Add a title.
            var section   = document.AddSection();
            var paragraph = section.AddParagraph(citation.Title.Best);

            paragraph.Format.Font.Bold = true;

            // Create the report helper.
            ReportContext context = new ReportContext();
            var           builder = new ItemBuilderBase(document, context);

            // Make a list with one item for each variable.
            builder.DefineList();
            foreach (var variable in allVariables)
            {
                string lineText = $"{variable.ItemName.Best} - {variable.Label.Best} - {variable.RepresentationType}";
                builder.AddListItem(lineText);
            }

            // Render the PDF and return it.
            var pdfRenderer = new PdfDocumentRenderer(true);

            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();

            using (var stream = new MemoryStream())
            {
                pdfRenderer.Save(stream, true);
                var fileContents = stream.ToArray();
                return(fileContents);
            }
        }
Пример #25
0
        public static string Render()
        {
            string filename = null;

            try
            {
                // Create an invoice form with the sample invoice data.
                var invoice = new MigraForm("D:\\invoice.xml");

                // Create the document using MigraDoc.
                var document = invoice.CreateDocument();
                document.UseCmykColor = true;

                #if DEBUG
                // For debugging only...
                MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");
                var document2 = MigraDoc.DocumentObjectModel.IO.DdlReader.DocumentFromFile("MigraDoc.mdddl");
                //document = document2;
                // With PDFsharp 1.50 beta 3 there is a known problem: the blank before "by" gets lost while persisting as MDDDL.
#endif
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                var enc1252 = Encoding.GetEncoding(1252);

                // Create a renderer for PDF that uses Unicode font encoding.
                var pdfRenderer = new PdfDocumentRenderer(true);

                // Set the MigraDoc document.
                pdfRenderer.Document = document;

                // Create the PDF document.
                pdfRenderer.RenderDocument();

                // Save the PDF document...
                filename = "Invoice.pdf";
                #if DEBUG
                // I don't want to close the document constantly...
                filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf";
                #endif
                pdfRenderer.Save(filename);
                // ...and start a viewer.
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }

            return(filename);
        }
Пример #26
0
        /// <summary>
        /// Tests borders.
        /// </summary>
        public static void Borders(string outputFile)
        {
            Document  document = new Document();
            Section   section  = document.AddSection();
            Paragraph par      = section.AddParagraph();

            FillFormattedParagraph(par);
            GiveBorders(par);

            PdfDocumentRenderer renderer = new PdfDocumentRenderer();

            renderer.Document = document;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(outputFile);
        }
 public void Save(string filename)
 {
     try
     {
         MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(m_document, "MigraDoc.mdddl");
         PdfDocumentRenderer renderer = new PdfDocumentRenderer(true);
         renderer.Document = m_document;
         renderer.RenderDocument();
         renderer.PdfDocument.Save(filename);
     }
     catch (Exception e)
     {
         Console.WriteLine("Error saving the PDF file:\n" + e.ToString());
     }
 }
Пример #28
0
        /// <summary>
        /// Closes this instance.
        /// </summary>
        public virtual void Close()
        {
            if (this.isClosed)
            {
                return;
            }

            var r = new PdfDocumentRenderer {
                Document = this.Document
            };

            r.RenderDocument();
            r.PdfDocument.Save(this.FileName);
            this.isClosed = true;
        }
Пример #29
0
        private void SavePDF()
        {
            // Create a renderer
            bool unicode = true;
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode);

            // Associate the MigraDoc document with a renderer
            pdfRenderer.Document = document;

            // Layout and render document to PDF
            pdfRenderer.RenderDocument();

            // Save the document
            pdfRenderer.PdfDocument.Save(fileName);
        }
Пример #30
0
    public string Rendering()
    {
        PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true)
        {
            Document = document
        };

        pdfRenderer.RenderDocument();
        string filename = string.Format("Cotizacion_{0}.pdf", Cotizacion.IT);
        string basePath = HttpContext.Current.Server.MapPath("~/cotizaciones/");
        string path     = basePath + filename;

        pdfRenderer.PdfDocument.Save(path);
        return(filename);
    }
Пример #31
0
        public PdfDocument getPDFDocument()
        {
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always);

            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();
            try
            {
                return(pdfRenderer.PdfDocument);
            }
            catch
            {
                return(null);
            }
        }
Пример #32
0
        public void MakePdf(string filename, bool execute = false, bool unicode = true)
        {
            var doc      = ClonedDocument();
            var renderer = new PdfDocumentRenderer(unicode)
            {
                Document = doc
            };

            renderer.RenderDocument();
            renderer.PdfDocument.Save(filename);
            if (execute)
            {
                Process.Start(filename);
            }
        }
Пример #33
0
 /// <summary>
 /// Tests texts and blanks.
 /// </summary>
 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());
     }
     PdfDocumentRenderer renderer = new PdfDocumentRenderer();
     renderer.Document = document;
     renderer.RenderDocument();
     renderer.PdfDocument.Save(pdfOutputFile);
 }
Пример #34
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);
            }
            PdfDocumentRenderer renderer = new PdfDocumentRenderer();
            renderer.Document = doc;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(outputFile);
        }
Пример #35
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";

            PdfDocumentRenderer renderer = new PdfDocumentRenderer();
            renderer.Document = doc;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(outputFile);
        }
Пример #36
0
        /// <summary>
        /// Tests alignments.
        /// </summary>
        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";
            PdfDocumentRenderer renderer = new PdfDocumentRenderer();
            renderer.Document = document;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(pdfOutputFile);
        }
Пример #37
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.");


            PdfDocumentRenderer renderer = new PdfDocumentRenderer();
            renderer.Document = document;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(outputFile);
        }
Пример #38
0
        /// <summary>
        /// Tests document fields.
        /// </summary>
        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");

            PdfDocumentRenderer renderer = new PdfDocumentRenderer();
            renderer.Document = document;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(outputFile);
        }
Пример #39
0
        /// <summary>
        /// Tests borders.
        /// </summary>
        public static void Borders(string outputFile)
        {
            Document document = new Document();
            Section section = document.AddSection();
            Paragraph par = section.AddParagraph();
            FillFormattedParagraph(par);
            GiveBorders(par);

            PdfDocumentRenderer renderer = new PdfDocumentRenderer();
            renderer.Document = document;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(outputFile);
        }
Пример #40
0
 /// <summary>
 /// Tests tab stops.
 /// </summary>
 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.");
     PdfDocumentRenderer renderer = new PdfDocumentRenderer();
     renderer.Document = document;
     renderer.RenderDocument();
     renderer.PdfDocument.Save(pdfOutputFile);
 }