예제 #1
1
        public byte[] MakeSpectacleSchedule(IEnumerable<SpectacledayTimeSlot> spectacleDayTimeSlots,
										  IEnumerable<Performance> performances,
										  IEnumerable<Area> areas,
										  IEnumerable<Venue> venues,
										  IEnumerable<TimeSlot> timeSlots,
										  IEnumerable<Artist> artists)
        {
            this.spectacleDayTimeSlots = spectacleDayTimeSlots;
            this.performances = performances;
            this.areas = areas;
            this.venues = venues;
            this.timeSlots = timeSlots;
            this.artists = artists;
            Document document = CreateDocument();
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);
            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();

            try {
                MemoryStream s = new MemoryStream();
                pdfRenderer.PdfDocument.Save(s);
                return s.ToArray();
            } catch (Exception e) {
                throw new BusinessLogicException($"Could not save PDF-File ({e.Message})");
            }
        }
예제 #2
0
        public static void CreatePDFDocument(ArticlesWithWordMigra article) {
             // Create a MigraDoc document
            Document document = PDFServices.CreateDocument(article);         
            //string ddl = MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToString(document);
            MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");
            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
            renderer.Document = document;       
            renderer.RenderDocument();
            var extension = ".pdf";
            // Save the document...
            string filename = article.DatePublished.ToString("yyyy-MM-dd")+" " + article.Author;
            var fileCreated = false;
            var FileNameCounter = 0;
           
            while (!fileCreated)
            {

                DirectoryInfo di = new DirectoryInfo(Directory.GetCurrentDirectory());
                FileInfo[] PDFFiles = di.GetFiles(filename + extension);
                if (PDFFiles.Length == 0)
                {
                    renderer.PdfDocument.Save(filename+ extension);
                    fileCreated = true;
                }
                else
                {
                    FileNameCounter = FileNameCounter + 1;
                    filename = filename+'('+ FileNameCounter+')';
                }
            }
            //// ...and start a viewer.
            //Process.Start(filename);
        }
예제 #3
0
        void Run()
        {
            if (File.Exists(outputName))
            {
                File.Delete(outputName);
            }

            var doc = new Document();
            doc.DefaultPageSetup.Orientation = Orientation.Portrait;
            doc.DefaultPageSetup.PageFormat = PageFormat.A4;
            //doc.DefaultPageSetup.LeftMargin = Unit.FromMillimeter(5.0);
            //doc.DefaultPageSetup.RightMargin = Unit.FromMillimeter(5.0);
            //doc.DefaultPageSetup.BottomMargin = Unit.FromMillimeter(5.0);
            //doc.DefaultPageSetup.TopMargin = Unit.FromMillimeter(5.0);
            StyleDoc(doc);
            var section = doc.AddSection();
            var footer = new TextFrame();

            section.Footers.Primary.Add(footer);
            var html = File.ReadAllText("example.html");
            section.AddHtml(html);

            var renderer = new PdfDocumentRenderer();
            renderer.Document = doc;
            renderer.RenderDocument();

            renderer.Save(outputName);
            Process.Start(outputName);
        }
예제 #4
0
파일: PDFExport.cs 프로젝트: ORRNY66/GS
        public string CreatePDFFile(Stone stone)
        {
            string filename = stone.FullFilePath+".pdf";

            Document document = this.CreateDocument();

            DefineStyles();
            PlaceImage(stone);

            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);

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

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

            SaveFileDialog savedlg = new SaveFileDialog();
            savedlg.DefaultExt = ".pdf";

               // Save the PDF document...
            if (savedlg.ShowDialog() == true)
            {
                filename = savedlg.FileName;
                pdfRenderer.Save(filename);
                Process.Start(filename);
                return filename;
            }
            else
            {
                return "";
            }

                    // ...and start a viewer.
        }
예제 #5
0
        public static void CreateFile(Result result, string filePath)
        {
            // Create a MigraDoc document
            Document document = CreateDocument(result);
            document.UseCmykColor = true;

            // 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;

            // An enum indicating whether to embed fonts or not.
            // This setting applies to all font programs used in the document.
            // This setting has no effect on the RTF renderer.
            // (The term 'font program' is used by Adobe for a file containing a font. Technically a 'font file'
            // is a collection of small programs and each program renders the glyph of a character when executed.
            // Using a font in PDFsharp may lead to the embedding of one or more font programms, because each outline
            // (regular, bold, italic, bold+italic, ...) has its own fontprogram)
            const PdfFontEmbedding embedding = PdfFontEmbedding.Always;

            // Create a renderer for the MigraDoc document.
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);
            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();
            pdfRenderer.PdfDocument.Save(filePath);
        }
예제 #6
0
파일: PDFExport.cs 프로젝트: ORRNY66/GS
        public string CreateRawPDFinTemp(Stone stone)
        {
            string filename = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(stone.Filename) + ".pdf");

            Document document = this.CreateDocument();

            DefineStyles();
            PlaceImage(stone);

            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);

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

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

               pdfRenderer.Save(filename);

               if (File.Exists(filename))
               {
               return filename;
               }
               else
               {
               return String.Empty;
               }

            // ...and start a viewer.
        }
        public Boolean Convert(String inputFileName, String outputFileName)
        {
            try
            {
                var text = File.ReadAllText(inputFileName);

                // Create a MigraDoc document
                Document document = new Document();
                var section = document.AddSection();
                var paragraph = section.AddParagraph();
                paragraph.Format.Font.Size = 12;
                paragraph.AddFormattedText(text);


                PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);
                pdfRenderer.Document = document;
                pdfRenderer.RenderDocument();
                pdfRenderer.PdfDocument.Save(outputFileName);
                return true;
            }
            catch (Exception ex)
            {
                Logger.WarnFormat(ex, "Error converting file {0} to Pdf.", inputFileName);
                return false;
            }
        }
예제 #8
0
        public void CreateDocument(DataTable dt, string filename)
        {
            // Create a new MigraDoc document
            this.document = new Document();
            this.document.Info.Title = "A sample invoice";
            this.document.Info.Subject = "Demonstrates how to create an invoice.";
            this.document.Info.Author = "Stefan Lange";

            DefineStyles();

            CreatePage();

            FillContent(dt);

            // 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";

            // I don't want to close the document constantly...
            //filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf";

            pdfRenderer.Save(filename);
            // ...and start a viewer.
            //Process.Start(filename);
        }
예제 #9
0
        ////--------------------------------
        //public ImageReportPDF(IDictionary<string, MyImage> _LoadedImgFiles, string _ReportTitle, string _ReportSummary)
        //{
        //    LoadedImgFiles = _LoadedImgFiles;
        //    ReportTitle = _ReportTitle;
        //    ReportSummary = _ReportSummary;
        //}
        ////--------------------------------
        //public ImageReportPDF(string _FilePath, string _FileName)
        //{
        //    FilePath = _FilePath;
        //    FileName = _FileName;
        //}
        //-------------------------------
        //-------------------------------
        public string GeneratePDFReport()
        {
            try
            {
                // Create a MigraDoc document
                //Document document = pdf.CreateDocument();
                Document document = CreateDocument();

                document.UseCmykColor = true;

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

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

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

                // Save the PDF document...
                string filename = PDFFilePath + "\\" + PDFFileName + ".pdf";

                pdfRenderer.Save(filename);
                // ...and start a viewer.
                //  Process.Start(filename);

                return "";

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
예제 #10
0
        public string crearPdf(string[] fotos)
        {

            Document document = new Document();
            PdfDocument pdfDocument = new PdfDocument();
            document.DefaultPageSetup.PageFormat = PageFormat.A4;
            document.DefaultPageSetup.LeftMargin = "1cm";
            document.DefaultPageSetup.TopMargin = "1cm";
            setDocumentStyle(ref document);
            string footerText = "LISTADO DE CODIGO DE BARRAS POR PROPIETARIO CON NIT Y NUMERO DE UNIDAD ";
            setDocumentHeaders2(
                 ref document,
                 footerText
            );
            foreach (string foto in fotos)
            {
                document.LastSection.AddImage(foto);
                
              //document.Section.AddImage(foto);
              //deja codigo de barras por pagina document.AddSection();
              //duplica la imagendocument.LastSection.AddImage(foto);
            }
            PdfDocumentRenderer pdfDocumentRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);
            pdfDocumentRenderer.Document = document;
            pdfDocumentRenderer.RenderDocument();
            string filename = "archivopdf\\ARCHIVO_CODIGO_DE_BARRAS.pdf";
            pdfDocumentRenderer.PdfDocument.Save(filename);
            return filename;
            }
예제 #11
0
        public static void SaveAll(Document doc, string path)
        {
            try
            {
                MigraDoc.Rendering.PdfDocumentRenderer docRend = new MigraDoc.Rendering.PdfDocumentRenderer(false);

                docRend.Document = doc;


                docRend.RenderDocument();

                string someName = GenerateWord.Generate(4);

                string FileName = "rel" + someName + ".pdf";

                docRend.PdfDocument.Save(path + "\\" + FileName);

                System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo();

                procInfo.FileName = path + "\\" + FileName;

                System.Diagnostics.Process.Start(procInfo);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Ocorreu algo errado", "Aviso", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                throw ex;
            }
        }
예제 #12
0
파일: Form1.cs 프로젝트: DavidS/MigraDoc
 private static void OpenPdf(Document doc)
 {
     var filename = "c:\\temp\\test.pdf";
     PdfDocumentRenderer pdf = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.None);
     pdf.Document = doc;
     pdf.RenderDocument();
     pdf.Save(filename);
     ShellExecute(filename, "");
 }
예제 #13
0
 public void GenerateFSD(string strProID, string strProTitle, string strProType, List<RevisionHistory> listRevisionHistory, string strProObjective, string strProAppName, string[] strArrayProDatabase, string[] strArrayProMiddleware, string[] strArrayProPicturePathTopology, string[] strArrayProPicturePathMenuRelation, string[] strArrayProPicturePathDatabaseDiagram, List<Solution> listSolution, string[] strArrayProJobBatch, string[] strArrayProParam, List<Attachment> listAttachment, string strProTestScenario, string strProOtherInfo, List<Approval> listApproval)
 {
     Document document = CreateDocument(strProID, strProTitle, strProType, listRevisionHistory, strProObjective, strProAppName, strArrayProDatabase, strArrayProMiddleware, strArrayProPicturePathTopology, strArrayProPicturePathMenuRelation, strArrayProPicturePathDatabaseDiagram, listSolution, strArrayProJobBatch, strArrayProParam, listAttachment, strProTestScenario, strProOtherInfo, listApproval);
     PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
     renderer.Document = document;
     renderer.RenderDocument();
     string filename = strProID + " - " + strProTitle + ".pdf";
     renderer.PdfDocument.Save(filename);
     Process.Start(filename);
 }
예제 #14
0
 public void GenerateCDS(string strProID , string strProTitle, string strProCDS, string strProType, string strProModule, DateTime datetimeProDate, List<RevisionHistory> listRevisionHistory, string strProObjective, string strProAppName, string[] strArrayProDatabase, string[] strArrayProMiddleware, List<LinkTable> listLinkTable, string[] strArrayProPicturePathDatabaseDiagram, string[] strArrayProPicturePathTopology, List<Scenario> listPositiveScenario, List<Scenario> listNegativeScenario, string strProOtherInfo, List<Approval> listApproval)
 {
     Document document = CreateDocument(strProID, strProTitle, strProCDS, strProType, strProModule, datetimeProDate, listRevisionHistory, strProObjective, strProAppName, strArrayProDatabase, strArrayProMiddleware, listLinkTable, strArrayProPicturePathDatabaseDiagram, strArrayProPicturePathTopology, listPositiveScenario, listNegativeScenario, strProOtherInfo, listApproval);
     PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
     renderer.Document = document;
     renderer.RenderDocument();
     string filename = strProID + " - " + strProTitle + ".pdf";
     renderer.PdfDocument.Save(filename);
     Process.Start(filename);
 }
예제 #15
0
 public void GenerateBRD(string strProID, string strProTitle, string strProBRD, string strProSFAT, string strProITRoadMap, DateTime datetimeProDate, string strProBAName, string strProBUName, string strProBUEmail, string strProBUDivision, string strProBUOfficeID, string strProBUCostCenter, List<RevisionHistory> listRevisionHistory, List<Approval> listApproval, List<DistributionList> listDistributionList, List<Glossary> listGlossary, string strProOverview, string strProDependencies, List<Stakeholder> listStakeholder, List<CurrentBFD> listCurrentBFD, List<ProposedBFD> listProposedBFD, List<ProposedReportAvailable> listProposedReportAvailable, List<SecurityRequirement> listSecurityRequirement, List<BackupRequirement> listBackupRequirement, string[] strArrayProUMMenu, string[] strArrayProUMDiv, bool[][] boolMatrixProUM, List<Assumption> listAssumption, List<Appendix> listAppendix)
 {
     Document document = CreateDocument(strProID, strProTitle, strProBRD, strProSFAT, strProITRoadMap, datetimeProDate, strProBAName, strProBUName, strProBUEmail, strProBUDivision, strProBUOfficeID, strProBUCostCenter, listRevisionHistory, listApproval, listDistributionList, listGlossary, strProOverview, strProDependencies, listStakeholder, listCurrentBFD, listProposedBFD, listProposedReportAvailable, listSecurityRequirement, listBackupRequirement, strArrayProUMMenu, strArrayProUMDiv, boolMatrixProUM, listAssumption, listAppendix);
     PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
     renderer.Document = document;
     renderer.RenderDocument();
     string filename = strProID + " - " + strProTitle + ".pdf";
     renderer.PdfDocument.Save(filename);
     Process.Start(filename);
 }
예제 #16
0
 public PDFDocumentBuilder()
 {
     document = new Document();
     const bool unicode = true;
     pdfRenderer = new PdfDocumentRenderer(unicode);
     document.Info.Title = "Search results";
     document.Info.Author = "Zajęcia projektowe z TO grupa 9:30 Wtorek";
     DefineStyles(document);
     pdfRenderer.Document = document;
     section = document.AddSection();
 }
예제 #17
0
    private void CreatePdf_Click(object sender, RoutedEventArgs e)
    {
      PdfDocumentRenderer printer = new PdfDocumentRenderer();
      printer.DocumentRenderer = preview.Renderer;
      printer.Document = preview.Document;
      printer.RenderDocument();
      preview.Document.BindToRenderer(null);
      printer.Save("test.pdf");

      Process.Start("test.pdf");
    }
예제 #18
0
		public override void CreerDocumentInscription() {
			var document = new Document();
			document.UseCmykColor = true;

			var inscription = new InscriptionDocument(document, this._donnees);
			inscription.GenererContenuDocument();

			var pdfRenderer = new PdfDocumentRenderer(Unicode, Embedding);
			pdfRenderer.Document = document;
			pdfRenderer.RenderDocument();
			pdfRenderer.PdfDocument.Save(this._savePath);
		}
예제 #19
0
        private void writeDocument()
        {
            PdfDocumentRenderer renderer = new PdfDocumentRenderer();

            renderer.Document = document;

            renderer.PdfDocument = pdfDocument;

            renderer.RenderDocument();

            renderer.PdfDocument.Save(fileOut);
        }
예제 #20
0
        public void saveDocument(string filePath)
        {
            // Create a renderer for the MigraDoc document.
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always);

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

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

            // Save the document...
            pdfRenderer.PdfDocument.Save(filePath);
        }
 public void Export(List<domain.Product> productList, decimal euro2cny, decimal serviceRate)
 {
     Document document = CreateDocument(productList,euro2cny,serviceRate);
     string ddl = MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToString(document);          
  
     bool unicode = true;
     PdfFontEmbedding embedding = PdfFontEmbedding.Always;  
               
     PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);            
     pdfRenderer.Document = document;           
     pdfRenderer.RenderDocument();            
     string filename = Guid.NewGuid().ToString() + ".pdf";
     pdfRenderer.PdfDocument.Save(filename);            
     Process.Start(filename);
 }
예제 #22
0
        public static void GenerateDocument(string filePath, List<QueryData> data)
        {
            Document document = CreateDocument(data);
            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...
            string filename = data[0].ProjectName + "_Validation_" + DateTime.Now.ToShortDateString() + ".pdf";
            renderer.PdfDocument.Save(filename);
            // ...and start a viewer.
            Process.Start(filename);
        }
예제 #23
0
        public static void ExportSchedulePage(
            Dictionary<int, Dictionary<string, Dictionary<int, Tuple<string, List<Tuple<Lesson, int>>, string>>>> schedule,
            string facultyName,
            string filename,
            string dow,
            ScheduleRepository repo,
            bool save,
            bool quit,
            bool print)
        {
            double scheduleFontsize = 10;
            int pageCount;
            Document document;
            do
            {
                // Create a new PDF document
                document = CreateDocument(repo, facultyName, dow, schedule, scheduleFontsize);

                // Create a renderer and prepare (=layout) the document
                var docRenderer = new DocumentRenderer(document);
                docRenderer.PrepareDocument();
                pageCount = docRenderer.FormattedDocument.PageCount;

                scheduleFontsize -= 0.5;
            } while (pageCount > 1);

            // Render the file
            var pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always) {Document = document};
            pdfRenderer.RenderDocument();

            // Save the document...
            if (save)
            {
                pdfRenderer.PdfDocument.Save(filename);
            }
            // ...and start a viewer.
            //Process.Start(filename);

            if (print)
            {
                if (!save)
                {
                    pdfRenderer.PdfDocument.Save(filename);
                }

                SendToPrinter(filename);
            }
        }
예제 #24
0
        public bool WritePDFReport(string FilePath)
        {
            //try
            //{
                // Create a invoice form with the sample invoice data

               InvoiceForm invoice = new InvoiceForm(FilePath + "\\Invoice.xml");

                // Create a MigraDoc document
                Document document = invoice.CreateDocument();
                document.UseCmykColor = true;

                //        #if DEBUG
                //                // for debugging only...
                //                MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");
                //                document = MigraDoc.DocumentObjectModel.IO.DdlReader.DocumentFromFile("MigraDoc.mdddl");
                //        #endif

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

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

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

                // Save the PDF document...
                string filename = FilePath + "\\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.
                //  Process.Start(filename);

            //}
            //catch (Exception ex)
            //{
            //    ex.
            //    //Console.WriteLine(ex.Message);
            //    //Console.ReadLine();
            //}

            return true;
        }
예제 #25
0
        public void Save()
        {
            // Create a MigraDoc document
            Document document = Documents.CreateDocument();

            // Write to Data Definition Language
            MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");

            // Render the document
            PdfDocumentRenderer render = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
            render.Document = document;
            render.RenderDocument();

            // Save the document
            render.PdfDocument.Save(Report.fileName);
        }
        private void SaveDocument()
        {
            var pdfRenderer = new PdfDocumentRenderer(true);

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

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

            // Save the document...
            var filename = "Invoice.pdf";
            pdfRenderer.PdfDocument.Save(filename);

            Process.Start(filename);
        }
예제 #27
0
    static void Main()
    {
      // Create a MigraDoc document
      Document document = CreateDocument();
      document.UseCmykColor = true;

     // string ddl = MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToString(document);

#if true_
      RtfDocumentRenderer renderer = new RtfDocumentRenderer();
      renderer.Render(document, "HelloWorld.rtf", null);
#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 = false;

      // An enum indicating whether to embed fonts or not.
      // This setting applies to all font programs used in the document.
      // This setting has no effect on the RTF renderer.
      // (The term 'font program' is used by Adobe for a file containing a font. Technically a 'font file'
      // is a collection of small programs and each program renders the glyph of a character when executed.
      // Using a font in PDFsharp may lead to the embedding of one or more font programms, because each outline
      // (regular, bold, italic, bold+italic, ...) has its own fontprogram)
      const PdfFontEmbedding embedding = PdfFontEmbedding.Always;

      // ----------------------------------------------------------------------------------------

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

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

      // 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);
    }
예제 #28
0
        public async Task<List<string>> RunAsync()
        {
            _document = new Document();

            try
            {
                SetStyles();

                CoverPage();

                TableOfContents();

                BasicInfo();

                await DiscussionBackground();

                DiscussionBgMediaTable();

                DiscussionBgSourcesTable();

                await FinalScene();

                Summary(_hardReportTask.Result);

                AllArgPoints();

                ClusterInformation(await _hardReportTask);

                LinkInformation(_hardReportTask.Result);

                PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always);
                pdfRenderer.Document = _document;
                pdfRenderer.RenderDocument();
                pdfRenderer.PdfDocument.Save(_PdfPathName);

                Process.Start(_PdfPathName);
            }
            catch (Exception e)
            {
                MessageDlg.Show(e.StackTrace);
            }

            return _images;
        }
예제 #29
0
        /// <summary>
        /// Returns a memory stream that represents this invoice in pdf form
        /// Based on code from http://www.pdfsharp.net/wiki/Default.aspx?Page=Invoice-sample&NS=&AspxAutoDetectCookieSupport=1 as well as associated methods
        /// </summary>
        /// <returns>A memory stream containing a pdf</returns>
        public MemoryStream ToPdf()
        {
            // Create a new MigraDoc document
            var document = new Document();
            // Each MigraDoc document needs at least one section.
            // main content
            Section section = document.AddSection();
            document.Info.Title = "Invoice #"+id;

            // we have to put it in a file first because this thing only works on file paths
            var fileName = Path.GetTempFileName();
            SettingsData.Default.InvoiceLogo.Save(fileName);

            DefineStyles(document);
            CreateSectionIntro(section, fileName);
            AddAddressFrame(section);
            AddDateFields(section);
            var table = CreateTableWithHeader(section);
            PopulateTable(table);

            if (SettingsData.Default.NoteAfterInvoiceItemList != null)
            {
                // Add the notes paragraph
                var paragraph = document.LastSection.AddParagraph();
                paragraph.Format.SpaceBefore = "1cm";
                paragraph.Format.Borders.Width = 0.75;
                paragraph.Format.Borders.Distance = 3;
                paragraph.Format.Borders.Color = Colors.Black;
                paragraph.Format.Shading.Color = Colors.LightGray;
                paragraph.AddText(SettingsData.Default.NoteAfterInvoiceItemList);
            }

            var renderer = new PdfDocumentRenderer(true) {Document = document};
            renderer.PrepareRenderPages();
            renderer.RenderDocument();
            var pdf = renderer.PdfDocument;
            File.Delete(fileName);

            var ms = new MemoryStream();
            pdf.Save(ms, false);
            ms.Seek(0, SeekOrigin.Begin); // reset the stream to the beginning
            return ms;
        }
예제 #30
0
    static void Main()
    {
      try
      {
        // Create a invoice form with the sample invoice data
        InvoiceForm invoice = new InvoiceForm("../../invoice.xml");

        // Create a MigraDoc document
        Document document = invoice.CreateDocument();
        document.UseCmykColor = true;

#if DEBUG
        // for debugging only...
        MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");
        document = MigraDoc.DocumentObjectModel.IO.DdlReader.DocumentFromFile("MigraDoc.mdddl");
#endif

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

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

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

        // Save the PDF document...
        string 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.
        Process.Start(filename);
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message);
        Console.ReadLine();
      }
    }
예제 #31
0
        public void CanGeneratePrettyReport()
        {
            var data = GetTestData();

            var atlanticData = GetDivision("Atlantic", data);
            var centralData = GetDivision("Central", data);

            var doc = new Document();
            var section = doc.AddSection();

            var title = section.AddParagraph("Standings");
            title.Format.Font.Size = Unit.FromPoint(16);
            title.Format.Font.Underline = Underline.Single;
            title.Format.Alignment = ParagraphAlignment.Center;
            title.Format.SpaceAfter = Unit.FromPoint(12);

            var atlanticHeading = section.AddParagraph("Atlantic Division");
            atlanticHeading.Format.Font.Bold = true;
            atlanticHeading.Format.Borders.Bottom.Color = Colors.Black;
            atlanticHeading.Format.Borders.Bottom.Width = Unit.FromPoint(1);
            section.AddParagraph();

            var atlanticTable = AddDivisionTableTo(section, "Atlantic");
            section.AddParagraph();

            var centralHeading = section.AddParagraph("Cental Division");
            centralHeading.Format.Font.Bold = true;
            centralHeading.Format.Borders.Bottom.Color = Colors.Black;
            centralHeading.Format.Borders.Bottom.Width = Unit.FromPoint(1);
            section.AddParagraph();

            var centralTable = AddDivisionTableTo(section, "Central");

            PopulateDivisionTable(atlanticTable, atlanticData);
            PopulateDivisionTable(centralTable, centralData);

            var pdfRenderer = new PdfDocumentRenderer();
            pdfRenderer.Document = doc;
            pdfRenderer.RenderDocument();

            pdfRenderer.Save(@"standings.pdf");
        }
예제 #32
0
        public void CreateCharacterCertificatePDF(string[] CertificateData, string admNo, int admYear)
        {
            if (CertificateData.Length != 5)
            {
                return;
            }
            else
            {
                // Generate nmhs-nexap directory in my document folder
                string containerfolder  = this.GenerateDocumentBaseDirectory();
                MigraModel.Document doc = new MigraModel.Document();
                MigraModel.Section  sec = doc.AddSection();
                sec.PageSetup           = doc.DefaultPageSetup.Clone();
                sec.PageSetup.TopMargin = ".7cm";

                MigraDoc.DocumentObjectModel.Shapes.TextFrame tframe = sec.AddTextFrame();
                tframe.AddImage("nmhs-logo.jpg");
                tframe.Left               = "-.5cm";
                tframe.Top                = "0.7cm";
                tframe.RelativeVertical   = MigraModel.Shapes.RelativeVertical.Page;
                tframe.RelativeHorizontal = MigraModel.Shapes.RelativeHorizontal.Margin;

                MigraModel.Paragraph paraSchoolName = sec.AddParagraph();
                paraSchoolName.Format.Font.Name  = "Times New Roman";
                paraSchoolName.Format.Alignment  = MigraModel.ParagraphAlignment.Center;
                paraSchoolName.Format.Font.Size  = 25;
                paraSchoolName.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkBlue;
                string schoolName = "NAIMOUZA HIGH SCHOOL";
                paraSchoolName.AddFormattedText(schoolName, MigraModel.TextFormat.Bold);

                MigraModel.Paragraph paraSchoolAddress = sec.AddParagraph();
                paraSchoolAddress.Format.Font.Size = 14;
                paraSchoolAddress.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                string addrs = "Vill. & P.O. Sujapur, Dist. Malda, 732206";
                paraSchoolAddress.AddText(addrs);

                MigraModel.Paragraph paraSchoolMeta = sec.AddParagraph();
                paraSchoolMeta.Format.Font.Size = 10;
                paraSchoolMeta.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                string meta = "INDEX NO. - R1-110, CONTACT NO. - 03512-246525";
                paraSchoolMeta.AddFormattedText(meta, MigraModel.TextFormat.NotBold);

                MigraModel.Paragraph paraAdmissionMeta = sec.AddParagraph();
                paraAdmissionMeta.Format.Font.Size = 10;
                paraAdmissionMeta.Format.Alignment = MigraModel.ParagraphAlignment.Right;
                string admYr = (admYear != 0) ? admYear.ToString() : "0000";
                string ameta = "Admission Sl. " + admNo + " of " + admYr;
                paraAdmissionMeta.AddFormattedText(ameta, MigraModel.TextFormat.Bold);

                MigraModel.Paragraph paraCertificateType = sec.AddParagraph();
                paraCertificateType.Format.Font.Size = 18;
                paraCertificateType.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                paraCertificateType.AddLineBreak();
                string ctype = "CHARACTER CERTIFICATE";
                paraCertificateType.AddFormattedText(ctype, MigraModel.TextFormat.NotBold);

                MigraModel.Paragraph para_a = sec.AddParagraph();
                para_a.Format.Font.Name  = "Lucida Handwriting";
                para_a.Format.Font.Size  = 16;
                para_a.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_a.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_a.AddLineBreak();
                para_a.AddLineBreak();
                para_a.AddLineBreak();
                para_a.AddLineBreak();
                para_a.AddTab();

                string para_aText, para_aTextb, paraTextc, paraTextd, stdName;
                para_aText  = CertificateData[0].Trim();
                para_aTextb = CertificateData[1].Trim();
                paraTextc   = CertificateData[2].Trim();
                paraTextd   = CertificateData[3].Trim();
                stdName     = CertificateData[4].Trim();

                para_a.AddText(para_aText);

                MigraModel.Paragraph para_b = sec.AddParagraph();
                para_b.Format.Font.Name  = "Lucida Handwriting";
                para_b.Format.Font.Size  = 16;
                para_b.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_b.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_b.AddLineBreak();
                para_b.AddTab();
                para_b.AddText(para_aTextb);

                MigraModel.Paragraph para_c = sec.AddParagraph();
                para_c.Format.Font.Name  = "Lucida Handwriting";
                para_c.Format.Font.Size  = 16;
                para_c.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_c.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_c.AddLineBreak();
                para_c.AddTab();
                para_c.AddText(paraTextc);

                MigraModel.Paragraph para_d = sec.AddParagraph();
                para_d.Format.Font.Name  = "Lucida Handwriting";
                para_d.Format.Font.Size  = 16;
                para_d.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_d.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_d.AddLineBreak();
                para_d.AddTab();
                para_d.AddText(paraTextd);


                MigraDoc.DocumentObjectModel.Shapes.TextFrame tframeHMaster = sec.AddTextFrame();
                MigraModel.Paragraph paraHMaster = tframeHMaster.AddParagraph();
                paraHMaster.Format.Font.Size = "14";
                paraHMaster.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                string txt1 = "Headmaster";
                string txt2 = "Naimuza High School";
                string txt3 = "Sujapur, Malda";
                paraHMaster.AddText(txt1);
                paraHMaster.AddLineBreak();
                paraHMaster.AddText(txt2);
                paraHMaster.AddLineBreak();
                paraHMaster.AddText(txt3);
                tframeHMaster.Width              = "6cm";
                tframeHMaster.Left               = "10cm";
                tframeHMaster.Top                = "19cm";
                tframeHMaster.RelativeVertical   = MigraModel.Shapes.RelativeVertical.Page;
                tframeHMaster.RelativeHorizontal = MigraModel.Shapes.RelativeHorizontal.Margin;

                MigraDoc.Rendering.PdfDocumentRenderer docRend = new MigraDoc.Rendering.PdfDocumentRenderer(false);
                docRend.Document = doc;
                try
                {
                    docRend.RenderDocument();
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show(e.Message);
                    return;
                }
                string fname      = "CHR_" + stdName + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".pdf";
                string pathString = Path.Combine(containerfolder, fname);
                docRend.PdfDocument.Save(pathString);

                System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo();
                processInfo.FileName = pathString;
                System.Diagnostics.Process.Start(processInfo);
            }
        }