public static void Run()
        {
            // ExStart:AddPageNumber
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            // Create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            // Open Document
            fileStamp.BindPdf(dataDir + "AddPageNumber.pdf");
            
            // Get total number of pages
            int totalPages = new PdfFileInfo(dataDir + "AddPageNumber.pdf").NumberOfPages;

            // Create formatted text for page number
            FormattedText formattedText = new FormattedText("Page # Of " + totalPages, System.Drawing.Color.Blue, System.Drawing.Color.Gray, Aspose.Pdf.Facades.FontStyle.Courier, EncodingType.Winansi, false, 14);

            // Set starting number for first page; you might want to start from 2 or more
            fileStamp.StartingNumber = 1;

            // Add page number
            fileStamp.AddPageNumber(formattedText, 0);

            // Save updated PDF file
            fileStamp.Save(dataDir + "AddPageNumber_out.pdf");

            // Close fileStamp
            fileStamp.Close();
            // ExEnd:AddPageNumber
            
        }
Example #2
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            //create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            //Open Document
            fileStamp.BindPdf(dataDir + "AddTextStampAll.pdf");

            //create stamp
            Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
            stamp.BindLogo(new FormattedText("Hello World!", System.Drawing.Color.Blue, System.Drawing.Color.Gray, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 14));
            stamp.SetOrigin(200, 200);
            stamp.Rotation     = 90.0F;
            stamp.IsBackground = true;

            //add stamp to PDF file
            fileStamp.AddStamp(stamp);

            //save updated PDF file
            fileStamp.Save(dataDir + "AddTextStampAll_out.pdf");

            //close fileStamp
            fileStamp.Close();
        }
Example #3
0
        public static void Run()
        {
            // ExStart:AddPageStampPage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            // Create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            // Open Document
            fileStamp.BindPdf(dataDir + "AddPageStamp-Page.pdf");

            // Create stamp
            Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
            stamp.BindPdf(dataDir + "temp.pdf", 1);
            stamp.SetOrigin(200, 200);
            stamp.Rotation     = 90.0F;
            stamp.IsBackground = true;

            // Set particular pages
            stamp.Pages = new int[] { 2 };

            // Add stamp to PDF file
            fileStamp.AddStamp(stamp);

            // Save updated PDF file
            fileStamp.Save(dataDir + "AddPageStamp-Page_out_.pdf");

            // Close fileStamp
            fileStamp.Close();
            // ExEnd:AddPageStampPage
        }
        public static void Run()
        {
            // ExStart:AddHeader
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            // Create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            // Open Document
            fileStamp.BindPdf(dataDir + "AddHeader.pdf");
         
            // Create formatted text for page number
            FormattedText formattedText = new FormattedText("Aspose - Your File Format Experts!", System.Drawing.Color.Blue, System.Drawing.Color.Gray, Aspose.Pdf.Facades.FontStyle.Courier, EncodingType.Winansi, false, 14);

            // Add header
            fileStamp.AddHeader(formattedText, 10);
           
            // Save updated PDF file
            fileStamp.Save(dataDir + "AddHeader_out.pdf");
            
            // Close fileStamp
            fileStamp.Close();
            // ExEnd:AddHeader
        }
        public static void Run()
        {
            // ExStart:AddFooter
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            // Create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            // Open Document
            fileStamp.BindPdf(dataDir + "AddFooter.pdf");

            // Create formatted text for page number
            FormattedText formattedText = new FormattedText("Aspose - Your File Format Experts!", System.Drawing.Color.Blue, System.Drawing.Color.Gray, Aspose.Pdf.Facades.FontStyle.Courier, EncodingType.Winansi, false, 14);

            // Add footer
            fileStamp.AddFooter(formattedText, 10);

            // Save updated PDF file
            fileStamp.Save(dataDir + "AddFooter_out.pdf");

            // Close fileStamp
            fileStamp.Close();
            // ExEnd:AddFooter
        }
Example #6
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            //create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            //Open Document
            fileStamp.BindPdf(dataDir + "Input_new.pdf");

            //get total number of pages
            int totalPages = new PdfFileInfo(dataDir + "Input_new.pdf").NumberOfPages;

            //create formatted text for page number
            FormattedText formattedText = new FormattedText("Page # Of " + totalPages, System.Drawing.Color.Blue, System.Drawing.Color.Gray, Aspose.Pdf.Facades.FontStyle.Courier, EncodingType.Winansi, false, 14);

            //set starting number for first page; you might want to start from 2 or more
            fileStamp.StartingNumber = 1;

            //add page number
            fileStamp.AddPageNumber(formattedText, 0);

            //save updated PDF file
            fileStamp.Save(dataDir + "AddPageNumber_out.pdf");

            //close fileStamp
            fileStamp.Close();
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            //create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            //Open Document
            fileStamp.BindPdf(dataDir + "AddTextStampAll.pdf"); 
           
            //create stamp
            Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
            stamp.BindLogo(new FormattedText("Hello World!", System.Drawing.Color.Blue, System.Drawing.Color.Gray, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 14));
            stamp.SetOrigin(200, 200);
            stamp.Rotation = 90.0F;
            stamp.IsBackground = true;

            //add stamp to PDF file
            fileStamp.AddStamp(stamp);

            //save updated PDF file
            fileStamp.Save(dataDir + "AddTextStampAll_out.pdf");

            //close fileStamp
            fileStamp.Close();
 
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            //create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            //Open Document
            fileStamp.BindPdf(dataDir + "AddPageStamp-Page.pdf");
 
            //create stamp
            Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
            stamp.BindPdf(dataDir+ "temp.pdf", 1);
            stamp.SetOrigin(200, 200);
            stamp.Rotation = 90.0F;
            stamp.IsBackground = true;

            //set particular pages
            stamp.Pages = new int[] { 2 };

            //add stamp to PDF file
            fileStamp.AddStamp(stamp);

            //save updated PDF file
            fileStamp.Save(dataDir + "AddPageStamp-Page_out.pdf");

            //close fileStamp
            fileStamp.Close();
 
        }
Example #9
0
        public static void Run()
        {
            // ExStart:AddImageStampAll
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            // Create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            // Open Document
            fileStamp.BindPdf(dataDir + "AddImageStampAll.pdf");

            // Create stamp
            Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
            stamp.BindImage(dataDir + "aspose-logo.jpg");
            stamp.SetOrigin(200, 200);
            stamp.Rotation     = 90.0F;
            stamp.IsBackground = true;

            // Add stamp to PDF file
            fileStamp.AddStamp(stamp);

            // Save updated PDF file
            fileStamp.Save(dataDir + "AddImageStampAll_out_.pdf");

            // Close fileStamp
            fileStamp.Close();
            // ExEnd:AddImageStampAll
        }
        public static void Run()
        {
            // ExStart:AddPageStampAll
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            // Create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            // Open Document
            fileStamp.BindPdf(dataDir + "AddPageStampAll.pdf"); 

            // Create stamp
            Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
            stamp.BindPdf(dataDir+ "temp.pdf", 1);
            stamp.SetOrigin(200, 200);
            stamp.Rotation = 90.0F;
            stamp.IsBackground = true;

            // Add stamp to PDF file
            fileStamp.AddStamp(stamp);

            // Save updated PDF file
            fileStamp.Save(dataDir + "AddPageStampAll_out.pdf");

            // Close fileStamp
            fileStamp.Close();
            // ExEnd:AddPageStampAll
            
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            //create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            //Open Document
            fileStamp.BindPdf(dataDir + "AddImageStamp-Page.pdf");

            //create stamp
            Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
            stamp.BindImage(dataDir + "aspose-logo.jpg");
            stamp.SetOrigin(200, 200);
            stamp.Rotation     = 90.0F;
            stamp.IsBackground = true;

            //set particular pages
            stamp.Pages = new int[] { 1 };

            //add stamp to PDF file
            fileStamp.AddStamp(stamp);

            //save updated PDF file
            fileStamp.Save(dataDir + "AddImageStamp-Page_out.pdf");

            //close fileStamp
            fileStamp.Close();
        }
 public static void CustomNumberStyle()
 {
     // ExStart:CustomNumberStyle
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();
     // Create PdfFileStamp object
     PdfFileStamp fileStamp = new PdfFileStamp();
     // Open Document
     fileStamp.BindPdf(dataDir + "AddPageNumber.pdf");
     // Specify numbering style as Numerals Roman UpperCase
     fileStamp.NumberingStyle = NumberingStyle.NumeralsRomanUppercase;
     // Add page number stamp at Bottom-Center of page
     fileStamp.AddPageNumber("#");
     // Save updated PDF file
     fileStamp.Save(dataDir + "CustomNumberStyle_out.pdf");
     // ExEnd:CustomNumberStyle
 }
        public static void CustomNumberStyle()
        {
            // ExStart:CustomNumberStyle
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();
            // Create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            // Open Document
            fileStamp.BindPdf(dataDir + "AddPageNumber.pdf");
            // Specify numbering style as Numerals Roman UpperCase
            fileStamp.NumberingStyle = NumberingStyle.NumeralsRomanUppercase;
            // Add page number stamp at Bottom-Center of page
            fileStamp.AddPageNumber("#");
            // Save updated PDF file
            fileStamp.Save(dataDir + "CustomNumberStyle_out_.pdf");
            // ExEnd:CustomNumberStyle
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            //create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            //Open Document
            fileStamp.BindPdf(dataDir + "AddImage-Footer.pdf");

            //add footer
            fileStamp.AddFooter(new FileStream(dataDir + "aspose-logo.jpg", FileMode.Open), 10);

            //save updated PDF file
            fileStamp.Save(dataDir + "AddImage-Footer_out.pdf");

            //close fileStamp
            fileStamp.Close();
        }
        public static void Run()
        {
            // ExStart:AddImageHeader
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            // Create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            // Open Document
            fileStamp.BindPdf(dataDir + "AddImage-Header.pdf");

            // Add Header
            fileStamp.AddHeader(new FileStream(dataDir + "AddImageHeader.jpg", FileMode.Open), 10);

            // Save updated PDF file
            fileStamp.Save(dataDir + "AddImage-Header_out.pdf");

            // Close fileStamp
            fileStamp.Close();
            // ExEnd:AddImageHeader
        }
Example #16
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            //create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            //Open Document
            fileStamp.BindPdf(dataDir + "AddImage-Footer.pdf");

            //add footer
            fileStamp.AddFooter(new FileStream(dataDir+ "aspose-logo.jpg", FileMode.Open), 10);

            //save updated PDF file
            fileStamp.Save(dataDir + "AddImage-Footer_out.pdf");

            //close fileStamp
            fileStamp.Close();
 
            
        }
        public static void Run()
        {
            // ExStart:AddImageHeader
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks();

            // Create PdfFileStamp object
            PdfFileStamp fileStamp = new PdfFileStamp();

            // Open Document
            fileStamp.BindPdf(dataDir + "AddImage-Header.pdf");

            // Add Header
            fileStamp.AddHeader(new FileStream(dataDir + "AddImageHeader.jpg", FileMode.Open), 10);

            // Save updated PDF file
            fileStamp.Save(dataDir + "AddImage-Header_out.pdf");

            // Close fileStamp
            fileStamp.Close();
            // ExEnd:AddImageHeader
            
        }
        /// <summary>
        /// adds the header and footer details to the given pathTotempPdf, and creates the offical pdf location.
        /// </summary>
        public void AddHeaderAndFooter(string pathToTempPdfFile)
        {
            PdfFileStamp fileStamp = null;
            try
            {
                fileStamp = new PdfFileStamp();
                fileStamp.BindPdf(pathToTempPdfFile);
                FormattedText ftSubjectID = null;
                FormattedText ftMedrioID = null;
                System.Drawing.Color fontColor = System.Drawing.Color.Black;

                if (CustomSubjectID)
                {
                    ftSubjectID = new FormattedText(string.Format("Subject Identifier: {0}", SubjectIdentifier)
                                                    , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);
                }

                if (IsMedrioIDShown)
                {
                    ftMedrioID = new FormattedText(string.Format("Medrio ID: {0}", Subject.FormatMedrioSubjectID(MedrioSubjectID))
                        , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);
                }

                FormattedText ftSite = new FormattedText(HeaderItemText("Site: ", SiteName, HEADER_LABELWIDTH)
                        , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);
                FormattedText ftVisit = new FormattedText(HeaderItemText(Study.VisitLabelSingular + ": ", VisitName, HEADER_LABELWIDTH)
                        , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);
                FormattedText ftGroup = new FormattedText(HeaderItemText("Group: ", GroupName, HEADER_LABELWIDTH)
                        , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);
                FormattedText ftForm = new FormattedText(HeaderItemText("Form: ", FormName, HEADER_LABELWIDTH)
                        , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);
                FormattedText ftStudy = new FormattedText(string.Format("{0}", StudyTitle)
                        , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);

                //add header
                int medrioIdTopMargin = 20;
                if (null != ftSubjectID)
                {
                    fileStamp.AddHeader(ftSubjectID, 20, 25, 0);
                    medrioIdTopMargin = 30;
                }
                if (null != ftMedrioID)
                {
                    fileStamp.AddHeader(ftMedrioID, medrioIdTopMargin, 25, 0);
                }
                fileStamp.AddHeader(ftSite, 20, fileStamp.PageWidth / 2, fileStamp.PageWidth / 2);
                fileStamp.AddHeader(ftVisit, 30, fileStamp.PageWidth / 2, fileStamp.PageWidth / 2);
                fileStamp.AddHeader(ftGroup, 20, 0, 50);
                fileStamp.AddHeader(ftForm, 30, 0, 50);

                TimeZoneInfo tzi = null;
                try
                {
                    tzi = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneFormatForCurrentUser);
                }
                catch
                {
                    tzi = TimeZoneInfo.Local;
                }

                DateTime dt = TimeZoneInfo.ConvertTime(DateTime.UtcNow, tzi);

                FormattedText ftDatetime = new FormattedText(string.Format("{0} {1:HH:mm} ({2})", dt.ToString(ExportDateFormat), dt, TimeZoneFormatForCurrentUser)
                        , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);

                // add footer
                fileStamp.AddFooter(ftStudy, 20, fileStamp.PageWidth / 2, fileStamp.PageWidth / 2);
                fileStamp.AddFooter(ftDatetime, 20, 25, 0);
                fileStamp.Save(PathToPdf);
            }
            finally
            {
                if (fileStamp != null)
                {
                    //close
                    fileStamp.Dispose();
                }
            }
        }
Example #19
0
        public ActionResult <Response> ConcatenateWithContents([FromBody] Request request)
        {
            try
            {
                Stopwatch stopwatch1 = new Stopwatch();
                stopwatch1.Start();

                PdfFileEditor pdfEditor = new PdfFileEditor();

                using (MemoryStream Concatenated_Stream = new MemoryStream())
                {
                    string concFilename = "Concatenated_Table_Of_Contents.pdf";

                    List <System.IO.Stream> pdfStreams = new List <System.IO.Stream>();
                    string[] files = System.IO.Directory.GetFiles(serverDirectory);
                    foreach (string file in files)
                    {
                        if (file.ToLower().Contains(concFilename.ToLower()))
                        {
                            continue;
                        }
                        if (!Path.GetExtension(file).Equals(".pdf"))
                        {
                            continue;
                        }
                        System.IO.FileStream stream = new System.IO.FileStream(file, System.IO.FileMode.Open);
                        pdfStreams.Add(stream);
                    }

                    //System.IO.FileStream outputPDF = new System.IO.FileStream(serverDirectory + request.filename + ".pdf", System.IO.FileMode.Create);
                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();

                    pdfEditor.Concatenate(pdfStreams.ToArray(), Concatenated_Stream);

                    stopwatch2.Stop();
                    Console.WriteLine("PdfEditor.Concatenate Action: " + stopwatch2.ElapsedMilliseconds.ToString());

                    // Insert a blank page at the begining of concatenated file to display Table of Contents
                    Aspose.Pdf.Document concatenated_pdfDocument = new Aspose.Pdf.Document(Concatenated_Stream);
                    // Insert a empty page in a PDF
                    concatenated_pdfDocument.Pages.Insert(1);

                    using (MemoryStream Document_With_BlankPage = new MemoryStream())
                    {
                        // Save output file

                        stopwatch2.Reset();
                        stopwatch2.Start();
                        concatenated_pdfDocument.Save(Document_With_BlankPage);

                        stopwatch2.Stop();
                        Console.WriteLine("Concatenated_pdfDocument.Save Action: " + stopwatch2.ElapsedMilliseconds.ToString());

                        using (var Document_with_TOC_Heading = new MemoryStream())
                        {
                            // Add Table Of Contents logo as stamp to PDF file
                            PdfFileStamp fileStamp = new PdfFileStamp();
                            // Find the input file
                            fileStamp.BindPdf(Document_With_BlankPage);

                            // Set Text Stamp to display string Table Of Contents
                            Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
                            stamp.BindLogo(new FormattedText("Table Of Contents", System.Drawing.Color.Maroon, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 18));
                            // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp
                            stamp.SetOrigin((new PdfFileInfo(Document_With_BlankPage).GetPageWidth(1) / 3), 700);
                            // Set particular pages
                            stamp.Pages = new int[] { 1 };
                            // Add stamp to PDF file

                            stopwatch2.Reset();
                            stopwatch2.Start();
                            fileStamp.AddStamp(stamp);

                            stopwatch2.Stop();
                            Console.WriteLine("FileStamp.AddStamp Action: " + stopwatch2.ElapsedMilliseconds.ToString());

                            int counter = 1;
                            int diff    = 0;
                            foreach (System.IO.Stream stream in pdfStreams)
                            {
                                var Document_Link = new Aspose.Pdf.Facades.Stamp();
                                Document_Link.BindLogo(new FormattedText(counter + " - Link to Document " + counter, System.Drawing.Color.Black, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 12));
                                Document_Link.SetOrigin(150, 650 - diff);
                                Document_Link.Pages = new int[] { 1 };
                                fileStamp.AddStamp(Document_Link);
                                counter++;
                                diff += 40;
                            }

                            stopwatch2.Reset();
                            stopwatch2.Start();
                            fileStamp.Save(Document_with_TOC_Heading);
                            stopwatch2.Stop();
                            Console.WriteLine("FileStamp.Save Action: " + stopwatch2.ElapsedMilliseconds.ToString());


                            fileStamp.Close();

                            PdfContentEditor contentEditor = new PdfContentEditor();
                            // Bind the PDF file in which we added the blank page
                            contentEditor.BindPdf(Document_with_TOC_Heading);

                            counter = 1;
                            diff    = 0;
                            int numberOfpagesOfPreviousFile = 0;
                            foreach (System.IO.Stream stream in pdfStreams)
                            {
                                if (counter == 1)
                                {
                                    contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 650 - diff, 100, 20), counter + 1, 1, System.Drawing.Color.Transparent);
                                }
                                else
                                {
                                    //Replace counter with numberOfpagesOfPreviousFile of the following line to fix Link page number
                                    contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 650 - diff, 100, 20), counter + 1, 1, System.Drawing.Color.Transparent);
                                }
                                counter++;
                                numberOfpagesOfPreviousFile = new PdfFileInfo(stream).NumberOfPages;
                                diff += 40;
                            }

                            if (System.IO.File.Exists(serverDirectory + concFilename))
                            {
                                System.IO.File.Delete(serverDirectory + concFilename);
                            }

                            stopwatch2.Reset();
                            stopwatch2.Start();

                            contentEditor.Save(serverDirectory + concFilename);

                            stopwatch2.Stop();
                            Console.WriteLine("FileStamp.Save Action: " + stopwatch2.ElapsedMilliseconds.ToString());
                        }
                    }
                }

                stopwatch1.Stop();
                Console.WriteLine("Total Time: " + stopwatch1.ElapsedMilliseconds.ToString());

                return(new Response()
                {
                    FileContent = string.Empty,
                    FileName = "Concatenated_Table_Of_Contents.pdf",
                    Message = "Files Concatenated successfully to: Concatenated_Table_Of_Contents.pdf file",
                    Success = true
                });
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    FileContent = string.Empty,
                    FileName = "",
                    Message = "Could not concatenate files. " + ex.Message,
                    Success = false
                });
            }
        }
        public static void CompletedCode()
        {
            // ExStart:CompletedCode
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create a MemoryStream object to hold the resultant PDf file
            using (MemoryStream Concatenated_Stream = new MemoryStream())
            {
                // Save concatenated output file
                pdfEditor.Concatenate(new FileStream(dataDir + "input1.pdf", FileMode.Open), new FileStream(dataDir + "input2.pdf", FileMode.Open), Concatenated_Stream);
                // Insert a blank page at the begining of concatenated file to display Table of Contents
                Aspose.Pdf.Document concatenated_pdfDocument = new Aspose.Pdf.Document(Concatenated_Stream);
                // Insert a empty page in a PDF
                concatenated_pdfDocument.Pages.Insert(1);

                // Hold the resultnat file with empty page added
                using (MemoryStream Document_With_BlankPage = new MemoryStream())
                {
                    // Save output file
                    concatenated_pdfDocument.Save(Document_With_BlankPage);

                    using (var Document_with_TOC_Heading = new MemoryStream())
                    {
                        // Add Table Of Contents logo as stamp to PDF file
                        PdfFileStamp fileStamp = new PdfFileStamp();
                        // Find the input file
                        fileStamp.BindPdf(Document_With_BlankPage);

                        // Set Text Stamp to display string Table Of Contents
                        Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
                        stamp.BindLogo(new FormattedText("Table Of Contents", System.Drawing.Color.Maroon, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 18));
                        // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp
                        stamp.SetOrigin((new PdfFileInfo(Document_With_BlankPage).GetPageWidth(1) / 3), 700);
                        // Set particular pages
                        stamp.Pages = new int[] { 1 };
                        // Add stamp to PDF file
                        fileStamp.AddStamp(stamp);

                        // Create stamp text for first item in Table Of Contents
                        var Document1_Link = new Aspose.Pdf.Facades.Stamp();
                        Document1_Link.BindLogo(new FormattedText("1 - Link to Document 1", System.Drawing.Color.Black, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 12));
                        // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp
                        Document1_Link.SetOrigin(150, 650);
                        // Set particular pages on which stamp should be displayed
                        Document1_Link.Pages = new int[] { 1 };
                        // Add stamp to PDF file
                        fileStamp.AddStamp(Document1_Link);

                        // Create stamp text for second item in Table Of Contents
                        var Document2_Link = new Aspose.Pdf.Facades.Stamp();
                        Document2_Link.BindLogo(new FormattedText("2 - Link to Document 2", System.Drawing.Color.Black, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 12));
                        // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp
                        Document2_Link.SetOrigin(150, 620);
                        // Set particular pages on which stamp should be displayed
                        Document2_Link.Pages = new int[] { 1 };
                        // Add stamp to PDF file
                        fileStamp.AddStamp(Document2_Link);

                        // Save updated PDF file
                        fileStamp.Save(Document_with_TOC_Heading);
                        fileStamp.Close();

                        // Now we need to add Heading for Table Of Contents and links for documents
                        PdfContentEditor contentEditor = new PdfContentEditor();
                        // Bind the PDF file in which we added the blank page
                        contentEditor.BindPdf(Document_with_TOC_Heading);
                        // Create link for first document
                        contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 650, 100, 20), 2, 1, System.Drawing.Color.Transparent);
                        // Create link for Second document
                        // We have used   new PdfFileInfo("d:/pdftest/Input1.pdf").NumberOfPages + 2   as PdfFileInfo.NumberOfPages(..) returns the page count for first document
                        // And 2 is because, second document will start at Input1+1 and 1 for the page containing Table Of Contents.
                        contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 620, 100, 20), new PdfFileInfo(dataDir + "Input1.pdf").NumberOfPages + 2, 1, System.Drawing.Color.Transparent);

                        // Save updated PDF
                        contentEditor.Save( dataDir + "Concatenated_Table_Of_Contents.pdf");
                    }
                }
            }
            // ExEnd:CompletedCode
        }
Example #21
0
        /// <summary>
        /// adds the header and footer details to the given pathTotempPdf, and creates the offical pdf location.
        /// </summary>
        public void AddHeaderAndFooter(string pathToTempPdfFile)
        {
            PdfFileStamp fileStamp = null;

            try
            {
                fileStamp = new PdfFileStamp();
                fileStamp.BindPdf(pathToTempPdfFile);
                FormattedText        ftSubjectID = null;
                FormattedText        ftMedrioID  = null;
                System.Drawing.Color fontColor   = System.Drawing.Color.Black;

                if (CustomSubjectID)
                {
                    ftSubjectID = new FormattedText(string.Format("Subject Identifier: {0}", SubjectIdentifier)
                                                    , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);
                }

                if (IsMedrioIDShown)
                {
                    ftMedrioID = new FormattedText(string.Format("Medrio ID: {0}", Subject.FormatMedrioSubjectID(MedrioSubjectID))
                                                   , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);
                }

                FormattedText ftSite = new FormattedText(HeaderItemText("Site: ", SiteName, HEADER_LABELWIDTH)
                                                         , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);
                FormattedText ftVisit = new FormattedText(HeaderItemText(Study.VisitLabelSingular + ": ", VisitName, HEADER_LABELWIDTH)
                                                          , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);
                FormattedText ftGroup = new FormattedText(HeaderItemText("Group: ", GroupName, HEADER_LABELWIDTH)
                                                          , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);
                FormattedText ftForm = new FormattedText(HeaderItemText("Form: ", FormName, HEADER_LABELWIDTH)
                                                         , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);
                FormattedText ftStudy = new FormattedText(string.Format("{0}", StudyTitle)
                                                          , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);

                //add header
                int medrioIdTopMargin = 20;
                if (null != ftSubjectID)
                {
                    fileStamp.AddHeader(ftSubjectID, 20, 25, 0);
                    medrioIdTopMargin = 30;
                }
                if (null != ftMedrioID)
                {
                    fileStamp.AddHeader(ftMedrioID, medrioIdTopMargin, 25, 0);
                }
                fileStamp.AddHeader(ftSite, 20, fileStamp.PageWidth / 2, fileStamp.PageWidth / 2);
                fileStamp.AddHeader(ftVisit, 30, fileStamp.PageWidth / 2, fileStamp.PageWidth / 2);
                fileStamp.AddHeader(ftGroup, 20, 0, 50);
                fileStamp.AddHeader(ftForm, 30, 0, 50);

                TimeZoneInfo tzi = null;
                try
                {
                    tzi = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneFormatForCurrentUser);
                }
                catch
                {
                    tzi = TimeZoneInfo.Local;
                }

                DateTime dt = TimeZoneInfo.ConvertTime(DateTime.UtcNow, tzi);

                FormattedText ftDatetime = new FormattedText(string.Format("{0} {1:HH:mm} ({2})", dt.ToString(ExportDateFormat), dt, TimeZoneFormatForCurrentUser)
                                                             , fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);

                // add footer
                fileStamp.AddFooter(ftStudy, 20, fileStamp.PageWidth / 2, fileStamp.PageWidth / 2);
                fileStamp.AddFooter(ftDatetime, 20, 25, 0);
                fileStamp.Save(PathToPdf);
            }
            finally
            {
                if (fileStamp != null)
                {
                    //close
                    fileStamp.Dispose();
                }
            }
        }
Example #22
0
        public static void CompletedCode()
        {
            // ExStart:CompletedCode
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();

            // Create a MemoryStream object to hold the resultant PDf file
            using (MemoryStream Concatenated_Stream = new MemoryStream())
            {
                // Save concatenated output file
                pdfEditor.Concatenate(new FileStream(dataDir + "input1.pdf", FileMode.Open), new FileStream(dataDir + "input2.pdf", FileMode.Open), Concatenated_Stream);
                // Insert a blank page at the begining of concatenated file to display Table of Contents
                Aspose.Pdf.Document concatenated_pdfDocument = new Aspose.Pdf.Document(Concatenated_Stream);
                // Insert a empty page in a PDF
                concatenated_pdfDocument.Pages.Insert(1);

                // Hold the resultnat file with empty page added
                using (MemoryStream Document_With_BlankPage = new MemoryStream())
                {
                    // Save output file
                    concatenated_pdfDocument.Save(Document_With_BlankPage);

                    using (var Document_with_TOC_Heading = new MemoryStream())
                    {
                        // Add Table Of Contents logo as stamp to PDF file
                        PdfFileStamp fileStamp = new PdfFileStamp();
                        // Find the input file
                        fileStamp.BindPdf(Document_With_BlankPage);

                        // Set Text Stamp to display string Table Of Contents
                        Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
                        stamp.BindLogo(new FormattedText("Table Of Contents", System.Drawing.Color.Maroon, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 18));
                        // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp
                        stamp.SetOrigin((new PdfFileInfo(Document_With_BlankPage).GetPageWidth(1) / 3), 700);
                        // Set particular pages
                        stamp.Pages = new int[] { 1 };
                        // Add stamp to PDF file
                        fileStamp.AddStamp(stamp);

                        // Create stamp text for first item in Table Of Contents
                        var Document1_Link = new Aspose.Pdf.Facades.Stamp();
                        Document1_Link.BindLogo(new FormattedText("1 - Link to Document 1", System.Drawing.Color.Black, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 12));
                        // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp
                        Document1_Link.SetOrigin(150, 650);
                        // Set particular pages on which stamp should be displayed
                        Document1_Link.Pages = new int[] { 1 };
                        // Add stamp to PDF file
                        fileStamp.AddStamp(Document1_Link);

                        // Create stamp text for second item in Table Of Contents
                        var Document2_Link = new Aspose.Pdf.Facades.Stamp();
                        Document2_Link.BindLogo(new FormattedText("2 - Link to Document 2", System.Drawing.Color.Black, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 12));
                        // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp
                        Document2_Link.SetOrigin(150, 620);
                        // Set particular pages on which stamp should be displayed
                        Document2_Link.Pages = new int[] { 1 };
                        // Add stamp to PDF file
                        fileStamp.AddStamp(Document2_Link);

                        // Save updated PDF file
                        fileStamp.Save(Document_with_TOC_Heading);
                        fileStamp.Close();

                        // Now we need to add Heading for Table Of Contents and links for documents
                        PdfContentEditor contentEditor = new PdfContentEditor();
                        // Bind the PDF file in which we added the blank page
                        contentEditor.BindPdf(Document_with_TOC_Heading);
                        // Create link for first document
                        contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 650, 100, 20), 2, 1, System.Drawing.Color.Transparent);
                        // Create link for Second document
                        // We have used   new PdfFileInfo("d:/pdftest/Input1.pdf").NumberOfPages + 2   as PdfFileInfo.NumberOfPages(..) returns the page count for first document
                        // and 2 is because, second document will start at Input1+1 and 1 for the page containing Table Of Contents.
                        contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 620, 100, 20), new PdfFileInfo(dataDir + "Input1.pdf").NumberOfPages + 2, 1, System.Drawing.Color.Transparent);

                        // Save updated PDF
                        contentEditor.Save(dataDir + "Concatenated_Table_Of_Contents.pdf");
                    }
                }
            }
            // ExEnd:CompletedCode
        }