コード例 #1
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);
                }
            }
        }
コード例 #2
0
        public byte[] Run(List <PersonFiles> files)
        {
            var                mergeXml          = GetMergeXml(files);
            MergeDocument      documentXml       = mergeXml.Items.First();
            IPresentationTools presentationTools = new PresentationTools();

            byte[] emptyTemplate = files.Where(p => p.Person == "/" && p.Name == "template.pptx").Select(d => d.Data).FirstOrDefault();
            using (MemoryStream emptyDocInMemoryStream = new MemoryStream(emptyTemplate, 0, emptyTemplate.Length, true, true))
            {
                OpenXmlPowerToolsDocument emptyDocPowerTools = new OpenXmlPowerToolsDocument(string.Empty, emptyDocInMemoryStream);
                using (OpenXmlMemoryStreamDocument streamEmptyDoc = new OpenXmlMemoryStreamDocument(emptyDocPowerTools))
                {
                    PresentationDocument emptyPresentation = streamEmptyDoc.GetPresentationDocument();
                    foreach (MergeDocumentPart part in documentXml.Part)
                    {
                        byte[] byteArray = files.Where(p => p.Person == part.Name && p.Name == part.Id).Select(d => d.Data).FirstOrDefault();
                        using (MemoryStream partDocInMemoryStream = new MemoryStream(byteArray, 0, byteArray.Length, true, true))
                        {
                            OpenXmlPowerToolsDocument partDocPowerTools = new OpenXmlPowerToolsDocument(string.Empty, partDocInMemoryStream);
                            using (OpenXmlMemoryStreamDocument streamDividedDoc = new OpenXmlMemoryStreamDocument(partDocPowerTools))
                            {
                                PresentationDocument templatePresentation = streamDividedDoc.GetPresentationDocument();
                                presentationTools.InsertSlidesFromTemplate(emptyPresentation, templatePresentation);
                            }
                        }
                    }

                    return(streamEmptyDoc.GetModifiedDocument().DocumentByteArray);
                }
            }
        }
コード例 #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);
        }
コード例 #4
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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        public byte[] Run(List <PersonFiles> files)
        {
            var mergeXml = GetMergeXml(files);

            byte[] template = files.Where(p => p.Person == "/" && p.Name == "template.xlsx").Select(d => d.Data).FirstOrDefault();
            using (MemoryStream docInMemoryStream = new MemoryStream(template, 0, template.Length, true, true))
            {
                OpenXmlPowerToolsDocument docPowerTools = new OpenXmlPowerToolsDocument(string.Empty, docInMemoryStream);
                using (OpenXmlMemoryStreamDocument streamEmptyDoc = new OpenXmlMemoryStreamDocument(docPowerTools))
                {
                    SpreadsheetDocument excelTemplateDoc = streamEmptyDoc.GetSpreadsheetDocument();
                    excelTemplateDoc.WorkbookPart.Workbook.Sheets = new Sheets();

                    MergeDocument documentXml = mergeXml.Items.First();
                    foreach (MergeDocumentPart part in documentXml.Part)
                    {
                        byte[] byteArray = files.Where(p => p.Person == part.Name && p.Name == part.Id).Select(d => d.Data).FirstOrDefault();
                        using (MemoryStream docPartInMemoryStream = new MemoryStream(byteArray, 0, byteArray.Length, true, true))
                        {
                            OpenXmlPowerToolsDocument docPartPowerTools = new OpenXmlPowerToolsDocument(string.Empty, docPartInMemoryStream);
                            using (OpenXmlMemoryStreamDocument streamPartDoc = new OpenXmlMemoryStreamDocument(docPartPowerTools))
                            {
                                SpreadsheetDocument spreadSheetDocument = streamPartDoc.GetSpreadsheetDocument();
                                ExcelTools.MergeWorkSheets(excelTemplateDoc, spreadSheetDocument);

                                // Close the handle explicitly.
                                spreadSheetDocument.Close();
                            }
                        }
                    }

                    return(streamEmptyDoc.GetModifiedDocument().DocumentByteArray);
                }
            }
        }
コード例 #7
0
ファイル: MergeCMDocumentServices.cs プロジェクト: yefta/IIF
        public void DoMergeCMDocument(long id, string mergeByFQN, string mergeBy)
        {
            MergeDocument svcMerge     = new MergeDocument();
            string        conStringIIF = this.AppConfig.IIFConnectionString;

            svcMerge.MergeCMDocument(id, conStringIIF, this.AppConfig.CMMergeDocumentTemplateLocation, this.AppConfig.CMMergeDocumentTemporaryLocation, mergeByFQN, mergeBy);
        }
コード例 #8
0
        // 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");
        }
コード例 #9
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"));
        }
コード例 #10
0
        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);
        }
        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"));
        }
コード例 #12
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 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"));
        }
コード例 #14
0
        // 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");
        }
コード例 #15
0
        // 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");
        }
コード例 #16
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"));
        }
コード例 #17
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);
        }
コード例 #18
0
        public void DoMergePAMDocument(long id, string mergeByFQN, string mergeBy)
        {
            MergeDocument svcMerge     = new MergeDocument();
            string        conStringIIF = this.AppConfig.IIFConnectionString;

            svcMerge.MergePAMDocument(id, conStringIIF, this.AppConfig.PAMMergeDocumentTemplateLocation, this.AppConfig.PAMMergeDocumentTemporaryLocation, mergeByFQN, mergeBy);

            PAM_Services svcPAM = new PAM_Services();

            svcPAM.AppConfig = this.AppConfig;
            svcPAM.DownloadPAMToSharedFolder(id);
        }
コード例 #19
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"));
        }
コード例 #21
0
ファイル: tab_default.ascx.cs プロジェクト: igorpontes/ZCR
        /// <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);
                }
            }
        }
コード例 #22
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");
        }
コード例 #23
0
        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);
        }
コード例 #24
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"));
        }
コード例 #25
0
        public void Run(string path)
        {
            string appPath     = Path.GetDirectoryName(Assembly.GetAssembly(typeof(WordMerge)).Location);
            string xmlFilePath = appPath + @"\Files\" + "mergeXmlDefinition.xml";
            var    xml         = File.ReadAllText(xmlFilePath);
            Merge  mergeXml;

            using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Merge));
                mergeXml = (Merge)serializer.Deserialize(stream);
            }

            Body          body        = new Body();
            MergeDocument documentXml = mergeXml.Items.First();

            foreach (MergeDocumentPart part in documentXml.Part)
            {
                WordprocessingDocument wordprocessingDocument =
                    WordprocessingDocument.Open(appPath + @"\Files\" + part.Name + @"\" + part.Id + ".docx", true);

                // Assign a reference to the existing document body.
                foreach (OpenXmlElement element in wordprocessingDocument.MainDocumentPart.Document.Body.ChildElements)
                {
                    body.Append(element.CloneNode(true));
                }

                // Close the handle explicitly.
                wordprocessingDocument.Close();
            }

            byte[] byteArray = File.ReadAllBytes(appPath + @"\Files\" + "template.docx");
            using (MemoryStream mem = new MemoryStream())
            {
                mem.Write(byteArray, 0, (int)byteArray.Length);
                using (WordprocessingDocument wordDoc =
                           WordprocessingDocument.Open(mem, true))
                {
                    wordDoc.MainDocumentPart.Document.Body = body;
                    wordDoc.MainDocumentPart.Document.Save();

                    using (FileStream fileStream = new FileStream(path,
                                                                  FileMode.CreateNew))
                    {
                        mem.WriteTo(fileStream);
                    }
                }
            }
        }
コード例 #26
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");
        }
コード例 #27
0
        // 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");
        }
コード例 #28
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);
        }
コード例 #29
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");
        }
コード例 #30
0
        // 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");
        }
コード例 #31
0
ファイル: tab_default.ascx.cs プロジェクト: igorpontes/ZCR
        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);
                }
            }
        }
コード例 #32
0
ファイル: tab_default.ascx.cs プロジェクト: igorpontes/ZCR
        /// <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);
                }

            }
        }
コード例 #33
0
ファイル: AppaltoService.cs プロジェクト: gipasoft/Sfera
        public Documento FillDocument(int? idModello, Appalto appalto, int idAzienda)
        {
            Documento result = null;
            if (idModello > 0 || appalto.TipoContratto > 0)
            {
                _appalto = appalto;

                if (idModello == null)
                {
                    var modello = _daoFactory.GetTipoContrattoDao().GetById(appalto.TipoContratto, false).ModelloLettera;
                    if (modello != null)
                        idModello = modello.ID;
                }

                if (idModello != null)
                {
                    var rtf = Conversione.ToString(_modelloLetteraservice.GetLettera(idModello.Value).Body);

                    var azienda = _daoFactory.GetAziendaDao().GetById(idAzienda, false);

                    var merge = new MergeDocument(rtf, false);

                    merge.Execute("nomeStudio", azienda.Descrizione);

                    if (azienda.Amministratore != null)
                        merge.Execute("amministratore", string.Format("{0} {1}", azienda.Amministratore.PersonaRiferimento.Nome, azienda.Amministratore.PersonaRiferimento.Cognome));

                    if (azienda.IndirizzoSede != null)
                    {
                        merge.Execute("indirizzoStudio", azienda.IndirizzoSede.Indirizzo);
                        if (azienda.IndirizzoSede.Comune != null)
                            merge.Execute("comuneStudio", azienda.IndirizzoSede.Comune.Descrizione);
                    }

                    merge.Execute("descrizioneAllegato1", appalto.DescrizioneStabile);
                    if (DateTimeFormatInfo.CurrentInfo != null)
                        merge.Execute("meseAnno", DateTimeFormatInfo.CurrentInfo.GetMonthName(appalto.DataAppalto.GetValueOrDefault().Month) + " " + appalto.DataAppalto.GetValueOrDefault().Year);
                    merge.Execute("intestazioneCondominio", appalto.Intestazione);
                    merge.Execute("dataInizioLavori", appalto.DataInizioLavori.GetValueOrDefault().ToShortDateString());
                    merge.Execute("descrizioneCompletaCondominio", appalto.DescrizioneStabile);
                    merge.Execute("descrizioneAppaltatore", appalto.Appaltatore);
                    merge.Execute("indirizzoAppaltatore", appalto.IndirizzoAppaltatore);
                    merge.Execute("comuneAppaltatore", appalto.ComuneAppaltatore);
                    merge.Execute("partitaIvaAppaltatore", appalto.PartitaIvaAppaltatore);
                    merge.Execute("codiceFiscaleAppaltatore", appalto.CodiceFiscaleAppaltatore);
                    merge.Execute("registroImprese", appalto.RegistroImprese);
                    merge.Execute("inailPat", appalto.InailPat);
                    merge.Execute("inailIdentificativo", appalto.InailIdentificativo);
                    merge.Execute("descrizionePolizza", appalto.CompagniaAssicurativa + " - " + appalto.AgenziaAssicurativa);
                    merge.Execute("compagniaAssicurativa", appalto.CompagniaAssicurativa + " - " + appalto.AgenziaAssicurativa);
                    merge.Execute("numeroPolizza", appalto.NumeroPolizza);
                    merge.Execute("importoAppaltoCifre", appalto.ImportoAppalto.GetValueOrDefault().ToString("c"));
                    merge.Execute("importoAppaltoLettere", CifreLettere.CalcolaLettere(appalto.ImportoAppalto.GetValueOrDefault()));
                    merge.Execute("descrizioneImporto", appalto.DescrizioneImportoAppalto);
                    merge.Execute("impPenCifre", appalto.ImportoPenalitaAppalto.GetValueOrDefault().ToString("c"));
                    merge.Execute("impPenLettere", CifreLettere.CalcolaLettere(appalto.ImportoPenalitaAppalto.GetValueOrDefault()));
                    merge.Execute("giorniFineLavoriCifre", appalto.GiorniFineLavori.GetValueOrDefault().ToString("#,##0"));
                    merge.Execute("giorniFineLavoriLettere", CifreLettere.CalcolaLettere(Convert.ToDecimal(appalto.GiorniFineLavori.GetValueOrDefault())));
                    merge.Execute("pagamento", appalto.ModalitaPagamento);
                    merge.Execute("descrizioneLavori", appalto.DescrizioneLavori);
                    var descrizioneAllegato = string.Empty;
                    if (appalto.Allegati != null && appalto.Allegati.Length > 0)
                        descrizioneAllegato = appalto.Allegati.Aggregate(descrizioneAllegato, (current, t) => current + (t + Environment.NewLine));
                    merge.Execute("descrizioneAllegato", descrizioneAllegato);

                    merge.Execute("oggettoAppalto", appalto.OggettoAppalto);

                    try
                    {
                        // TODO: Da rivedere per evitare di scrivere il file temporaneo
                        var filePath = Path.GetTempPath() + "Appalto_" + _appalto.TipoContratto + ".rtf";

                        try
                        {
                            var bytes = merge.GetRtf();
                            var documentoMessage = _saveAppalto.Save(appalto, bytes, "Appalto_" + appalto.TipoContratto + ".rtf");
                            if (documentoMessage.Documento != null)
                            {
                                result = documentoMessage.Documento;
                            }
                        }
                        catch (Exception ex)
                        {
                            _log.ErrorFormat("Errore inaspettato nel metodo: {0} - filePath.{1} - modello:{2}", ex, Utility.GetMethodDescription(), filePath, idModello.GetValueOrDefault());
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.ErrorFormat("Errore inaspettato nel metodo: {0} - modello:{1}", ex, Utility.GetMethodDescription(), idModello.GetValueOrDefault());
                    }                    
                }
                else
                {
                    throw new InvalidDataException("Per il tipo di contratto selezionato non è definito nessun modello di appalto");
                }

            }

            return result;
        }