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

            // Create two file streams to read pdf files
            FileStream fs1 = new FileStream(dataDir + "inFile.pdf", FileMode.Open, FileAccess.Read);
            FileStream fs2 = new FileStream(dataDir + "inFile2.pdf", FileMode.Open, FileAccess.Read);

            // Create byte arrays to keep the contents of PDF files
            byte[] buffer1 = new byte[Convert.ToInt32(fs1.Length)];
            byte[] buffer2 = new byte[Convert.ToInt32(fs2.Length)];


            int i = 0;
            // Read PDF file contents into byte arrays
            i = fs1.Read(buffer1, 0, Convert.ToInt32(fs1.Length));
            i = fs2.Read(buffer2, 0, Convert.ToInt32(fs2.Length));

            // Now, first convert byte arrays into MemoryStreams and then concatenate those streams
            using (MemoryStream pdfStream = new MemoryStream())
            {
                using (MemoryStream fileStream1 = new MemoryStream(buffer1))
                {
                    using (MemoryStream fileStream2 = new MemoryStream(buffer2))
                    {
                        // Create instance of PdfFileEditor class to concatenate streams
                        PdfFileEditor pdfEditor = new PdfFileEditor();
                        // Concatenate both input MemoryStreams and save to putput MemoryStream
                        pdfEditor.Concatenate(fileStream1, fileStream2, pdfStream);
                        // Convert MemoryStream back to byte array
                        byte[] data = pdfStream.ToArray();
                        // Create a FileStream to save the output PDF file
                        FileStream output = new FileStream(dataDir + "merged_out.pdf", FileMode.Create,
                        FileAccess.Write);
                        // Write byte array contents in the output file stream
                        output.Write(data, 0, data.Length);
                        // Close output file
                        output.Close();
                    }
                }
            }
            // Close input files
            fs1.Close();
            fs2.Close();
            // ExEnd:ConcatenateMultiplePDFUsingMemoryStream                      
        }
        public static void Run()
        {
            // ExStart:ResizePageContents
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor Object
            PdfFileEditor fileEditor = new PdfFileEditor();

            // Open PDF Document
            Document doc = new Document(dataDir + "input.pdf");

            // Specify Parameter to be used for resizing
            PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(
            // Left margin = 10% of page width
            PdfFileEditor.ContentsResizeValue.Percents(10),
            // New contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%)
            null,
            // Right margin is 10% of page
            PdfFileEditor.ContentsResizeValue.Percents(10),
            // Top margin = 10% of height
            PdfFileEditor.ContentsResizeValue.Percents(10),
            // New contents height is calculated automatically (similar to width)
            null,
            // Bottom margin is 10%
            PdfFileEditor.ContentsResizeValue.Percents(10)
            );

            // Resize Page Contents
            fileEditor.ResizeContents(doc, new int[] { 1, 2 }, parameters);

            // Save document into new location.
            doc.Save(dataDir + "ResizePageContents_out.pdf");
            // ExEnd:ResizePageContents
        }
 public static void Run()
 {
     try
     {
         // ExStart:PageBreak
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdfFacades_WorkingDocuments();
         // Instantiate Document instance
         Document doc = new Document(dataDir + "input.pdf");
         // Instantiate blank Document instance
         Document dest = new Document();
         // Create PdfFileEditor object
         PdfFileEditor fileEditor = new PdfFileEditor();
         fileEditor.AddPageBreak(doc, dest, new PdfFileEditor.PageBreak[] 
         { 
             new PdfFileEditor.PageBreak(1, 450) 
         });
         // Save resultant file
         dest.Save(dataDir + "PageBreak_out.pdf");
         // ExEnd:PageBreak  
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
     }
     
 }
Exemple #4
0
        public static void Run()
        {
            // ExStart:SplitPagesToBulkUsingStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create input stream
            FileStream inputStream = new FileStream(dataDir + "MultiplePages.pdf", FileMode.Open);
            int        fileNumber  = 1;

            // Create array of pages to split
            int[][] numberOfPages = new int[][] { new int[] { 1, 2 }, new int[] { 3, 4 } };
            // Split to bulk
            MemoryStream[] outBuffer = pdfEditor.SplitToBulks(inputStream, numberOfPages);
            // Save individual files
            foreach (MemoryStream aStream in outBuffer)
            {
                FileStream outStream = new FileStream(dataDir + "File_" + fileNumber.ToString() + "_out_.pdf", FileMode.Create);
                aStream.WriteTo(outStream);
                outStream.Close();
                fileNumber++;
            }
            // ExEnd:SplitPagesToBulkUsingStreams
        }
        public static void AddMargins(string packagedFile, Package package, Config config)
        {
            PdfFileEditor fileEditor = new PdfFileEditor();
            var           pageMargin = PageSetting.GetBodyMargin(package, config);

            fileEditor.AddMargins(packagedFile, packagedFile, null, pageMargin.LeftPoints, pageMargin.RightPoints, pageMargin.TopPoints, pageMargin.BottomPoints);
        }
Exemple #6
0
        public static void Run()
        {
            // ExStart:ResizePageContents
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor Object
            PdfFileEditor fileEditor = new PdfFileEditor();

            // Open PDF Document
            Document doc = new Document(dataDir + "input.pdf");

            // Specify Parameter to be used for resizing
            PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(
                // Left margin = 10% of page width
                PdfFileEditor.ContentsResizeValue.Percents(10),
                // New contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%)
                null,
                // Right margin is 10% of page
                PdfFileEditor.ContentsResizeValue.Percents(10),
                // Top margin = 10% of height
                PdfFileEditor.ContentsResizeValue.Percents(10),
                // New contents height is calculated automatically (similar to width)
                null,
                // Bottom margin is 10%
                PdfFileEditor.ContentsResizeValue.Percents(10)
                );

            // Resize Page Contents
            fileEditor.ResizeContents(doc, new int[] { 1, 2 }, parameters);

            // Save document into new location.
            doc.Save(dataDir + "ResizePageContents_out_.pdf");
            // ExEnd:ResizePageContents
        }
        public static void Run()
        {
            // ExStart:SplitPagesToBulkUsingStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create input stream
            FileStream inputStream = new FileStream(dataDir + "MultiplePages.pdf", FileMode.Open);
            int fileNumber = 1;
            // Create array of pages to split
            int[][] numberOfPages = new int[][] { new int[] { 1, 2 }, new int[] { 3, 4} };
            // Split to bulk
            MemoryStream[] outBuffer = pdfEditor.SplitToBulks(inputStream, numberOfPages);
            // Save individual files
            foreach (MemoryStream aStream in outBuffer)
            {
                FileStream outStream = new FileStream(dataDir + "File_" + fileNumber.ToString() + "_out.pdf", FileMode.Create);
                aStream.WriteTo(outStream);
                outStream.Close();
                fileNumber++;
            }
            // ExEnd:SplitPagesToBulkUsingStreams
        }
Exemple #8
0
        public ActionResult <Response> UploadFile([FromBody] Request request)
        {
            try
            {
                //System.IO.Directory.CreateDirectory(outputConcDir);

                PdfFileEditor pdfEditor = new PdfFileEditor();

                Byte[] bitmapData = Convert.FromBase64String(request.filecontent.Split(",").Last());
                System.IO.MemoryStream streamBitmap = new System.IO.MemoryStream(bitmapData);

                System.IO.FileStream outputPDF = new System.IO.FileStream(serverDirectory + request.filename, System.IO.FileMode.Create);

                pdfEditor.Concatenate(new System.IO.MemoryStream[] { streamBitmap }, outputPDF);
                outputPDF.Close();

                return(new Response()
                {
                    FileContent = string.Empty,
                    FileName = string.Empty,
                    Message = "File Uploaded successfully",
                    Success = true
                });
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    FileContent = string.Empty,
                    FileName = "",
                    Message = "Could not upload file. " + ex.Message,
                    Success = false
                });
            }
        }
Exemple #9
0
 public static void Run()
 {
     try
     {
         // ExStart:PageBreak
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdfFacades_WorkingDocuments();
         // Instantiate Document instance
         Document doc = new Document(dataDir + "input.pdf");
         // Instantiate blank Document instance
         Document dest = new Document();
         // Create PdfFileEditor object
         PdfFileEditor fileEditor = new PdfFileEditor();
         fileEditor.AddPageBreak(doc, dest, new PdfFileEditor.PageBreak[]
         {
             new PdfFileEditor.PageBreak(1, 450)
         });
         // Save resultant file
         dest.Save(dataDir + "PageBreak_out_.pdf");
         // ExEnd:PageBreak
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
     }
 }
        ///<Summary>
        /// Split method to split pdf document
        ///</Summary>

        public Response Splitter(DocumentInfo[] docs, string sourceFolder)
        {
            if (docs == null)
            {
                return(BadDocumentResponse);
            }
            if (docs.Length <= 0 || docs.Length > MaximumUploadFiles)
            {
                return(MaximumFileLimitsResponse);
            }

            SetDefaultOptions(docs, "");
            Opts.AppName     = "Splitter";
            Opts.MethodName  = "Splitter";
            Opts.FolderName  = sourceFolder;
            Opts.CreateZip   = true;
            Opts.ZipFileName = "Splitted document";

            return(Process((inFilePath, outPath, zipOutFolder) =>
            {
                foreach (var doc in docs)
                {
                    PdfFileEditor pdfEditor = new PdfFileEditor();
                    pdfEditor.SplitToPages(doc.FileName, $"{zipOutFolder}\\{Path.GetFileNameWithoutExtension(doc.FileName)}_%NUM%.pdf");
                }
            }));
        }
 public static void Run()
 {
     // ExStart:ConcatenateUsingPath
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();
     // Create PdfFileEditor object
     PdfFileEditor pdfEditor = new PdfFileEditor();
     // Concatenate files
     pdfEditor.Concatenate(dataDir + "input.pdf", dataDir + "input2.pdf", dataDir + "ConcatenateUsingPath_out.pdf");
     // ExEnd:ConcatenateUsingPath
 }
        public static void Run()
        {
            // ExStart:MakeNUpUsingPageSizeAndPaths
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Make NUp
            pdfEditor.MakeNUp(dataDir + "MultiplePages.pdf", dataDir + "MakeNUpUsingPageSizeAndPaths_out.pdf", 2, 3, PageSize.A5);
            // ExEnd:MakeNUpUsingPageSizeAndPaths
        }
        public static void Run()
        {
            // ExStart:InsertPagesBetweenNumbers
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Insert pages
            pdfEditor.Insert(dataDir + "MultiplePages.pdf", 1, dataDir + "InsertPages.pdf", 2, 5,  dataDir + "InsertPagesBetweenNumbers_out.pdf");
            // ExEnd:InsertPagesBetweenNumbers
        }
        public static void Run()
        {
            // ExStart:ConcatenateUsingPath
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();
            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();

            // Concatenate files
            pdfEditor.Concatenate(dataDir + "input.pdf", dataDir + "input2.pdf", dataDir + "ConcatenateUsingPath_out_.pdf");
            // ExEnd:ConcatenateUsingPath
        }
        public static void Run()
        {
            // ExStart:UsingPageSizeHorizontalAndVerticalValues
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Make NUp
            pdfEditor.MakeNUp(dataDir + "input.pdf", "UsingPageSizeHorizontalAndVerticalValues_out.pdf", 2, 3);
            // ExEnd:UsingPageSizeHorizontalAndVerticalValues
        }
        public static void Run()
        {
            // ExStart:SplitPagesToEndUsingPaths
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Split pages
            pdfEditor.SplitToEnd(dataDir + "MultiplePages.pdf", 3, dataDir + "SplitPagesToEndUsingPaths_out.pdf");
            // ExEnd:SplitPagesToEndUsingPaths
        }
        public static void Run()
        {
            // ExStart:ConcatenatePdfFilesAndCreateTOC
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Save concatenated output file
            pdfEditor.Concatenate(new FileStream(dataDir + "input1.pdf", FileMode.Open), new FileStream(dataDir + "input2.pdf", FileMode.Open), new FileStream(dataDir + "ConcatenatePdfFilesAndCreateTOC_out.pdf", FileMode.Create));
            // ExEnd:ConcatenatePdfFilesAndCreateTOC                      
        }
        public static void Run()
        {
            // ExStart:MakeBookletUsingPaths
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Make booklet
            pdfEditor.MakeBooklet(dataDir + "input.pdf", dataDir + "MakeBookletUsingPaths_out.pdf");
            // ExEnd:MakeBookletUsingPaths
        }
Exemple #19
0
        private static TimeSpan PDFConcatenateUsingPDFFacades(string[] files)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            PdfFileEditor pfe = new PdfFileEditor();

            pfe.CopyOutlines = false;
            pfe.Concatenate(files, dataDir + "\\Facades\\CopyOutline_out.pdf");
            stopwatch.Stop();
            return(stopwatch.Elapsed);
        }
        public static void Run()
        {
            // ExStart:MakeBookletUsingPageSizeAndPaths
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Make booklet
            pdfEditor.MakeBooklet(dataDir + "input.pdf", dataDir + "MakeBookletUsingPageSizeAndPaths_out_.pdf", PageSize.A5);
            // ExEnd:MakeBookletUsingPageSizeAndPaths
        }
        public static void Run()
        {
            // ExStart:AppendFiles
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Append file
            pdfEditor.Append(dataDir + "input.pdf", dataDir +  "input2.pdf", 1, 1, dataDir + "AppendFiles_out.pdf");
            // ExEnd:AppendFiles
        }
        public static void CopyOutline()
        {
            // ExStart:CopyOutline
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            PdfFileEditor pfe = new PdfFileEditor();

            string[] files = Directory.GetFiles(dataDir);
            pfe.CopyOutlines = false;
            pfe.Concatenate(files, dataDir + "CopyOutline_out_.pdf");
            // ExEnd:CopyOutline
        }
Exemple #23
0
        public static void Run()
        {
            // ExStart:InsertPagesBetweenNumbers
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

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

            // Insert pages
            pdfEditor.Insert(dataDir + "MultiplePages.pdf", 1, dataDir + "InsertPages.pdf", 2, 5, dataDir + "InsertPagesBetweenNumbers_out_.pdf");
            // ExEnd:InsertPagesBetweenNumbers
        }
Exemple #24
0
        public static void Run()
        {
            // ExStart:MakeNUpUsingPaths
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

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

            // Make NUp
            pdfEditor.MakeNUp(dataDir + "input.pdf", dataDir + "input2.pdf", "MakeNUpUsingPaths_out.pdf");
            // ExEnd:MakeNUpUsingPaths
        }
        public static void Run()
        {
            // ExStart:ExtractArrayOfPages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            int[] pagesToExtract = new int[] { 1, 2 };
            // Extract pages
            pdfEditor.Extract(dataDir + "Extract.pdf", pagesToExtract, dataDir + "ExtractArrayOfPages_out.pdf");
            // ExEnd:ExtractArrayOfPages
        }
        public static void CopyOutline()
        {
            // ExStart:CopyOutline
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            PdfFileEditor pfe = new PdfFileEditor();
            string[] files = Directory.GetFiles(dataDir);
            pfe.CopyOutlines = false;
            pfe.Concatenate(files, dataDir + "CopyOutline_out.pdf");
            // ExEnd:CopyOutline
 
        }
Exemple #27
0
        public static void Run()
        {
            // ExStart:ConcatenatePdfFilesAndCreateTOC
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

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

            // Save concatenated output file
            pdfEditor.Concatenate(new FileStream(dataDir + "input1.pdf", FileMode.Open), new FileStream(dataDir + "input2.pdf", FileMode.Open), new FileStream(dataDir + "ConcatenatePdfFilesAndCreateTOC_out_.pdf", FileMode.Create));
            // ExEnd:ConcatenatePdfFilesAndCreateTOC
        }
        public static void Run()
        {
            // ExStart:UsingPageSizeHorizontalAndVerticalValues
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

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

            // Make NUp
            pdfEditor.MakeNUp(dataDir + "input.pdf", "UsingPageSizeHorizontalAndVerticalValues_out.pdf", 2, 3);
            // ExEnd:UsingPageSizeHorizontalAndVerticalValues
        }
        public static void Run()
        {
            // ExStart:SplitPagesUsingPaths
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

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

            // Split pages
            pdfEditor.SplitFromFirst(dataDir + "MultiplePages.pdf", 3, dataDir + "SplitPagesUsingPaths_out.pdf");
            // ExEnd:SplitPagesUsingPaths
        }
        public static void Run()
        {
            // ExStart:InsertArrayOfPages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            int[] pagesToInsert = new int[] { 2, 3 };
            // Insert pages
            pdfEditor.Insert(dataDir + "MultiplePages.pdf", 1, dataDir + "InsertPages.pdf", pagesToInsert, dataDir + "InsertArrayOfPages_out.pdf");
            // ExEnd:InsertArrayOfPages
        }
Exemple #31
0
        public static void Run()
        {
            // ExStart:AppendFiles
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

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

            // Append file
            pdfEditor.Append(dataDir + "input.pdf", dataDir + "input2.pdf", 1, 1, dataDir + "AppendFiles_out.pdf");
            // ExEnd:AppendFiles
        }
        public static void Run()
        {
            // ExStart:ExtractArrayOfPages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

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

            int[] pagesToExtract = new int[] { 1, 2 };
            // Extract pages
            pdfEditor.Extract(dataDir + "Extract.pdf", pagesToExtract, dataDir + "ExtractArrayOfPages_out.pdf");
            // ExEnd:ExtractArrayOfPages
        }
Exemple #33
0
        public static void Run()
        {
            // ExStart:InsertArrayOfPages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

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

            int[] pagesToInsert = new int[] { 2, 3 };
            // Insert pages
            pdfEditor.Insert(dataDir + "MultiplePages.pdf", 1, dataDir + "InsertPages.pdf", pagesToInsert, dataDir + "InsertArrayOfPages_out_.pdf");
            // ExEnd:InsertArrayOfPages
        }
        public static void Run()
        {
            // ExStart:DeletePagesUsingFilePath
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Array of pages to delete
            int[] pagesToDelete = new int[] { 1, 2};
            // Delete pages
            pdfEditor.Delete(dataDir + "input.pdf", pagesToDelete, dataDir + "DeletePagesUsingFilePath_out.pdf");
            // ExEnd:DeletePagesUsingFilePath
        }
        public static void Run()
        {
            // ExStart:ConcatenateMultiplePDFUsingMemoryStream
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create two file streams to read pdf files
            FileStream fs1 = new FileStream(dataDir + "inFile.pdf", FileMode.Open, FileAccess.Read);
            FileStream fs2 = new FileStream(dataDir + "inFile2.pdf", FileMode.Open, FileAccess.Read);

            // Create byte arrays to keep the contents of PDF files
            byte[] buffer1 = new byte[Convert.ToInt32(fs1.Length)];
            byte[] buffer2 = new byte[Convert.ToInt32(fs2.Length)];


            int i = 0;

            // Read PDF file contents into byte arrays
            i = fs1.Read(buffer1, 0, Convert.ToInt32(fs1.Length));
            i = fs2.Read(buffer2, 0, Convert.ToInt32(fs2.Length));

            // Now, first convert byte arrays into MemoryStreams and then concatenate those streams
            using (MemoryStream pdfStream = new MemoryStream())
            {
                using (MemoryStream fileStream1 = new MemoryStream(buffer1))
                {
                    using (MemoryStream fileStream2 = new MemoryStream(buffer2))
                    {
                        // Create instance of PdfFileEditor class to concatenate streams
                        PdfFileEditor pdfEditor = new PdfFileEditor();
                        // Concatenate both input MemoryStreams and save to putput MemoryStream
                        pdfEditor.Concatenate(fileStream1, fileStream2, pdfStream);
                        // Convert MemoryStream back to byte array
                        byte[] data = pdfStream.ToArray();
                        // Create a FileStream to save the output PDF file
                        FileStream output = new FileStream(dataDir + "merged_out_.pdf", FileMode.Create,
                                                           FileAccess.Write);
                        // Write byte array contents in the output file stream
                        output.Write(data, 0, data.Length);
                        // Close output file
                        output.Close();
                    }
                }
            }
            // Close input files
            fs1.Close();
            fs2.Close();
            // ExEnd:ConcatenateMultiplePDFUsingMemoryStream
        }
        public static void Run()
        {
            // ExStart:MakeBookletUsingStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create streams
            FileStream inputStream = new FileStream( dataDir + "input.pdf", FileMode.Open);
            FileStream outputStream = new FileStream(dataDir + "MakeBookletUsingStreams_out.pdf", FileMode.Create);
            // Make booklet
            pdfEditor.MakeBooklet(inputStream, outputStream);
            // ExEnd:MakeBookletUsingStreams
        }
        public static void Run()
        {
            // ExStart:MakeBookletUsingPageSizeLeftRightPagesAndPaths
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Set left and right pages
            int[] leftPages = new int[] { 1, 5};
            int[] rightPages = new int[] { 2, 3 };
            // Make booklet
            pdfEditor.MakeBooklet(dataDir + "MultiplePages.pdf", dataDir + "MakeBookletUsingPageSizeLeftRightPagesAndPaths_out.pdf", PageSize.A5, leftPages, rightPages);
            // ExEnd:MakeBookletUsingPageSizeLeftRightPagesAndPaths
        }
        public static void Run()
        {
            // ExStart:ExtractPagesBetweenTwoNumbersUsingStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create streams
            FileStream inputStream = new FileStream(dataDir + "MultiplePages.pdf", FileMode.Open);
            FileStream outputStream = new FileStream(dataDir + "ExtractPagesBetweenTwoNumbers_out.pdf", FileMode.Create);
            // Extract pages
            pdfEditor.Extract(inputStream, 1, 3, outputStream);
            // ExEnd:ExtractPagesBetweenTwoNumbersUsingStreams
        }
Exemple #39
0
        public static void Run()
        {
            // ExStart:DeletePagesUsingFilePath
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

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

            // Array of pages to delete
            int[] pagesToDelete = new int[] { 1, 2 };
            // Delete pages
            pdfEditor.Delete(dataDir + "input.pdf", pagesToDelete, dataDir + "DeletePagesUsingFilePath_out_.pdf");
            // ExEnd:DeletePagesUsingFilePath
        }
        public static void Run()
        {
            // ExStart:SplitPagesUsingStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create streams
            FileStream inputStream = new FileStream(dataDir + "MultiplePages.pdf", FileMode.Open);
            FileStream outputStream = new FileStream(dataDir + "SplitPagesUsingStreams_out.pdf", FileMode.Create);
            // Split pages
            pdfEditor.SplitFromFirst(inputStream, 3, outputStream);
            // ExEnd:SplitPagesUsingStreams
        }
        public static void Run()
        {
            // ExStart:UsingPageSizeHorizontalVerticalValuesAndStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create streams
            FileStream inputStream = new FileStream(dataDir + "input.pdf", FileMode.Open);
            FileStream outputStream = new FileStream(dataDir + "UsingPageSizeHorizontalVerticalValuesAndStreams_out.pdf", FileMode.Create);
            // Make NUp
            pdfEditor.MakeNUp(inputStream, outputStream, 2, 3);
            // ExEnd:UsingPageSizeHorizontalVerticalValuesAndStreams
        }
    public static void RenderInBrowser()
    {
        // ExStart:RenderInBrowser
        // The path to the documents directory.
        string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();
 
        // Array of files
        string[] filesArray = new string[2];
        filesArray[0] = dataDir + "input.pdf";
        filesArray[1] = dataDir + "input2.pdf";
        // Create PdfFileEditor object
        PdfFileEditor pdfEditor = new PdfFileEditor();
        // Display the resultant concatenated PDF file in 
        pdfEditor.Concatenate(filesArray, dataDir + "RenderInBrowser_out.pdf");
        // ExEnd:RenderInBrowser
    }
        public static void Run()
        {
            // ExStart:ConcatenateArrayOfFilesWithPath
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Array of files
            string[] filesArray = new string[2];
            filesArray[0] =  dataDir + "input.pdf";
            filesArray[1] = dataDir + "input2.pdf";
            // Concatenate files
            pdfEditor.Concatenate(filesArray, dataDir + "ConcatenateArrayOfFilesWithPath_out.pdf");
            // ExEnd:ConcatenateArrayOfFilesWithPath
        }
Exemple #44
0
        public static void Run()
        {
            // ExStart:ExtractPagesBetweenTwoNumbersUsingStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create streams
            FileStream inputStream  = new FileStream(dataDir + "MultiplePages.pdf", FileMode.Open);
            FileStream outputStream = new FileStream(dataDir + "ExtractPagesBetweenTwoNumbers_out.pdf", FileMode.Create);

            // Extract pages
            pdfEditor.Extract(inputStream, 1, 3, outputStream);
            // ExEnd:ExtractPagesBetweenTwoNumbersUsingStreams
        }
        public static void Run()
        {
            // ExStart:UsingPageSizeHorizontalVerticalValuesAndStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create streams
            FileStream inputStream  = new FileStream(dataDir + "input.pdf", FileMode.Open);
            FileStream outputStream = new FileStream(dataDir + "UsingPageSizeHorizontalVerticalValuesAndStreams_out.pdf", FileMode.Create);

            // Make NUp
            pdfEditor.MakeNUp(inputStream, outputStream, 2, 3);
            // ExEnd:UsingPageSizeHorizontalVerticalValuesAndStreams
        }
        public static void Run()
        {
            // ExStart:AppendArrayOfFiles
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Array of files
            string[] portFiles = new string[2];
            portFiles[0] = dataDir + "input.pdf";
            portFiles[1] = dataDir + "input2.pdf";
            // Append file
            pdfEditor.Append(dataDir + "input3.pdf", portFiles, 1, 1, dataDir + "AppendArrayOfFiles_out.pdf");
            // ExEnd:AppendArrayOfFiles
        }
 /// <summary>
 /// Takes an array of <see cref="Stream"/>s and returns a <see cref="byte"/>[] array.
 /// </summary>
 /// <param name="streamList">streamList</param>
 /// <returns>merged pdfs</returns>
 private static byte[] ReturnStreamListAsByteArray(Stream[] streamList)
 {
     using (var memoryStream = new MemoryStream())
     {
         var pfe = new PdfFileEditor();
         pfe.Concatenate(streamList, memoryStream);
         // Now manually dispose memory streams (we're done using them).
         // We need to do this otherwise the list of streams will be
         // unreadable which will cause an exception.
         foreach (var doc in streamList)
         {
             doc.Dispose();
         }
         return memoryStream.ToArray();
     }
 }
Exemple #48
0
        public static void Run()
        {
            // ExStart:MakeBookletUsingPageSizeLeftRightPagesAndPaths
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

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

            // Set left and right pages
            int[] leftPages  = new int[] { 1, 5 };
            int[] rightPages = new int[] { 2, 3 };
            // Make booklet
            pdfEditor.MakeBooklet(dataDir + "MultiplePages.pdf", dataDir + "MakeBookletUsingPageSizeLeftRightPagesAndPaths_out.pdf", PageSize.A5, leftPages, rightPages);
            // ExEnd:MakeBookletUsingPageSizeLeftRightPagesAndPaths
        }
Exemple #49
0
 /// <summary>
 /// Takes an array of <see cref="Stream"/>s and returns a <see cref="byte"/>[] array.
 /// </summary>
 /// <param name="streamList">streamList</param>
 /// <returns>merged pdfs</returns>
 private static byte[] ReturnStreamListAsByteArray(Stream[] streamList)
 {
     using (var memoryStream = new MemoryStream())
     {
         var pfe = new PdfFileEditor();
         pfe.Concatenate(streamList, memoryStream);
         // Now manually dispose memory streams (we're done using them).
         // We need to do this otherwise the list of streams will be
         // unreadable which will cause an exception.
         foreach (var doc in streamList)
         {
             doc.Dispose();
         }
         return(memoryStream.ToArray());
     }
 }
        public static void Run()
        {
            // ExStart:AppendFilesUsingStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create streams
            FileStream inputStream = new FileStream( dataDir + "input.pdf", FileMode.Open);
            FileStream portStream = new FileStream(dataDir + "input2.pdf", FileMode.Open);
            FileStream outputStream = new FileStream(dataDir + "AppendFilesUsingStreams_out.pdf", FileMode.Create);
            // Append file
            pdfEditor.Append(inputStream, portStream, 1, 1, outputStream);	
            // ExEnd:AppendFilesUsingStreams
        }
Exemple #51
0
        public static void Run()
        {
            // ExStart:SplitPagesUsingStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create streams
            FileStream inputStream  = new FileStream(dataDir + "MultiplePages.pdf", FileMode.Open);
            FileStream outputStream = new FileStream(dataDir + "SplitPagesUsingStreams_out_.pdf", FileMode.Create);

            // Split pages
            pdfEditor.SplitFromFirst(inputStream, 3, outputStream);
            // ExEnd:SplitPagesUsingStreams
        }
Exemple #52
0
        public static void Run()
        {
            // ExStart:MakeBookletUsingStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create streams
            FileStream inputStream  = new FileStream(dataDir + "input.pdf", FileMode.Open);
            FileStream outputStream = new FileStream(dataDir + "MakeBookletUsingStreams_out.pdf", FileMode.Create);

            // Make booklet
            pdfEditor.MakeBooklet(inputStream, outputStream);
            // ExEnd:MakeBookletUsingStreams
        }
        public static void Run()
        {
            // ExStart:UsingArrayOfFilesAndPaths
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create array of files
            string[] filesArray = new string[2];
            filesArray[0] =  dataDir + "input.pdf";
            filesArray[1] = dataDir + "input2.pdf";
            // Make NUp
            pdfEditor.MakeNUp(filesArray, dataDir + "UsingArrayOfFilesAndPaths_out.pdf", true);
            // ExEnd:UsingArrayOfFilesAndPaths
        }
        public static void Run()
        {
            // ExStart:UsingArrayOfFilesAndStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create streams
            FileStream[] fileStreams = new FileStream[2];
            fileStreams[0] = new FileStream(dataDir + "input.pdf", FileMode.Open);
            fileStreams[1] = new FileStream(dataDir + "input2.pdf", FileMode.Open);
            FileStream outputStream = new FileStream(dataDir + "UsingArrayOfFilesAndStreams_out.pdf", FileMode.Create);
            // Make NUp
            pdfEditor.MakeNUp(fileStreams, outputStream, true);
            // ExEnd:UsingArrayOfFilesAndStreams
        }
        public static void Run()
        {
            // ExStart:ConcatenateBlankPdfUsingStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create streams
            FileStream inputStream1 = new FileStream( dataDir + "input.pdf", FileMode.Open);
            FileStream inputStream2 = new FileStream( dataDir + "input2.pdf", FileMode.Open);
            FileStream blankStream = new FileStream(dataDir + "blank.pdf", FileMode.Open);
            FileStream outputStream = new FileStream(dataDir + "ConcatenateBlankPdfUsingStreams_out.pdf", FileMode.Create);
            // Concatenate file
            pdfEditor.Concatenate(inputStream1, inputStream2, blankStream, outputStream);
            // ExEnd:ConcatenateBlankPdfUsingStreams
        }
        public static void Run()
        {
            // ExStart:InsertPagesUsingStreams
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();
            // Create streams
            FileStream inputStream = new FileStream( dataDir + "MultiplePages.pdf", FileMode.Open);
            FileStream portStream = new FileStream(dataDir + "InsertPages.pdf", FileMode.Open);
            FileStream outputStream = new FileStream(dataDir + "InsertPagesUsingStreams_out.pdf", FileMode.Create);
            int[] pagesToInsert = new int[] { 2, 3 };
            // Insert pages
            pdfEditor.Insert(inputStream, 1, portStream, pagesToInsert, outputStream);
            // ExEnd:InsertPagesUsingStreams
        }
Exemple #57
0
        public static void Run()
        {
            // ExStart:AppendArrayOfFiles
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

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

            // Array of files
            string[] portFiles = new string[2];
            portFiles[0] = dataDir + "input.pdf";
            portFiles[1] = dataDir + "input2.pdf";
            // Append file
            pdfEditor.Append(dataDir + "input3.pdf", portFiles, 1, 1, dataDir + "AppendArrayOfFiles_out.pdf");
            // ExEnd:AppendArrayOfFiles
        }
        public static void Run()
        {
            // ExStart:ConcatenateArrayOfFilesWithPath
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

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

            // Array of files
            string[] filesArray = new string[2];
            filesArray[0] = dataDir + "input.pdf";
            filesArray[1] = dataDir + "input2.pdf";
            // Concatenate files
            pdfEditor.Concatenate(filesArray, dataDir + "ConcatenateArrayOfFilesWithPath_out_.pdf");
            // ExEnd:ConcatenateArrayOfFilesWithPath
        }
Exemple #59
0
        public static void Run()
        {
            // ExStart:UsingArrayOfFilesAndPaths
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

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

            // Create array of files
            string[] filesArray = new string[2];
            filesArray[0] = dataDir + "input.pdf";
            filesArray[1] = dataDir + "input2.pdf";
            // Make NUp
            pdfEditor.MakeNUp(filesArray, dataDir + "UsingArrayOfFilesAndPaths_out_.pdf", true);
            // ExEnd:UsingArrayOfFilesAndPaths
        }
        public static void RenderInBrowser()
        {
            // ExStart:RenderInBrowser
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();

            // Array of files
            string[] filesArray = new string[2];
            filesArray[0] = dataDir + "input.pdf";
            filesArray[1] = dataDir + "input2.pdf";
            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();

            // Display the resultant concatenated PDF file in
            pdfEditor.Concatenate(filesArray, dataDir + "RenderInBrowser_out_.pdf");
            // ExEnd:RenderInBrowser
        }