Exemplo n.º 1
0
        protected void PDF_Upload_Click(object sender, EventArgs e)
        {
            string pdfname      = PdfInput.FileName;
            string logoPath     = Server.MapPath("~/PDFFolder");
            string completePath = Server.MapPath("PDFFolder/" + pdfname);

            if (!Directory.Exists(logoPath))
            {
                DirectorySecurity securityRules = new DirectorySecurity();
                securityRules.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null),
                                                                     FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit,
                                                                     PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
                DirectoryInfo di = Directory.CreateDirectory(logoPath);     //Création directory
                di.SetAccessControl(securityRules);
            }
            PdfInput.SaveAs(completePath);
            Response.Write("File uploaded sucessfully.");
        }
Exemplo n.º 2
0
        // Generates document
        public static void Generate(ILogger logger, YesNo useTestMode = YesNo.No)
        {
            #region Initialize timer
            var sw = new Stopwatch();
            sw.Start();
            #endregion

            #region page-1

            var page1 = new PdfInput
            {
                AutoUpdateChanges = true,
                Input             = "~/Resources/Sample-04/file-sample-1.pdf"
            };

            // Inserts report title
            page1.Replace(new ReplaceText(
                              new WithTextObject
            {
                Text           = "#TITLE#",
                NewText        = "Lorem ipsum",
                UseTestMode    = useTestMode,
                TextOffset     = PointF.Empty,
                Style          = TextStylesTable["ReportTitle"],
                ReplaceOptions = ReplaceTextOptions.AccordingToMargins
            }));


            // Inserts bar-chart image
            using (var barGraph = PdfImage.FromFile("~/Resources/Sample-04/Images/bar-chart.png"))
            {
                page1.Replace(new ReplaceText(
                                  new WithImageObject
                {
                    Text           = "#BAR-CHART#",
                    UseTestMode    = useTestMode,
                    ImageOffset    = PointF.Empty,
                    Style          = ImagesStylesTable["Default"],
                    ReplaceOptions = ReplaceTextOptions.AccordingToMargins,
                    Image          = barGraph
                }));
            }

            #endregion

            #region page-2

            var page2 = new PdfInput
            {
                AutoUpdateChanges = true,
                Input             = "~/Resources/Sample-04/file-sample-2.pdf"
            };

            // Inserts html table
            page2.Replace(new ReplaceText(
                              new WithTableObject
            {
                Text           = "#DATA-TABLE#",
                UseTestMode    = useTestMode,
                TableOffset    = PointF.Empty,
                Style          = PdfTableStyle.Default,
                ReplaceOptions = ReplaceTextOptions.FromPositionToRightMargin,
                Table          = PdfTable.CreateFromHtml(GenerateHtmlDatatable())
            }));

            #endregion

            #region page-3

            var page3 = new PdfInput
            {
                AutoUpdateChanges = true,
                Input             = "~/Resources/Sample-04/file-sample-3.pdf"
            };

            #endregion

            #region page-4

            var page4 = new PdfInput
            {
                AutoUpdateChanges = true,
                Input             = "~/Resources/Sample-04/file-sample-4.pdf"
            };

            // Inserts image
            using (var image = PdfImage.FromFile("~/Resources/Sample-04/Images/image-1.jpg"))
            {
                page4.Replace(new ReplaceText(
                                  new WithImageObject
                {
                    Text           = "#IMAGE1#",
                    UseTestMode    = useTestMode,
                    ImageOffset    = PointF.Empty,
                    Style          = ImagesStylesTable["Center"],
                    ReplaceOptions = ReplaceTextOptions.AccordingToMargins,
                    Image          = image
                }));
            }

            #endregion

            #region merge

            // Defines global text replacements to replace > header text
            var globalReplacements = new GlobalReplacementsCollection
            {
                new WithTextObject
                {
                    Text           = "#HEADER-TEXT#",
                    NewText        = "Report Name - Lorem ipsum dolor",
                    Style          = TextStylesTable["Header"],
                    ReplaceOptions = ReplaceTextOptions.FromLeftMarginToNextElement,
                    UseTestMode    = useTestMode,
                    TextOffset     = PointF.Empty
                }
            };

            var files = new PdfObject(new PdfObjectConfig {
                GlobalReplacements = globalReplacements
            })
            {
                Items = new List <PdfInput>
                {
                    new PdfInput {
                        Index = 0, Input = page1
                    },
                    new PdfInput {
                        Index = 1, Input = page2
                    },
                    new PdfInput {
                        Index = 2, Input = page3
                    },
                    new PdfInput {
                        Index = 3, Input = page4
                    },
                }
            };

            var mergeResult = files.TryMergeInputs();
            if (!mergeResult.Success)
            {
                logger.Info("   > Error creating output merge result");
                logger.Info($"     > Error: {mergeResult.Errors.AsMessages().ToStringBuilder()}");
                return;
            }

            #endregion

            #region save

            // Saves merged result to disk
            var saveResult = mergeResult.Result.Action(new SaveToFile {
                OutputPath = "~/Output/Sample04/Sample-04"
            });
            var ts = sw.Elapsed;
            sw.Stop();

            if (!saveResult.Success)
            {
                logger.Info("   > Error while saving to disk");
                logger.Info($"     > Error: {saveResult.Errors.AsMessages().ToStringBuilder()}");
                logger.Info($"   > Elapsed time: { ts.Hours:00}:{ ts.Minutes:00}:{ ts.Seconds:00}.{ ts.Milliseconds / 10:00}");
                return;
            }

            logger.Info("   > Saved to disk correctly");
            logger.Info("     > Path: ~/Output/Sample04/Sample-04.pdf");
            logger.Info($"   > Elapsed time: { ts.Hours:00}:{ ts.Minutes:00}:{ ts.Seconds:00}.{ ts.Milliseconds / 10:00}");

            #endregion
        }
Exemplo n.º 3
0
        // Generates document
        public static void Generate(ILogger logger, YesNo useTestMode = YesNo.No)
        {
            #region Initialize timer
            var sw = new Stopwatch();
            sw.Start();
            #endregion

            #region Creates pdf file reference

            var doc = new PdfInput
            {
                AutoUpdateChanges = true,
                Input             = "~/Resources/Sample-10/file-sample.pdf"
            };

            #endregion

            #region Replace actions

            // Inserts report title
            doc.Replace(new ReplaceText(
                            new WithTextObject
            {
                Text           = "#TITLE#",
                NewText        = "Lorem ipsum",
                UseTestMode    = useTestMode,
                TextOffset     = PointF.Empty,
                Style          = TextStylesTable["ReportTitle"],
                ReplaceOptions = ReplaceTextOptions.AccordingToMargins
            }));


            // Inserts bar-chart image
            using (var barGraph = PdfImage.FromFile("~/Resources/Sample-10/Images/bar-chart.png"))
            {
                doc.Replace(new ReplaceText(
                                new WithImageObject
                {
                    Text           = "#BAR-CHART#",
                    UseTestMode    = useTestMode,
                    ImageOffset    = PointF.Empty,
                    Style          = ImagesStylesTable["Default"],
                    ReplaceOptions = ReplaceTextOptions.Default,
                    Image          = barGraph
                }));
            }

            // Inserts image
            using (var image = PdfImage.FromFile("~/Resources/Sample-10/Images/image-1.jpg"))
            {
                doc.Replace(new ReplaceText(
                                new WithImageObject
                {
                    Text           = "#IMAGE1#",
                    UseTestMode    = useTestMode,
                    ImageOffset    = PointF.Empty,
                    Style          = ImagesStylesTable["Center"],
                    ReplaceOptions = ReplaceTextOptions.AccordingToMargins,
                    Image          = image
                }));
            }

            #endregion

            #region Create output result

            var result = doc.CreateResult(new OutputResultConfig {
                Zipped = true
            });
            if (!result.Success)
            {
                logger.Info("   > Error creating output result");
                logger.Info($"     > Error: {result.Errors.AsMessages().ToStringBuilder()}");
                return;
            }

            #endregion

            #region Saves output result

            var saveResult = result.Result.Action(new SaveToFile {
                OutputPath = $"~/Output/Sample10/Sample-10"
            });
            var ts = sw.Elapsed;
            sw.Stop();

            if (!saveResult.Success)
            {
                logger.Info("   > Error while saving to disk");
                logger.Info($"     > Error: {saveResult.Errors.AsMessages().ToStringBuilder()}");
                logger.Info($"   > Elapsed time: { ts.Hours:00}:{ ts.Minutes:00}:{ ts.Seconds:00}.{ ts.Milliseconds / 10:00}");
                return;
            }

            logger.Info("   > Saved to disk correctly");
            logger.Info("     > Path: ~/Output/Sample10/Sample-10.zip");
            logger.Info($"   > Elapsed time: { ts.Hours:00}:{ ts.Minutes:00}:{ ts.Seconds:00}.{ ts.Milliseconds / 10:00}");

            #endregion
        }
Exemplo n.º 4
0
        // Generates document
        public static void Generate(ILogger logger, YesNo useTestMode = YesNo.No)
        {
            #region Initialize timer
            var sw = new Stopwatch();
            sw.Start();
            #endregion

            #region Creates pdf file reference

            var doc = new PdfInput
            {
                AutoUpdateChanges = true,
                Input             = "~/Resources/Sample-02/file-sample.pdf"
            };

            #endregion

            #region Replace actions

            // Inserts html table
            doc.Replace(new ReplaceText(
                            new WithTableObject
            {
                Text           = "#DATA-TABLE#",
                UseTestMode    = useTestMode,
                TableOffset    = PointF.Empty,
                Style          = PdfTableStyle.Default,
                ReplaceOptions = ReplaceTextOptions.FromPositionToRightMargin,
                Table          = PdfTable.CreateFromHtml(GenerateHtmlDatatable())
            }));

            #endregion

            #region Create output result

            var result = doc.CreateResult();
            if (!result.Success)
            {
                logger.Info("   > Error creating output result");
                logger.Info($"     > Error: {result.Errors.AsMessages().ToStringBuilder()}");
                return;
            }

            #endregion

            #region Saves output result

            var saveResult = result.Result.Action(new SaveToFile {
                OutputPath = "~/Output/Sample02/Sample-02"
            });
            var ts = sw.Elapsed;
            sw.Stop();

            if (!saveResult.Success)
            {
                logger.Info("   > Error while saving to disk");
                logger.Info($"     > Error: {saveResult.Errors.AsMessages().ToStringBuilder()}");
                return;
            }

            logger.Info("   > Saved to disk correctly");
            logger.Info("     > Path: ~/Output/Sample02/Sample-02.pdf");
            logger.Info($"   > Elapsed time: { ts.Hours:00}:{ ts.Minutes:00}:{ ts.Seconds:00}.{ ts.Milliseconds / 10:00}");

            #endregion
        }