public static void Merger()
        {
            MergeDocument document = new MergeDocument(Util.GetPath("Resources/PDFs/DocumentA.pdf"));

            Aes256Security security = new Aes256Security("OwnerPassword", "UserPassword");

            document.Security = security;

            document.Draw("PasswordProtectPDFMerger.pdf");
            document.Draw(Util.GetPath("Output/PasswordProtectExistingPDF.pdf"));
        }
Exemple #2
0
        private static string BarcodeJobTicketPdf(string FullFileName, string JobName, string StockCode)
        {
            string pdfFullName = FullFileName.Replace(" .pdf", ".pdf");

            ceTe.DynamicPDF.Document.AddLicense("DPS70NEDJGMGEGWKOnLLQb4SjhbTTJhXnkpf9bj8ZzxFH+FFxctoPX+HThGxkpidUCHJ5b88fg4oUJSHiRBggzHdghUgkkuIvoag");
            var doc  = new ceTe.DynamicPDF.Document();
            var page = new ceTe.DynamicPDF.Page();

            MergeDocument MyDocJobTicket = new MergeDocument();
            PdfDocument   pdfTemplate    = new PdfDocument(FullFileName);
            var           qrCode         = new ceTe.DynamicPDF.PageElements.Image(Encode.QR(JobName), 300, 50);

            qrCode.Height = 90;
            qrCode.Width  = 90;

            MyDocJobTicket.Append(pdfTemplate);
            MyDocJobTicket.Pages[0].Dimensions.SetMargins(0);

            MyDocJobTicket.Pages[0].Elements.Add(qrCode);
            qrCode        = new ceTe.DynamicPDF.PageElements.Image(Encode.QR(StockCode), 50, 405);
            qrCode.Height = 38;
            qrCode.Width  = 38;
            MyDocJobTicket.Pages[0].Elements.Add(qrCode);
            MyDocJobTicket.FormFlattening = FormFlatteningOptions.Default;
            MyDocJobTicket.Draw(pdfFullName);
            MyDocJobTicket = null;
            FileInfo fi = new FileInfo(FullFileName);

            fi.Delete();
            return(pdfFullName);
        }
Exemple #3
0
        public static void Run(string outputPdfPath)
        {
            // Create an output document and set it's properties
            MergeDocument document = new MergeDocument(Util.GetResourcePath("PDFs/fw9_18.pdf"));

            document.Creator = "StampPDF";
            document.Author  = "ceTe Software";
            document.Title   = "Stamp PDF";

            // Create a template to place an image behind each page in the PDF
            Template backgroundTemplate = new Template();

            document.Template = backgroundTemplate;
            backgroundTemplate.Elements.Add(new BackgroundImage(Util.GetResourcePath("Images/DPDFLogo_Watermark.png")));

            // Create a label for the stamp and rotate it 20 degrees
            Label label = new Label("Stamped with Merger for .NET.", 0, 250, 500, 100, Font.Helvetica, 24, TextAlign.Center, RgbColor.Red);

            label.Angle = -20;

            // Create an anchor group to keep the label anchored regardless of page size
            AnchorGroup anchorGroup = new AnchorGroup(500, 100, Align.Center, VAlign.Top);

            anchorGroup.Add(label);

            // Create a stamp template and add the anchor group containing the label to it
            Template stampTemplate = new Template();

            document.StampTemplate = stampTemplate;
            stampTemplate.Elements.Add(anchorGroup);

            // Outputs the stamped document to the current web page
            document.Draw(outputPdfPath);
        }
Exemple #4
0
        public void Merge(string sourceDirectory)
        {
            var coverPages = Directory.EnumerateFiles(sourceDirectory, coverPageIdentifier);

            foreach (string coverPage in coverPages)
            {
                string fileName   = coverPage.Substring(sourceDirectory.Length + 1);
                string filePrefix = fileName.Substring(0, fileName.IndexOf("_") + 1);

                var bodyPage = Directory.EnumerateFiles(sourceDirectory, filePrefix + bodyPageIdentifier).First();

                string      path      = sourceDirectory + @"\" + fileName;
                PdfDocument pdf       = new PdfDocument(path);
                var         pageCount = pdf.Pages.Count;

                for (int i = 1; i <= pageCount; i++)
                {
                    MergeDocument document = new MergeDocument(path, i, 1);
                    document.Append(bodyPage);

                    string planID = filePrefix + (i.ToString().PadLeft(5, '0')) + ".pdf";

                    string archivePath = sourceDirectory + @"\" + planID;
                    document.Draw(archivePath);
                }
            }
        }
        protected Arquivo inserirArquivosNaLista(string id, string opcao)
        {
            List <Arquivo> list_temp = new List <Arquivo>();

            list_temp = (List <Arquivo>)Session[opcao];
            Arquivo arq_temp = new Arquivo();

            if (list_temp != null)
            {
                string nomeArquivo = montarFormatoGD(id, opcao + ext);
                int    count       = list_temp.Count;
                if (count >= 2)
                {
                    MergeDocument document = MergeDocument.Merge(diretorio + list_temp.ElementAt(0).nome_Arquivo, diretorio + list_temp.ElementAt(1).nome_Arquivo);
                    if (count > 2)
                    {
                        for (int i = 2; i < count; i++)
                        {
                            document.Append(diretorio + list_temp.ElementAt(i).nome_Arquivo);
                        }
                    }
                    document.Draw(nomeArquivo);
                    System.IO.File.Delete(diretorio + nomeArquivo);
                    System.IO.File.Move(nomeArquivo, diretorio + nomeArquivo);
                }
                arq_temp.nome_Arquivo = nomeArquivo;
                arq_temp.tipo_Arquivo = opcao;
            }
            return(arq_temp);
        }
        public static void Run(string outputPdfPath)
        {
            MergeDocument document = new MergeDocument(Util.GetResourcePath("PDFs/fw9AcroForm_18_filled.pdf"));

            document.Form.Output = FormOutput.Flatten;

            document.Draw(outputPdfPath);
        }
        // A simple Merge of two PDF files.
        // Use the ceTe.DynamicPDF.Merger namespace for the MergeDocument class.
        static void Merge2Pdfs()
        {
            //Create MergeDocument object with source PDFs to Merge
            MergeDocument document = MergeDocument.Merge(GetResourcePath("doc-a.pdf"), GetResourcePath("doc-b.pdf"));

            //Save the merged PDF
            document.Draw("output-simple-merge.pdf");
        }
Exemple #8
0
        public static void CombinePDF()
        {
            MergeDocument document = new MergeDocument(Util.GetPath("Resources/PDFs/DocumentA.pdf"));

            document.Append(Util.GetPath("Resources/PDFs/DocumentB.pdf"));
            document.Append(Util.GetPath("Resources/PDFs/DocumentC.pdf"), 1, 2);
            document.Draw(Util.GetPath("Output/CombinePDFs.pdf"));
        }
Exemple #9
0
        public static void CombinePDFWithOptions()
        {
            MergeOptions options = MergeOptions.All;

            options.DocumentProperties = false;
            MergeDocument document = new MergeDocument(Util.GetPath("Resources/PDFs/DocumentA.pdf"), options);

            document.Append(Util.GetPath("Resources/PDFs/DocumentB.pdf"));
            document.Draw(Util.GetPath("Output/CombinePDFWithOptions.pdf"));
        }
        public static void MergeOption()
        {
            MergeDocument document = new MergeDocument(Util.GetPath("Resources/PDFs/DocumentA.pdf"));
            MergeOptions  options  = MergeOptions.Append;

            options.Outlines = false;
            document.Append(Util.GetPath("Resources/PDFs/DocumentB.pdf"), options);
            document.Append(Util.GetPath("Resources/PDFs/DocumentC.pdf"));
            document.Draw(Util.GetPath("Output/MergeOption.pdf"));
        }
        // Combines PDF documents.
        // This code uses the DynamicPDF Merger for .NET product.
        // Use the ceTe.DynamicPDF.Merger namespace for the MergeDocument class.
        private static void CombinePDFs()
        {
            //Create MergeDocument object and append PDFs
            MergeDocument document = new MergeDocument(GetResourcePath("doc-a.pdf"));

            document.Append(GetResourcePath("doc-b.pdf"));
            document.Append(GetResourcePath("doc-c.pdf"), 1, 2);

            //Save merged document
            document.Draw("output-combined.pdf");
        }
        // A simple merge and then appending another PDF.
        // Use the ceTe.DynamicPDF.Merger namespace for the MergeDocument class.
        static void MergeAndAppendPdfs()
        {
            //Create MergeDocument object with source PDFs to Merge
            MergeDocument document = MergeDocument.Merge(GetResourcePath("doc-a.pdf"), GetResourcePath("doc-b.pdf"));

            //Append a PDF document
            document.Append(GetResourcePath("doc-c.pdf"), 1, 2);

            //Save the merged PDF
            document.Draw("output-with-append.pdf");
        }
Exemple #13
0
        public static void Run()
        {
            PdfDocument pdf = new PdfDocument(Util.GetPath("Resources/PDFs/TimeMachine.pdf"));

            MergeDocument part1 = new MergeDocument(pdf, 1, 4);

            part1.Draw(Util.GetPath("Output/TimeMachinePart1.pdf"));

            MergeDocument part2 = new MergeDocument(pdf, 5, 8);

            part2.Draw(Util.GetPath("Output/TimeMachinePart2.pdf"));
        }
Exemple #14
0
        public static void Merger()
        {
            MergeDocument document = new MergeDocument(Util.GetPath("Resources/PDFs/DocumentA.pdf"));

            Aes256Security security = new Aes256Security("OwnerPassword", "UserPassword");

            security.AllowCopy  = false;
            security.AllowPrint = false;
            document.Security   = security;

            document.Draw(Util.GetPath("Output/EncryptExistingPDF.pdf"));
        }
        public static void Merger()
        {
            MergeDocument document = new MergeDocument(Util.GetPath("Resources/PDFs/DocumentA.pdf"));

            Template           template   = new Template();
            PageNumberingLabel pageLabels = new PageNumberingLabel("%%CP%% of %%TP%%", 0, 0, 200, 20);

            template.Elements.Add(pageLabels);
            document.Template = template;

            document.Draw(Util.GetPath("Output/AddPageNumberToExistingPDF.pdf"));
        }
Exemple #16
0
        public static void Run(string outputPdfPath)
        {
            MergeDocument document = new MergeDocument(Util.GetResourcePath("PDFs/fw9AcroForm_18_filled.pdf"));

            document.Form.Fields["topmostSubform[0].Page1[0].f1_1[0]"].Output            = FormFieldOutput.Remove;
            document.Form.Fields["topmostSubform[0].Page1[0].Address[0].f1_8[0]"].Output = FormFieldOutput.Remove;

            document.Form.Fields["topmostSubform[0].Page1[0].f1_2[0]"].Output            = FormFieldOutput.Flatten;
            document.Form.Fields["topmostSubform[0].Page1[0].Address[0].f1_7[0]"].Output = FormFieldOutput.Flatten;

            document.Draw(outputPdfPath);
        }
Exemple #17
0
        /// <summary>
        /// Método usado para deletar uma página especifica do documento.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        protected void ImageButtonDeletePagina_Click(object sender, ImageClickEventArgs e)
        {
            string nomeArquivo = LabelArquivo.Text;

            LabelErro.Text         = "";
            ImageAttention.Visible = false;
            //verificar se o nome nao esta nulo
            if (nomeArquivo.Equals(""))
            {
                ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "window.alert('Não existe arquivo');", true);
            }
            else
            {
                int         page        = Convert.ToInt16(TextBoxDeletePagina.Text);
                PdfDocument originalPDF = new PdfDocument(pathDir + nomeArquivo);  //specify original file
                int         totalpages  = originalPDF.Pages.Count;

                if ((page > totalpages) || (page <= 0))
                {
                    ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "window.alert('Página fora do limite!');", true);
                }
                else if (totalpages == 1)
                {
                    System.IO.File.Delete(pathDir + nomeArquivo);
                    TableArquivo.Visible = false;
                    string abaAtiva = retornaAbaAtiva();
                    Session.Add("postou_" + abaAtiva, "nao");
                    ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "window.alert('Página deletada com sucesso!');", true);
                }
                else if (totalpages != 1)
                {
                    if (page == totalpages)
                    {
                        MergeDocument smallerPDF = new MergeDocument(originalPDF, 1, page - 1);
                        smallerPDF.Draw(nomeArquivo);
                        System.IO.File.Delete(pathDir + nomeArquivo);
                        System.IO.File.Move(nomeArquivo, pathDir + nomeArquivo);
                    }
                    else
                    {
                        MergeDocument smallerPDF  = new MergeDocument(originalPDF, 1, page - 1);
                        int           pagesAppend = totalpages - page;
                        smallerPDF.Append(originalPDF, page + 1, pagesAppend);  //append pages deleted plus one until page count;
                        smallerPDF.Draw(nomeArquivo);
                        System.IO.File.Delete(pathDir + nomeArquivo);
                        System.IO.File.Move(nomeArquivo, pathDir + nomeArquivo);
                    }
                    ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "window.alert('Página deletada com sucesso!');", true);
                }
            }
        }
Exemple #18
0
        public static void Run()
        {
            MergeDocument document = new MergeDocument(Util.GetPath("Resources/PDFs/fw9AcroForm_18.pdf"));

            document.Form.Fields["topmostSubform[0].Page1[0].f1_1[0]"].Value = "Any Company, Inc.";
            document.Form.Fields["topmostSubform[0].Page1[0].f1_2[0]"].Value = "Any Company";
            document.Form.Fields["topmostSubform[0].Page1[0].FederalClassification[0].c1_1[0]"].Value = "1";
            document.Form.Fields["topmostSubform[0].Page1[0].Address[0].f1_7[0]"].Value = "123 Main Street";
            document.Form.Fields["topmostSubform[0].Page1[0].Address[0].f1_8[0]"].Value = "Washington, DC  22222";
            document.Form.Fields["topmostSubform[0].Page1[0].f1_9[0]"].Value            = "Any Requester";
            document.Form.Fields["topmostSubform[0].Page1[0].f1_10[0]"].Value           = "17288825617";

            document.Draw(Util.GetPath("Output/AcroFormFilling.pdf"));
        }
Exemple #19
0
        // Add password protection for an existing PDF.
        // This code uses DynamicPDF Merger for .NET product.
        // Use the ceTe.DynamicPDF.Merger namespace for the MergeDocument class.
        private static void AddPasswordToExistingPDF()
        {
            //Create PdfDocument object with the existing PDF file and create MergeDocument using PdfDocument
            PdfDocument   pdf      = new PdfDocument(GetResourcePath("doc-a.pdf"));
            MergeDocument document = new MergeDocument(pdf);

            //Create Security object with passwords and set it to the Document
            Aes256Security security = new Aes256Security("owner", "user");

            document.Security = security;

            //Save the Document
            document.Draw("output-existing-pdf.pdf");
        }
        public static void Run(string outputPdfPath)
        {
            // Create a merge document and set it's properties
            MergeDocument document = MergeDocument.Merge(Util.GetResourcePath("PDFs/DocumentA.pdf"), Util.GetResourcePath("PDFs/DocumentB.pdf"));

            // Append additional PDF
            document.Append(Util.GetResourcePath("PDFs/DocumentC.pdf"));

            // Append 3 pages from an aditional PDF
            document.Append(Util.GetResourcePath("PDFs/DocumentD.pdf"), 1, 3);

            // Outputs the merged document to the current web page
            document.Draw(outputPdfPath);
        }
Exemple #21
0
        // Splits a PDF document into two.
        // This code uses the DynamicPDF Merger for .NET product.
        // Use the ceTe.DynamicPDF.Merger namespace for the PdfDocument and MergeDocument classes.
        static void Main(string[] args)
        {
            //Create a PdfDocument using the source PDF
            PdfDocument pdf = new PdfDocument(GetResourcePath("doc-a.pdf"));

            // Create MergeDocument and append the pages needed from main document to split
            MergeDocument part1 = new MergeDocument(pdf, 1, 2);

            part1.Draw("output-part1.pdf");

            // Create MergeDocument and append the pages needed from main document to split
            MergeDocument part2 = new MergeDocument(pdf, 3, 2);

            part2.Draw("output-part2.pdf");
        }
        // Combines PDF documents with options.
        // This code uses the DynamicPDF Merger for .NET product.
        // Use the ceTe.DynamicPDF.Merger namespace for the MergeDocument class.
        private static void CombinePDFsWithOptions()
        {
            //Create MergeOptions with different settings
            MergeOptions options = MergeOptions.Append;

            options.Outlines = false;

            //Create MergeDocument object
            MergeDocument document = new MergeDocument();

            // Append a document with options
            document.Append(GetResourcePath("doc-with-outline.pdf"), options);

            //Save document
            document.Draw("output-with-options.pdf");
        }
Exemple #23
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            // Create a merge document and set it's properties
            MergeDocument document = MergeDocument.Merge(FileUpload1.PostedFile.FileName, FileUpload2.PostedFile.FileName);

            string nomeArquivo1 = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf('\\') + 1);

            // Outputs the merged document to the current web page
            //document.DrawToWeb(FileUpload1.PostedFile.FileName);
            document.Draw(nomeArquivo1);

            // Opens the PDF (Requires a PDF Viewer)
            //System.Diagnostics.Process.Start(nomeArquivo1);

            // Put the file on a specific Path
            System.IO.File.Move(nomeArquivo1, "c://Temp//" + nomeArquivo1);
        }
Exemple #24
0
        // Encrypts an existing PDF document
        // This code uses the DynamicPDF Merger for .NET product.
        // Use the ceTe.DynamicPDF.Merger namespace for the MergeDocument class.
        private static void EncryptExistingPDF()
        {
            //Create a MergeDocument object with the existing PDF
            MergeDocument document = new MergeDocument(GetResourcePath("doc-a.pdf"));

            //Create Security object with passwords and other settings
            Aes256Security security = new Aes256Security("owner", "user");

            security.AllowAccessibility = true;
            security.AllowFormFilling   = false;

            //Set security to the Document
            document.Security = security;

            //Save document
            document.Draw("output-existing-pdf.pdf");
        }
        // A simple merge and appending two other PDFs with options.
        // Use the ceTe.DynamicPDF.Merger namespace for the MergeDocument and MergeOptions classes.
        static void MergeWithOptions()
        {
            //Create MergeDocument with MergeOptions
            var document = new MergeDocument(GetResourcePath("doc-a.pdf"), MergeOptions.All);

            var optionsNoOutlines = MergeOptions.Append;

            optionsNoOutlines.Outlines = false;
            document.Append(GetResourcePath("doc-with-outline.pdf"), optionsNoOutlines);

            var optionsNoAnnotations = MergeOptions.Append;

            optionsNoAnnotations.PageAnnotations = false;
            document.Append(GetResourcePath("doc-with-note.pdf"), optionsNoAnnotations);

            document.Draw("output-with-options.pdf");
        }
Exemple #26
0
        // This examples uses the DynamicPDF Merger for .NET Product
        // Use the ceTe.DynamicPDF namespace for the Template class
        // Use the ceTe.DynamicPDF.PageElements namespace for the PageNumberingLabel element.
        // Use the ceTe.DynamicPDF.Merger namespace for the MergeDocument class.
        private static void AddPageNumbersToExistingPDF()
        {
            //Create a MergeDocument object using the existing PDF
            MergeDocument document = new MergeDocument(GetResourcePath("doc-a.pdf"));

            //Create a template bject
            Template template = new Template();

            //Create a PageNumberingLabel and add it to the template
            PageNumberingLabel pageLabels = new PageNumberingLabel("%%CP%% of %%TP%%", 0, 0, 200, 20);

            template.Elements.Add(pageLabels);

            //Set template to the document
            document.Template = template;

            //Save document.
            document.Draw("output-existing-pdf.pdf");
        }
Exemple #27
0
        protected void ImageButtonDeletePagina_Click(object sender, ImageClickEventArgs e)
        {
            string nomeArquivo = LabelArquivo.Text;

            LabelErro.Text         = "";
            ImageAttention.Visible = false;
            //verificar se o nome nao esta nulo
            if (nomeArquivo.Equals(""))
            {
                LabelErro.Text         = "Não existe arquivo";
                ImageAttention.Visible = true;
            }
            else
            {
                int         page        = Convert.ToInt16(TextBoxDeletePagina.Text);
                PdfDocument originalPDF = new PdfDocument(pathDir + nomeArquivo);  //specify original file
                int         totalpages  = originalPDF.Pages.Count;

                if ((page > totalpages) || (page <= 0))
                {
                    LabelErro.Text         = "Página fora do limite";
                    ImageAttention.Visible = true;
                }
                else if (page == totalpages)
                {
                    MergeDocument smallerPDF = new MergeDocument(originalPDF, 1, page - 1);
                    smallerPDF.Draw(nomeArquivo);
                    System.IO.File.Delete(pathDir + nomeArquivo);
                    System.IO.File.Move(nomeArquivo, pathDir + nomeArquivo);
                }
                else
                {
                    MergeDocument smallerPDF  = new MergeDocument(originalPDF, 1, page - 1);
                    int           pagesAppend = totalpages - page;
                    smallerPDF.Append(originalPDF, page + 1, pagesAppend);  //append pages deleted plus one until page count;
                    smallerPDF.Draw(nomeArquivo);
                    System.IO.File.Delete(pathDir + nomeArquivo);
                    System.IO.File.Move(nomeArquivo, pathDir + nomeArquivo);
                }
            }
        }
        public static void Run(string outputPdfPath)
        {
            // Create a document and set it's properties
            MergeDocument document = new MergeDocument(Util.GetResourcePath("PDFs/fw9AcroForm_18.pdf"));

            document.Creator = "AcroFormFill.aspx";
            document.Author  = "ceTe Software";
            document.Title   = "W-9 AcroForm Filler";

            // Add content to the page
            document.Form.Fields["topmostSubform[0].Page1[0].f1_1[0]"].Value = "Any Company, Inc.";
            document.Form.Fields["topmostSubform[0].Page1[0].f1_2[0]"].Value = "Any Company";
            document.Form.Fields["topmostSubform[0].Page1[0].FederalClassification[0].c1_1[0]"].Value = "1";
            document.Form.Fields["topmostSubform[0].Page1[0].Address[0].f1_7[0]"].Value = "123 Main Street";
            document.Form.Fields["topmostSubform[0].Page1[0].Address[0].f1_8[0]"].Value = "Washington, DC  22222";
            document.Form.Fields["topmostSubform[0].Page1[0].f1_9[0]"].Value            = "Any Requester";
            document.Form.Fields["topmostSubform[0].Page1[0].f1_10[0]"].Value           = "17288825617";



            string ssn = "265748".Replace("-", "").Replace(" ", "");
            string ein = "521234567".Trim().Replace("-", "").Replace(" ", "");

            if (ssn.Length >= 9)
            {
                document.Form.Fields["topmostSubform[0].Page1[0].SSN[0].f1_11[0]"].Value = ssn.Substring(0, 1) + ssn.Substring(1, 1) + ssn.Substring(2, 1);
                document.Form.Fields["topmostSubform[0].Page1[0].SSN[0].f1_12[0]"].Value = ssn.Substring(3, 1) + ssn.Substring(4, 1);
                document.Form.Fields["topmostSubform[0].Page1[0].SSN[0].f1_13[0]"].Value = ssn.Substring(5, 1) + ssn.Substring(6, 1) + ssn.Substring(7, 1) + ssn.Substring(8, 1);
            }
            else if (ein.Length >= 9)
            {
                document.Form.Fields["topmostSubform[0].Page1[0].EmployerID[0].f1_14[0]"].Value = ein.Substring(0, 1) + ein.Substring(1, 1);
                document.Form.Fields["topmostSubform[0].Page1[0].EmployerID[0].f1_15[0]"].Value = ein.Substring(2, 1) + ein.Substring(3, 1) + ein.Substring(4, 1) + ein.Substring(5, 1) + ein.Substring(6, 1) + ein.Substring(7, 1) + ein.Substring(8, 1);
            }
            // Uncomment to make form read only
            //document.Form.IsReadOnly = true;

            // Outputs the W-9 to the current web page
            document.Draw(outputPdfPath);
        }
        protected Arquivo inserirArquivosNaLista(string id, string opcao)
        {
            List <Arquivo> list_temp = new List <Arquivo>();

            list_temp = (List <Arquivo>)Session[opcao];
            Arquivo arq_temp = new Arquivo();

            if (list_temp != null)
            {
                string nomeArquivo = list_temp.ElementAt(0).nome_Arquivo;
                int    count       = list_temp.Count;

                if (count >= 2)
                {
                    MergeDocument document = MergeDocument.Merge(diretorio + list_temp.ElementAt(0).nome_Arquivo, diretorio + list_temp.ElementAt(1).nome_Arquivo);
                    if (count > 2)
                    {
                        for (int i = 2; i < count; i++)
                        {
                            document.Append(diretorio + list_temp.ElementAt(i).nome_Arquivo);
                        }
                    }
                    document.Draw(nomeArquivo);

                    //Deletando os arquivos temporarios usados no merge
                    for (int i = 0; i < count; i++)
                    {
                        if (!nomeArquivo.Equals((String)list_temp.ElementAt(i).nome_Arquivo))
                        {
                            System.IO.File.Delete(diretorio + list_temp.ElementAt(i).nome_Arquivo);
                        }
                    }
                    System.IO.File.Move(nomeArquivo, diretorio + nomeArquivo);
                }
                arq_temp.nome_Arquivo = nomeArquivo;
                arq_temp.tipo_Arquivo = opcao;
            }
            return(arq_temp);
        }
Exemple #30
0
        protected void ImageButtonSalvar_Click(object sender, ImageClickEventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                //lembrar de adicionar o ID do cadastro ao nome na hora de adicionar ao banco
                String nameFile = "";
                if (Session["abaAtiva"].ToString().Equals((string)"TabPanelPessoais"))
                {
                    nameFile = "docsPessoais";
                }
                else if (Session["abaAtiva"].ToString().Equals((string)"TabPanelTitulacao"))
                {
                    nameFile = "titulacoes";
                }
                else if (Session["abaAtiva"].ToString().Equals((string)"TabPanelPortaria"))
                {
                    nameFile = "portarias";
                }
                else if (Session["abaAtiva"].ToString().Equals((string)"TabPanelCI"))
                {
                    nameFile = "cis";
                }
                else if (Session["abaAtiva"].ToString().Equals((string)"TabPanelAviso"))
                {
                    nameFile = "avisoFerias";
                }
                else if (Session["abaAtiva"].ToString().Equals((string)"TabPanelRequerimento"))
                {
                    nameFile = "requerimentos";
                }
                else if (Session["abaAtiva"].ToString().Equals((string)"TabPanelOutros"))
                {
                    nameFile = "outros";
                }

                if (Session["postou_" + nameFile].ToString().Equals((string)"sim"))
                {
                    string nomeArquivo = nameFile + ext;
                    // Create a merge document and set it's properties
                    MergeDocument document = MergeDocument.Merge(pathDir + nomeArquivo, FileUpload1.PostedFile.FileName);
                    //string nomeArquivo1 = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf('\\') + 1);
                    // Outputs the merged document
                    document.Draw(nomeArquivo);
                    System.IO.File.Delete(pathDir + nomeArquivo);
                    System.IO.File.Move(nomeArquivo, pathDir + nomeArquivo);
                }
                //se ainda nao postou o documento nao precisa fazer um merge
                else
                {
                    try
                    {
                        FileUpload1.SaveAs(pathDir + nameFile + ext);
                        //FileUpload1.SaveAs("C:\\Temp\\" + nameFile + ext);
                        Session.Add("fileName", nameFile + ext);
                    }
                    catch (Exception ex)
                    {
                        LabelErro.Text = ex.Message;
                    }
                }
                LabelArquivo.Text        = nameFile + ext;
                LinkButtonVer.Visible    = true;
                LinkButtonDelete.Visible = true;
                //levantar flag dizendo que o arquivo foi postado
                Session.Add("postou_" + nameFile, "sim");
            }
            else
            {
                //Mostra o Erro quando não tem arquivo selecionado
                LabelErro.Text = "Selecione o arquivo";
            }
        }
Exemple #31
0
        protected void ImageButtonDeletePagina_Click(object sender, ImageClickEventArgs e)
        {
            string nomeArquivo = LabelArquivo.Text;
            LabelErro.Text = "";
            ImageAttention.Visible = false;
            //verificar se o nome nao esta nulo
            if (nomeArquivo.Equals(""))
            {
                LabelErro.Text = "Não existe arquivo";
                ImageAttention.Visible = true;
            }
            else
            {
                int page = Convert.ToInt16(TextBoxDeletePagina.Text);
                PdfDocument originalPDF = new PdfDocument(pathDir + nomeArquivo);  //specify original file
                int totalpages = originalPDF.Pages.Count;

                if ((page > totalpages) || (page <= 0))
                {
                    LabelErro.Text = "Página fora do limite";
                    ImageAttention.Visible = true;
                }
                else if (page == totalpages)
                {
                    MergeDocument smallerPDF = new MergeDocument(originalPDF, 1, page - 1);
                    smallerPDF.Draw(nomeArquivo);
                    System.IO.File.Delete(pathDir + nomeArquivo);
                    System.IO.File.Move(nomeArquivo, pathDir + nomeArquivo);
                }
                else
                {
                    MergeDocument smallerPDF = new MergeDocument(originalPDF, 1, page - 1);
                    int pagesAppend = totalpages - page;
                    smallerPDF.Append(originalPDF, page + 1, pagesAppend);  //append pages deleted plus one until page count;
                    smallerPDF.Draw(nomeArquivo);
                    System.IO.File.Delete(pathDir + nomeArquivo);
                    System.IO.File.Move(nomeArquivo, pathDir + nomeArquivo);
                }
            }
        }
Exemple #32
0
        /// <summary>
        /// Método usado para deletar uma página especifica do documento.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        protected void ImageButtonDeletePagina_Click(object sender, ImageClickEventArgs e)
        {
            string nomeArquivo = LabelArquivo.Text;
            LabelErro.Text = "";
            ImageAttention.Visible = false;
            //verificar se o nome nao esta nulo
            if (nomeArquivo.Equals(""))
            {
                ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "window.alert('Não existe arquivo');", true);
            }
            else
            {
                int page = Convert.ToInt16(TextBoxDeletePagina.Text);
                PdfDocument originalPDF = new PdfDocument(pathDir + nomeArquivo);  //specify original file
                int totalpages = originalPDF.Pages.Count;

                if ((page > totalpages) || (page <= 0))
                {
                    ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "window.alert('Página fora do limite!');", true);
                }
                else if (totalpages == 1)
                {
                    System.IO.File.Delete(pathDir + nomeArquivo);
                    TableArquivo.Visible = false;
                    string abaAtiva = retornaAbaAtiva();
                    Session.Add("postou_" + abaAtiva, "nao");
                    ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "window.alert('Página deletada com sucesso!');", true);
                }
                else if (totalpages != 1)
                {
                    if (page == totalpages)
                    {
                        MergeDocument smallerPDF = new MergeDocument(originalPDF, 1, page - 1);
                        smallerPDF.Draw(nomeArquivo);
                        System.IO.File.Delete(pathDir + nomeArquivo);
                        System.IO.File.Move(nomeArquivo, pathDir + nomeArquivo);
                    }
                    else
                    {
                        MergeDocument smallerPDF = new MergeDocument(originalPDF, 1, page - 1);
                        int pagesAppend = totalpages - page;
                        smallerPDF.Append(originalPDF, page + 1, pagesAppend);  //append pages deleted plus one until page count;
                        smallerPDF.Draw(nomeArquivo);
                        System.IO.File.Delete(pathDir + nomeArquivo);
                        System.IO.File.Move(nomeArquivo, pathDir + nomeArquivo);
                    }
                    ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "window.alert('Página deletada com sucesso!');", true);
                }

            }
        }