Example #1
0
        public static void Run()
        {
            // 帳票定義ファイルを読み込みます
            Report report = new Report(Json.Read("report\\example2.rrpt"));

            // GlobalScopeに値を登録します
            report.GlobalScope.Add("startDate", DateTime.ParseExact("2013/02/01", "yyyy/MM/dd", null));
            report.GlobalScope.Add("endDate", DateTime.ParseExact("2013/02/28", "yyyy/MM/dd", null));
            report.GlobalScope.Add("printDate", DateTime.Today);
            report.GlobalScope.Add("kaisha", "株式会社 システムベース");

            // 帳票にデータを渡します
            report.Fill(new ReportDataSource(getDataTable()));

            // PDF出力の実行時間を計測します
            Stopwatch sw = new Stopwatch();
            sw.Start();

            // ページ分割を行います
            ReportPages pages = report.GetPages();

            // PDF出力
            using (FileStream fs = new FileStream("output\\example2_huge.pdf", FileMode.Create))
            {
                PdfRenderer renderer = new PdfRenderer(fs);
                // バックスラッシュ文字を円マーク文字に変換します
                renderer.Setting.ReplaceBackslashToYen = true;
                pages.Render(renderer);
            }

            // 計測結果を表示します
            System.Windows.Forms.MessageBox.Show("実行時間は" + sw.ElapsedMilliseconds + "ミリ秒です");
        }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <param name="item"></param>
        /// <param name="options"></param>
        public void Save(string path, object item, object options)
        {
            if (string.IsNullOrEmpty(path) || item == null)
                return;

            var ic = options as IImageCache;
            if (options == null)
                return;

            var r = new PdfRenderer();
            r.State.DrawShapeState.Flags = ShapeStateFlags.Printable;
            r.State.ImageCache = ic;

            if (item is Container)
            {
                r.Save(path, item as Container);
            }
            else if (item is Document)
            {
                r.Save(path, item as Document);
            }
            else if (item is Project)
            {
                r.Save(path, item as Project);
            }
        }
        public static ResultIterator Process(this TessBaseAPI tessBaseAPI, string inputFile, bool createPdf = false)
        {
            tessBaseAPI.SetPageSegMode(PageSegmentationMode.AUTO);
            var pix = tessBaseAPI.SetImage(inputFile);

            tessBaseAPI.Recognize();

            //if create pdf export pdf
            if (createPdf)
            {
                //ensure input name is set
                tessBaseAPI.SetInputName(inputFile);

                var    fileInfo     = new System.IO.FileInfo(inputFile);
                string tessDataPath = string.Format("{0}", tessBaseAPI.GetDatapath());
                string outputName   = fileInfo.FullName.Replace(fileInfo.Extension, string.Empty); //input name.pdf

                // ensure the data directory exist
                if (!System.IO.Directory.Exists(tessDataPath))
                {
                    throw new System.IO.DirectoryNotFoundException(string.Format("tessData path {0} does not exist", tessDataPath));
                }

                // call pdf renderer and export pdf
                using (var pdfRenderer = new PdfRenderer(outputName, tessDataPath, false))
                {
                    pdfRenderer.BeginDocument("tesseract.net searchable Pdf generation");
                    pdfRenderer.AddImage(tessBaseAPI);
                    pdfRenderer.EndDocument();
                }
            }

            pix.Dispose();
            return(tessBaseAPI.GetIterator());
        }
Example #4
0
        public IActionResult RenderThumbnailImages([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer();
            object      result    = pdfviewer.GetThumbnailImages(jsonObject);

            return(Content(JsonConvert.SerializeObject(result)));
        }
        public IActionResult Unload([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer(_cache);

            pdfviewer.ClearCache(jsonObject);
            return(this.Content("Document cache is cleared"));
        }
    protected void Button1_Click(object sender, EventArgs e)
    {
        contributors = CreateTestList();


        // instance reporting engine
        // assign parameters

        ReportEngine engine = new ReportEngine();

        string reportPath = Server.MapPath("ContributorList.srd");

        ReportModel reportModel = ReportEngine.LoadReportModel(reportPath);

        PageBuilder pageBuilder = engine.CreatePageBuilder(reportModel, contributors);

        pageBuilder.BuildExportList();
        string outputPath = Server.MapPath("ContributorList.pdf");

        // render report
        PdfRenderer pdfRenderer =
            PdfRenderer.CreateInstance(pageBuilder.Pages, outputPath, false);

        pdfRenderer.Start();
        pdfRenderer.RenderOutput();
        pdfRenderer.End();

        // send report to the client
        Response.ContentType = "Application/pdf";
        Response.WriteFile(outputPath);
        Response.End();
    }
Example #7
0
        public IActionResult PrintImages([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer();
            string      pageImage = pdfviewer.GetPrintImage(jsonObject);

            return(Content(pageImage));
        }
Example #8
0
        public IActionResult ExportAnnotations([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfViewer  = new PdfRenderer(Cache);
            string?     jsonResult = pdfViewer.GetAnnotationComments(jsonObject).SerializeToJson();

            return(Content(jsonResult));
        }
        public object Unload(Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer();

            pdfviewer.ClearCache(jsonObject);
            return("Document cache is cleared");
        }
        public IActionResult RenderAnnotationComments([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer  = new PdfRenderer(_cache);
            object      jsonResult = pdfviewer.GetAnnotationComments(jsonObject);

            return(Content(JsonConvert.SerializeObject(jsonResult)));
        }
        public object Bookmarks(Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer  = new PdfRenderer();
            var         jsonResult = pdfviewer.GetBookmarks(jsonObject);

            return(jsonResult);
        }
        public object RenderAnnotationComments(Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer  = new PdfRenderer();
            object      jsonResult = pdfviewer.GetAnnotationComments(jsonObject);

            return(jsonResult);
        }
Example #13
0
                public void Generate(string path)
                {
                    try
                    {
                        var file           = new Java.IO.File(path);
                        var fileDescriptor = ParcelFileDescriptor.Open(file, ParcelFileMode.ReadOnly);

                        var docRenderer = new PdfRenderer(fileDescriptor);
                        if (docRenderer.PageCount == 0)
                        {
                            Image = null; PageCount = 0; return;
                        }

                        var docPage = docRenderer.OpenPage(0);

                        Bitmap renderedPage = Bitmap.CreateBitmap(docPage.Width, docPage.Height, Bitmap.Config.Argb8888);
                        docPage.Render(renderedPage, null, null, PdfRenderMode.ForDisplay);

                        Image     = renderedPage;
                        PageCount = docRenderer.PageCount;
                    }
                    catch (Exception)
                    {
                        Image     = null;
                        PageCount = 0;
                    }
                }
        public HttpResponseMessage Download(Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer    = new PdfRenderer();
            string      documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);

            return(GetPlainText(documentBase));
        }
        public IActionResult ExportFormFields([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer  = new PdfRenderer(_cache);
            string      jsonResult = pdfviewer.ExportFormFields(jsonObject);

            return(Content(jsonResult));
        }
Example #16
0
        public void Run()
        {
            var name = "test_0_2";

            Report report = new Report(Json.Read(Path.Combine("rrpt", name + ".rrpt")));

            report.GlobalScope.Add("time", DateTime.Now);
            report.GlobalScope.Add("lang", "core");

            report.Fill(DummyDataSource.GetInstance());
            ReportPages pages = report.GetPages();

            using (FileStream fs = new FileStream(Path.Combine("out", name + ".pdf"), FileMode.Create))
            {
                PdfRenderer renderer = new PdfRenderer(fs);
                pages.Render(renderer);
            }

            using (FileStream fs = new FileStream(Path.Combine("out", name + ".xlsx"), FileMode.Create))
            {
                XSSFWorkbook workbook = new XSSFWorkbook();
                XlsxRenderer renderer = new XlsxRenderer(workbook);
                renderer.NewSheet("sheet_name");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            {
                var printer = new Printer(pages);
                var preview = new FmPrintPreview(printer);
                preview.ShowDialog();
            }
        }
Example #17
0
        /// <summary>
        /// Converts a set of <see cref="FixedPage"/>s from at least one XPS document into a <see cref="PdfDocument"/>.
        /// This method can be used to merge multiple XPS documents into a single PDF.
        /// </summary>
        /// <param name="pages">A collection of FixedPages to render to PDF.</param>
        /// <returns>A PDF document that contains the converted version of the pages passed in.</returns>
        public static PdfDocument Convert(IEnumerable <FixedPage> pages)
        {
            if (pages == null)
            {
                throw new ArgumentNullException(nameof(pages));
            }

            PdfDocument pdfDocument = new PdfDocument();
            PdfRenderer renderer    = new PdfRenderer();

            int pageIndex = 0;

            foreach (FixedPage page in pages)
            {
                if (page == null)
                {
                    continue;
                }
                Debug.WriteLine(String.Format("  page={0}", pageIndex));
                PdfPage pdfPage = renderer.CreatePage(pdfDocument, page);
                renderer.RenderPage(pdfPage, page);
                pageIndex++;

#if DEBUG
                // stop at page...
                if (pageIndex == 50)
                {
                    break;
                }
#endif
            }

            return(pdfDocument);
        }
Example #18
0
 public override void render(PdfRenderer renderer)
 {
     if (foreignObject != null)
     {
         renderer.RenderForeignObjectArea(this);
     }
 }
        public IActionResult Load([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer  pdfviewer  = new PdfRenderer(_cache);
            MemoryStream stream     = new MemoryStream();
            object       jsonResult = new object();

            if (jsonObject != null && jsonObject.ContainsKey("document"))
            {
                if (bool.Parse(jsonObject["isFileName"]))
                {
                    string documentPath = GetDocumentPath(jsonObject["document"]);
                    if (!string.IsNullOrEmpty(documentPath))
                    {
                        byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
                        stream = new MemoryStream(bytes);
                    }
                    else
                    {
                        return(this.Content(jsonObject["document"] + " is not found"));
                    }
                }
                else
                {
                    byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
                    stream = new MemoryStream(bytes);
                }
            }
            jsonResult = pdfviewer.Load(stream, jsonObject);
            return(Content(JsonConvert.SerializeObject(jsonResult)));
        }
		private string[] Render (PdfRenderer pdf, string outputDirectory)
		{
			var result = new string[pdf.PageCount];

			for (int i = 0; i < pdf.PageCount; i++) {
				var pagePath = string.Format ("{0}/{1}.png", outputDirectory.TrimEnd (new char[] { '/', '\\' }), i);
				var page = pdf.OpenPage (i);
				var image = RenderImage (page);

				using (var fs = new FileStream (pagePath, FileMode.CreateNew)) {
					image.Compress (Bitmap.CompressFormat.Png, 95, fs);
				}

				result [i] = pagePath;

				page.Close ();
			}

			pdf.Close ();

			var metaPath = string.Format ("{0}/{1}", outputDirectory.TrimEnd (new char[] { '/', '\\' }), MetaFile);
			File.Create (metaPath);

			return result;
		}
Example #21
0
        public IActionResult Bookmarks([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer  = new PdfRenderer();
            object      jsonResult = pdfviewer.GetBookmarks(jsonObject);

            return(Content(JsonConvert.SerializeObject(jsonResult)));
        }
        public IActionResult ExportAnnotations([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer(_cache);
            string      result    = pdfviewer.ExportAnnotation(jsonObject);

            return(Content(result));
        }
Example #23
0
        public void It_should_render_images()
        {
            var redBlue    = CreateBitmap(Brushes.Red, Brushes.Blue, 400, 400);
            var blueYellow = CreateBitmap(Brushes.Blue, Brushes.Yellow, 30, 30);

            var renderer = new PdfRenderer();
            var vBox     = new VBox();
            var hBox     = new HBox();

            AddComponent(hBox, new Image {
                Src = redBlue, Width = 40, Height = 40, Scaling = ImageScaling.Uniform
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 40, Height = 30, Scaling = ImageScaling.Uniform, Alignment = Alignment.Center
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 40, Height = 30, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("center left")
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 40, Height = 30, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("center right")
            });
            vBox.AddComponent(hBox);
            hBox = new HBox();
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 30, Height = 40, Scaling = ImageScaling.Uniform, Alignment = Alignment.Center
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 30, Height = 40, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("top center")
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 30, Height = 40, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("bottom center")
            });
            vBox.AddComponent(hBox);
            hBox = new HBox();
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 10, Height = 20, Scaling = ImageScaling.Fill
            });
            AddComponent(hBox, new Image {
                Src = blueYellow, Scaling = ImageScaling.None
            });
            AddComponent(hBox, new Image {
                Src = blueYellow, Width = 20, Height = 20, Alignment = Alignment.Center, Scaling = ImageScaling.None
            });
            AddComponent(hBox, new Image {
                Src = blueYellow, Width = 20, Height = 20, Alignment = Alignment.Parse("top left"), Scaling = ImageScaling.None
            });
            AddComponent(hBox, new Image {
                Src = blueYellow, Width = 20, Height = 20, Alignment = Alignment.Parse("bottom right"), Scaling = ImageScaling.None
            });
            vBox.AddComponent(hBox);
            var form = new Form(vBox);

            var doc  = new PdfDocument();
            var page = doc.AddPage();

            renderer.Render(form, page, new PdfRendererOptions {
                AdjustPageSize = true
            });
            PdfImageComparer.ComparePdfs("bitmaps", doc);
        }
        public IActionResult PrintImages([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer(_cache);
            object      pageImage = pdfviewer.GetPrintImage(jsonObject);

            return(Content(JsonConvert.SerializeObject(pageImage)));
        }
        public IActionResult RenderPdfTexts([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer(_cache);
            object      result    = pdfviewer.GetDocumentText(jsonObject);

            return(Content(JsonConvert.SerializeObject(result)));
        }
        public HttpResponseMessage ExportAnnotations(Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer();
            var         annots    = pdfviewer.GetAnnotations(jsonObject);

            return(GetPlainText(annots));
        }
        public IActionResult ImportFormFields([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer  = new PdfRenderer(_cache);
            object      jsonResult = pdfviewer.ImportFormFields(jsonObject);

            return(Content(JsonSerializer.Serialize(jsonResult)));
        }
        public object PrintImages(Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer();
            object      pageImage = pdfviewer.GetPrintImage(jsonObject);

            return(pageImage);
        }
        public IActionResult Download([FromBody] Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer    = new PdfRenderer(_cache);
            string      documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);

            return(Content(documentBase));
        }
        public object RenderPdfPages(Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer  = new PdfRenderer();
            object      jsonResult = pdfviewer.GetPage(jsonObject);

            return(JsonConvert.SerializeObject(jsonResult));
        }
        public object RenderThumbnailImages(Dictionary <string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer();
            object      result    = pdfviewer.GetThumbnailImages(jsonObject);

            return(JsonConvert.SerializeObject(result));
        }
Example #32
0
        /// <summary>
        /// Parses the given XPS file and saves the PDF Version.
        /// </summary>
        void ParseFile(string file)
        {
            string baseDir  = GetDirectory("PdfSharp/testing/PdfSharp.Xps.UnitTests/Primitives.Glyphs/GlyphFiles");
            string filename = System.IO.Path.Combine(baseDir, file + ".xps");

            PdfDocument document = new PdfDocument();

            try
            {
                XpsModel.XpsDocument xpsDoc = XpsModel.XpsDocument.Open(filename);
                foreach (XpsModel.FixedDocument doc in xpsDoc.Documents)
                {
                    foreach (XpsModel.FixedPage page in doc.Pages)
                    {
                        page.GetType();

                        //Render PDF Page
                        PdfPage pdfpage = document.AddPage();
                        pdfpage.Width  = page.PointWidth;
                        pdfpage.Height = page.PointHeight;

                        PdfRenderer renderer = new PdfRenderer();
                        renderer.RenderPage(pdfpage, page);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                GetType();
            }
            document.Save(Path.Combine(OutputDirectory, file + ".pdf"));
        }
Example #33
0
        public static void Run()
        {
            Report report = new Report(Json.Read("report\\feature.rrpt"));

            // "feature-4"にgetDataTable1-4をそれぞれ割り当てます
            GroupDataProvider dataProvider = new GroupDataProvider();
            dataProvider.GroupDataMap.Add("feature1", new ReportDataSource(getDataTable1()));
            dataProvider.GroupDataMap.Add("feature2", new ReportDataSource(getDataTable2()));
            dataProvider.GroupDataMap.Add("feature3", new ReportDataSource(getDataTable3()));
            dataProvider.GroupDataMap.Add("feature4", new ReportDataSource(getDataTable4()));

            // 第2引数にdataProviderを渡します
            report.Fill(DummyDataSource.GetInstance(), dataProvider);
            ReportPages pages = report.GetPages();

            // PDF出力
            using (FileStream fs = new FileStream("output\\feature.pdf", FileMode.Create))
            {
                PdfRenderer renderer = new PdfRenderer(fs);
                renderer.Setting.ReplaceBackslashToYen = true;
                pages.Render(renderer);
            }

            // XLS出力
            using (FileStream fs = new FileStream("output\\feature.xls", FileMode.Create))
            {
                HSSFWorkbook workbook = new HSSFWorkbook();
                XlsRenderer renderer = new XlsRenderer(workbook);
                renderer.NewSheet("feature");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // XLSX出力
            using (FileStream fs = new FileStream("output\\feature.xlsx", FileMode.Create))
            {
                XSSFWorkbook workbook = new XSSFWorkbook();
                XlsxRenderer renderer = new XlsxRenderer(workbook);
                renderer.NewSheet("feature");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // プレビュー
            {
                FmPrintPreview preview = new FmPrintPreview(new Printer(pages));
                preview.StartUpZoomFit = true;
                preview.ShowDialog();
            }
        }
        public static void Run()
        {
            Report report = new Report(Json.Read("report\\example_dataprovider.rrpt"));

            // "group_shohin"という識別子を持ったグループには、
            // getShoninDataTableから得られるデータを割り当てます
            GroupDataProvider dataProvider = new GroupDataProvider();
            dataProvider.GroupDataMap.Add("group_shonin", new ReportDataSource(getShoninDataTable()));

            // 第2引数にdataProviderを渡します
            report.Fill(new ReportDataSource(getDataTable()), dataProvider);

            ReportPages pages = report.GetPages();

            // PDF出力
            using (FileStream fs = new FileStream("output\\example_dataprovider.pdf", FileMode.Create))
            {
                PdfRenderer renderer = new PdfRenderer(fs);
                renderer.Setting.ReplaceBackslashToYen = true;
                pages.Render(renderer);
            }

            // XLS出力
            using (FileStream fs = new FileStream("output\\example_dataprovider.xls", FileMode.Create))
            {
                HSSFWorkbook workbook = new HSSFWorkbook();
                XlsRenderer renderer = new XlsRenderer(workbook);
                renderer.NewSheet("example_dataprovider");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // XLSX出力
            using (FileStream fs = new FileStream("output\\example_dataprovider.xlsx", FileMode.Create))
            {
                XSSFWorkbook workbook = new XSSFWorkbook();
                XlsxRenderer renderer = new XlsxRenderer(workbook);
                renderer.NewSheet("example_dataprovider");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // プレビュー
            {
                FmPrintPreview preview = new FmPrintPreview(new Printer(pages));
                preview.StartUpZoomFit = true;
                preview.ShowDialog();
            }
        }
Example #35
0
        public static void Run()
        {
            // サブページを先に生成します
            Report subReport = new Report(Json.Read("report\\example_subpage2.rrpt"));
            subReport.Fill(new ReportDataSource(getDataTable()));
            ReportPages subPages = subReport.GetPages();

            Report report = new Report(Json.Read("report\\example_subpage1.rrpt"));
            // 外枠帳票にサブページを登録します
            report.AddSubPages("subpage", subPages);
            // 外枠帳票の中でサブページが正しく割り当てられるようにSubPageDataSourceを渡します
            report.Fill(new SubPageDataSource(subPages, "group1", "page1", "page2"));
            ReportPages pages = report.GetPages();

            // PDF出力
            using (FileStream fs = new FileStream("output\\example_subpage.pdf", FileMode.Create))
            {
                PdfRenderer renderer = new PdfRenderer(fs);
                renderer.Setting.ReplaceBackslashToYen = true;
                pages.Render(renderer);
            }

            // XLS出力
            using (FileStream fs = new FileStream("output\\example_subpage.xls", FileMode.Create))
            {
                HSSFWorkbook workbook = new HSSFWorkbook();
                XlsRenderer renderer = new XlsRenderer(workbook);
                renderer.NewSheet("example_subpage");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // XLSX出力
            using (FileStream fs = new FileStream("output\\example_subpage.xlsx", FileMode.Create))
            {
                XSSFWorkbook workbook = new XSSFWorkbook();
                XlsxRenderer renderer = new XlsxRenderer(workbook);
                renderer.NewSheet("example_subpage");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // プレビュー
            {
                FmPrintPreview preview = new FmPrintPreview(new Printer(pages));
                preview.StartUpZoomFit = true;
                preview.ShowDialog();
            }
        }
		private static Bitmap RenderImage (PdfRenderer.Page page)
		{
			var bitmap = Bitmap.CreateBitmap (page.Width, page.Height, Bitmap.Config.Argb8888);

			// Fill with default while color first
			var canvas = new Canvas(bitmap);
			var paint = new Paint ()
			{
				Color = Color.White
			};
			canvas.DrawRect (new Rect (0, 0, page.Width, page.Height), paint);

			// Render content
			page.Render (bitmap, null, null, PdfRenderMode.ForDisplay);
			return bitmap;
		}
        public static void Run()
        {
            // 差込みを行うコンテントを、あらかじめ共有コンテントへ登録しておきます
            ReportDesign sharedReport = new ReportDesign(Json.Read("report/example_shared.rrpt"));
            Report.AddSharedContent("company_info", sharedReport);

            Report report = new Report(Json.Read("report\\example_mergecontent.rrpt"));
            report.GlobalScope.Add("company_name", "株式会社ラピッドレポート");
            report.GlobalScope.Add("tel", "0000-11-2222");
            report.Fill(new ReportDataSource(getDataTable()));
            ReportPages pages = report.GetPages();

            // PDF出力
            using (FileStream fs = new FileStream("output\\example_mergecontent.pdf", FileMode.Create))
            {
                PdfRenderer renderer = new PdfRenderer(fs);
                renderer.Setting.ReplaceBackslashToYen = true;
                pages.Render(renderer);
            }

            // XLS出力
            using (FileStream fs = new FileStream("output\\example_mergecontent.xls", FileMode.Create))
            {
                HSSFWorkbook workbook = new HSSFWorkbook();
                XlsRenderer renderer = new XlsRenderer(workbook);
                renderer.NewSheet("example_mergecontent");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // XLSX出力
            using (FileStream fs = new FileStream("output\\example_mergecontent.xlsx", FileMode.Create))
            {
                XSSFWorkbook workbook = new XSSFWorkbook();
                XlsxRenderer renderer = new XlsxRenderer(workbook);
                renderer.NewSheet("example_mergecontent");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // プレビュー
            {
                FmPrintPreview preview = new FmPrintPreview(new Printer(pages));
                preview.StartUpZoomFit = true;
                preview.ShowDialog();
            }
        }
Example #38
0
        public static void Run()
        {
            // 第2引数にCustomizerオブジェクトを渡します
            Report report = new Report(Json.Read("report\\example_region.rrpt"), new Customizer());
            report.Fill(new ReportDataSource(getDataTable()));
            ReportPages pages = report.GetPages();

            // PDF出力
            using (FileStream fs = new FileStream("output\\example_region.pdf", FileMode.Create))
            {
                PdfRenderer renderer = new PdfRenderer(fs);
                renderer.Setting.ReplaceBackslashToYen = true;
                pages.Render(renderer);
            }

            // XLS出力
            using (FileStream fs = new FileStream("output\\example_region.xls", FileMode.Create))
            {
                HSSFWorkbook workbook = new HSSFWorkbook();
                XlsRenderer renderer = new XlsRenderer(workbook);
                renderer.NewSheet("example_region");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // XLSX出力
            using (FileStream fs = new FileStream("output\\example_region.xlsx", FileMode.Create))
            {
                XSSFWorkbook workbook = new XSSFWorkbook();
                XlsxRenderer renderer = new XlsxRenderer(workbook);
                renderer.NewSheet("example_region");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // プレビュー
            {
                FmPrintPreview preview = new FmPrintPreview(new Printer(pages));
                preview.StartUpZoomFit = true;
                preview.ShowDialog();
            }
        }
Example #39
0
 // PDF出力実行
 public void ExportPDF()
 {
     SaveFileDialog fd = new SaveFileDialog();
     fd.AddExtension = true;
     fd.Filter = "PDFファイル(*.pdf)|*.pdf";
     if (fd.ShowDialog() == DialogResult.OK)
     {
         try
         {
             using(FileStream fs = new FileStream(fd.FileName, FileMode.Create))
             {
                 PdfRenderer renderer = new PdfRenderer(fs);
                 renderer.Setting.ReplaceBackslashToYen = true;
                 this.PrintPreview.Printer.Pages.Render(renderer);
             }
             MessageBox.Show(fd.FileName + "を保存しました", "確認");
         }
         catch (Exception)
         {
             MessageBox.Show(fd.FileName + "の保存に失敗しました", "確認");
         }
     }
 }
Example #40
0
        public static void Run(HttpServerUtility server, HttpResponse response)
        {
            // 帳票定義ファイルを読み込みます
            Report report = new Report(Json.Read(server.MapPath("report\\example1.rrpt")));

            // 帳票にデータを渡します
            report.Fill(new ReportDataSource(getDataTable()));

            // ページ分割を行います
            ReportPages pages = report.GetPages();

            // PDF出力
            using (Stream _out = response.OutputStream)
            {
                PdfRenderer renderer = new PdfRenderer(_out);
                // バックスラッシュ文字を円マーク文字に変換します
                renderer.Setting.ReplaceBackslashToYen = true;
                pages.Render(renderer);
                response.ContentType = "application/pdf";
                response.AddHeader("Content-Disposition", "attachment;filename=example1.pdf");
                response.End();
            }
        }
Example #41
0
 public void Render(
     PdfRenderer renderer, 
     ReportDesign reportDesign, 
     Region region, 
     ElementDesign design, 
     object data)
 {
     Region r = region.ToPointScale(reportDesign);
     PdfContentByte cb = renderer.Writer.DirectContent;
     Single x = r.Left + r.GetWidth() / 2;
     Single y = r.Top + r.GetHeight() / 2;
     Single w = 12;
     cb.SaveState();
     cb.Rectangle(renderer.Trans.X(x - w / 2), renderer.Trans.Y(y - w / 2), w, -w);
     cb.Stroke();
     if ((bool)data)
     {
         cb.SetColorFill(PdfRenderUtil.GetColor("steelblue"));
         cb.MoveTo(renderer.Trans.X(x - w / 2), renderer.Trans.Y(y - w / 4));
         cb.LineTo(renderer.Trans.X(x - w / 4), renderer.Trans.Y(y + w / 2));
         cb.LineTo(renderer.Trans.X(x + w / 2), renderer.Trans.Y(y - w / 2));
         cb.LineTo(renderer.Trans.X(x - w / 4), renderer.Trans.Y(y));
         cb.Fill();
     }
     cb.RestoreState();
 }
Example #42
0
        public static void Run()
        {
            // 帳票定義ファイルを読み込みます
            Report report = new Report(Json.Read("report\\example2.rrpt"));

            // GlobalScopeに値を登録します
            report.GlobalScope.Add("startDate", DateTime.ParseExact("2013/02/01", "yyyy/MM/dd", null));
            report.GlobalScope.Add("endDate", DateTime.ParseExact("2013/02/28", "yyyy/MM/dd", null));
            report.GlobalScope.Add("printDate", DateTime.Today);
            report.GlobalScope.Add("kaisha", "株式会社 システムベース");

            // 帳票にデータを渡します
            report.Fill(new ReportDataSource(getDataTable()));

            // ページ分割を行います
            ReportPages pages = report.GetPages();

            // PDF出力
            using (FileStream fs = new FileStream("output\\example2.pdf", FileMode.Create))
            {
                PdfRenderer renderer = new PdfRenderer(fs);
                // バックスラッシュ文字を円マーク文字に変換します
                renderer.Setting.ReplaceBackslashToYen = true;
                pages.Render(renderer);
            }

            // XLS出力
            using (FileStream fs = new FileStream("output\\example2.xls", FileMode.Create))
            {
                HSSFWorkbook workbook = new HSSFWorkbook();
                XlsRenderer renderer = new XlsRenderer(workbook);
                // Renderメソッドを呼ぶ前に必ずNewSheetメソッドを呼んでワークシートを作成します
                renderer.NewSheet("売上明細表");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // XLSX出力
            using (FileStream fs = new FileStream("output\\example2.xlsx", FileMode.Create))
            {
                XSSFWorkbook workbook = new XSSFWorkbook();
                XlsxRenderer renderer = new XlsxRenderer(workbook);
                // Renderメソッドを呼ぶ前に必ずNewSheetメソッドを呼んでワークシートを作成します
                renderer.NewSheet("売上明細表");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // 直接印刷、プレビュー画面表示
            {
                Printer printer = new Printer(pages);
                //// 直接印刷
                //// ダイアログを出して印刷します
                //if (printer.PrintDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                //{
                //    printer.PrintDocument.Print();
                //}

                //// ダイアログを出さずに印刷します
                //printer.PrintDocument.Print();

                // プレビュー画面表示
                FmPrintPreview preview = new FmPrintPreview(printer);
                // プレビュー画面が開かれた時点で表示倍率を現在のウィンドウサイズに合わせます
                preview.StartUpZoomFit = true;
                preview.ShowDialog();
            }
        }
		public async Task<Abstractions.PdfDocument> Rasterize (string pdfPath, bool cachePirority = true)
		{
			if(cachePirority)
			{
				var existing = await GetRasterized(pdfPath);
				if(existing != null)
				{
					Debug.WriteLine("Using cached images ...");

					return existing;
				}
			}

			Debug.WriteLine("Downloading and generating again ...");

			var localpath = pdfPath.IsDistantUrl () ? await this.DownloadTemporary (pdfPath) : pdfPath;

			//TODO threading the process

			#if DROID
			var f = new Java.IO.File(localpath);
			var fd = Android.OS.ParcelFileDescriptor.Open(f,Android.OS.ParcelFileMode.ReadOnly);
			var pdf = new PdfRenderer (fd);
			#else
			var pdf = CGPDFDocument.FromFile (localpath);
			#endif

			var path = GetLocalPath(pdfPath, !cachePirority);
			var pagesPaths = this.Render (pdf, path);

			return new Plugin.PdfRasterizer.Abstractions.PdfDocument () 
			{
				Pages = pagesPaths.Select ((p) => new PdfPage () { Path = p }),
			};
		}
Example #44
0
        public static void Run()
        {
            // 帳票定義ファイルを読み込みます
            Report report = new Report(Json.Read("report\\example1.rrpt"));

            // CSVファイルから帳票にデータを渡します
            using (StreamReader r = new StreamReader("report\\data.csv", Encoding.GetEncoding("shift-jis")))
            {
                report.Fill(new CsvDataSource(r));
            }

            // ページ分割を行います
            ReportPages pages = report.GetPages();

            // PDF出力
            using (FileStream fs = new FileStream("output\\example1csv.pdf", FileMode.Create))
            {
                PdfRenderer renderer = new PdfRenderer(fs);
                // バックスラッシュ文字を円マーク文字に変換します
                renderer.Setting.ReplaceBackslashToYen = true;
                pages.Render(renderer);
            }

            // XLS出力
            using (FileStream fs = new FileStream("output\\example1csv.xls", FileMode.Create))
            {
                HSSFWorkbook workbook = new HSSFWorkbook();
                XlsRenderer renderer = new XlsRenderer(workbook);
                // Renderメソッドを呼ぶ前に必ずNewSheetメソッドを呼んでワークシートを作成します
                renderer.NewSheet("見積書");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // XLSX出力
            using (FileStream fs = new FileStream("output\\example1csv.xlsx", FileMode.Create))
            {
                XSSFWorkbook workbook = new XSSFWorkbook();
                XlsxRenderer renderer = new XlsxRenderer(workbook);
                // Renderメソッドを呼ぶ前に必ずNewSheetメソッドを呼んでワークシートを作成します
                renderer.NewSheet("見積書");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // 直接印刷、プレビュー画面表示
            {
                Printer printer = new Printer(pages);

                //// 直接印刷
                //// ダイアログを出して印刷します
                //if (printer.PrintDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                //{
                //    printer.PrintDocument.Print();
                //}

                //// ダイアログを出さずに印刷します
                //printer.PrintDocument.Print();

                // プレビュー画面表示
                FmPrintPreview preview = new FmPrintPreview(printer);
                // プレビュー画面が開かれた時点で表示倍率を現在のウィンドウサイズに合わせます
                preview.StartUpZoomFit = true;
                preview.ShowDialog();
            }
        }
Example #45
0
        public static void Run()
        {
            // 郵便番号フォーマッタが設定されたSettingオブジェクトを用意します
            ReportSetting setting = new ReportSetting();
            setting.TextFormatterMap.Add("yubin", new YubinTextFormatter());

            Report report = new Report(Json.Read("report\\example_extention.rrpt"), setting);
            report.Fill(new ReportDataSource(getDataTable()));
            ReportPages pages = report.GetPages();

            // PDF出力
            using (FileStream fs = new FileStream("output\\example_extention.pdf", FileMode.Create))
            {
                // チェックボックスレンダラが設定されたSettingオブジェクトを用意します
                PdfRendererSetting pdfSetting = new PdfRendererSetting();
                pdfSetting.ElementRendererMap.Add("checkbox", new PdfCheckBoxRenderer());

                PdfRenderer renderer = new PdfRenderer(fs, pdfSetting);
                renderer.Setting.ReplaceBackslashToYen = true;
                pages.Render(renderer);
            }

            // XLS出力
            using (FileStream fs = new FileStream("output\\example_extention.xls", FileMode.Create))
            {
                // チェックボックスレンダラが設定されたSettingオブジェクトを用意します
                XlsRendererSetting xlsSetting = new XlsRendererSetting();
                xlsSetting.ElementRendererMap.Add("checkbox", new XlsCheckBoxRenderer());

                HSSFWorkbook workbook = new HSSFWorkbook();
                XlsRenderer renderer = new XlsRenderer(workbook, xlsSetting);
                renderer.NewSheet("example_extention");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // XLSX出力
            using (FileStream fs = new FileStream("output\\example_extention.xlsx", FileMode.Create))
            {
                // チェックボックスレンダラが設定されたSettingオブジェクトを用意します
                XlsxRendererSetting xlsxSetting = new XlsxRendererSetting();
                xlsxSetting.ElementRendererMap.Add("checkbox", new XlsxCheckBoxRenderer());

                XSSFWorkbook workbook = new XSSFWorkbook();
                XlsxRenderer renderer = new XlsxRenderer(workbook, xlsxSetting);
                renderer.NewSheet("example_extention");
                pages.Render(renderer);
                workbook.Write(fs);
            }

            // プレビュー
            {
                // チェックボックスレンダラが設定されたSettingオブジェクトを用意します
                GdiRendererSetting gdiSetting = new GdiRendererSetting();
                gdiSetting.ElementRendererMap.Add("checkbox", new GdiCheckBoxRenderer());

                FmPrintPreview preview = new FmPrintPreview(new Printer(pages, gdiSetting));
                preview.StartUpZoomFit = true;
                preview.ShowDialog();
            }
        }
Example #46
0
        public static void Run()
        {
            // 帳票定義ファイルを読み込みます
            Report report = new Report(Json.Read("report\\example_image.rrpt"));

            // 帳票にデータを渡します
            report.Fill(new ReportDataSource(getDataTable()));

            // ページ分割を行います
            ReportPages pages = report.GetPages();

            // イメージマップを生成します
            ImageMap imageMap = getImageMap();

            // PDF出力
            using (FileStream fs = new FileStream("output\\example_image.pdf", FileMode.Create))
            {
                PdfRenderer renderer = new PdfRenderer(fs);

                // イメージローダを登録します
                renderer.ImageLoaderMap.Add("image", new PdfImageLoader(imageMap));
                renderer.ImageLoaderMap.Add("graph", new PdfGraphImageLoader());

                pages.Render(renderer);
            }

            // XLS出力
            using (FileStream fs = new FileStream("output\\example_image.xls", FileMode.Create))
            {
                HSSFWorkbook workbook = new HSSFWorkbook();
                XlsRenderer renderer = new XlsRenderer(workbook);
                renderer.NewSheet("example_image");

                // イメージローダを登録します
                renderer.ImageLoaderMap.Add("image", new XlsImageLoader(imageMap));
                renderer.ImageLoaderMap.Add("graph", new XlsGraphImageLoader());

                pages.Render(renderer);
                workbook.Write(fs);
            }

            // XLSX出力
            using (FileStream fs = new FileStream("output\\example_image.xlsx", FileMode.Create))
            {
                XSSFWorkbook workbook = new XSSFWorkbook();
                XlsxRenderer renderer = new XlsxRenderer(workbook);
                renderer.NewSheet("example_image");

                // イメージローダを登録します
                renderer.ImageLoaderMap.Add("image", new XlsxImageLoader(imageMap));
                renderer.ImageLoaderMap.Add("graph", new XlsxGraphImageLoader());

                pages.Render(renderer);
                workbook.Write(fs);
            }

            // プレビュー画面表示
            {
                Printer printer = new Printer(pages);

                // イメージローダを登録します
                printer.ImageLoaderMap.Add("image", new GdiImageLoader(imageMap));
                printer.ImageLoaderMap.Add("graph", new GdiGraphImageLoader());

                FmPrintPreview preview = new FmPrintPreview(printer);
                preview.StartUpZoomFit = true;
                preview.ShowDialog();
            }
        }