Ejemplo n.º 1
0
        protected void convert2image(DocFileInfo file, string password, DocFileInfo destFile, bool?repair, ref string responseText)
        {
            bool?status = PDFUtil.pdf2image_isprocessing(file.FileID.Value);

            if ((!status.HasValue || !status.Value) && repair.HasValue && repair.Value)
            {
                PublicMethods.set_timeout(() => {
                    PDFUtil.pdf2image(paramsContainer.Tenant.Id, file, password, destFile, ImageFormat.Png, true);
                }, 0);

                responseText = "{\"Status\":\"" + "Processing" + "\"}";

                //PDFUtil.pdf2image(paramsContainer.Tenant.Id, file.FileID.Value, fileAddress, destFolder, ImageFormat.Png, true);
                //responseText = "{\"Status\":\"" + "Ready" + "\"}";
            }
            else if (status.HasValue)
            {
                responseText = "{\"Status\":\"" + (status.Value ? "Processing" : "Ready") + "\"}";
            }
            else
            {
                PublicMethods.set_timeout(() => {
                    PDFUtil.pdf2image(paramsContainer.Tenant.Id, file, password, destFile, ImageFormat.Png, false);
                }, 0);

                responseText = "{\"Status\":\"" + "Processing" + "\"}";

                //PDFUtil.pdf2image(paramsContainer.Tenant.Id, file.FileID.Value, fileAddress, destFolder, ImageFormat.Png, false);
                //responseText = "{\"Status\":\"" + "Ready" + "\"}";
            }
        }
        /// <summary>
        /// Genera el documento PDF
        /// </summary>
        /// <param name="docGuardar">Documento de aspose a guardar.</param>
        /// <param name="instancia">Documento de instancia.</param>
        /// <param name="concatenarAdjuntos">Si se deben concatenar los documentos adjuntos.</param>
        /// <returns>Documento generado.</returns>
        public static byte[] guardarDocumentoComoPDF(Document docGuardar, DocumentoInstanciaXbrlDto instancia, bool concatenarAdjuntos = true)
        {
            byte[] resultadoArchivo = null;
            String pathSalida       = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".pdf";

            try {
                SaveOptions savePdf = new PdfSaveOptions()
                {
                    UseHighQualityRendering = true
                };

                docGuardar.Save(pathSalida, savePdf);
                if (concatenarAdjuntos)
                {
                    var adjuntos = ObtenDocumentosAdjuntos(instancia);
                    if (adjuntos != null)
                    {
                        var listaFlujosPDF = new List <String>()
                        {
                            pathSalida, adjuntos
                        };
                        pathSalida = PDFUtil.MezclaPDFs(listaFlujosPDF);
                    }
                }
                resultadoArchivo = ReadBytesFromFile(pathSalida);
            } catch (Exception ex) {
                LogUtil.Error(ex);
                throw ex;
            }
            return(resultadoArchivo);
        }
Ejemplo n.º 3
0
        public static byte[] add_custom_cover(Guid applicationId, Guid currentUserId, byte[] pdfContent, Guid coverId, Guid ownerNodeId)
        {
            DocFileInfo pdfCover = null;

            pdfCover = DocumentsController.get_file(applicationId, coverId);
            if (pdfCover == null || string.IsNullOrEmpty(pdfCover.Extension) || pdfCover.Extension.ToLower() != "pdf")
            {
                pdfCover = null;
            }

            byte[] coverContent = pdfContent == null ? null : pdfCover.toByteArray(applicationId);

            if (coverContent == null || coverContent.Length == 0)
            {
                return(pdfContent);
            }

            Dictionary <string, string> dic = CNAPI.get_replacement_dictionary(applicationId, currentUserId, ownerNodeId, true);

            List <FormElement> tempElems = dic.Keys.ToList().Select(key => new FormElement()
            {
                Name      = key,
                Type      = FormElementTypes.Text,
                TextValue = dic[key]
            }).ToList();

            byte[] cover = PDFTemplates.fill_template(coverContent, tempElems);

            return(PDFUtil.merge_documents(new List <object>()
            {
                cover, pdfContent
            }));
        }
        /// <summary>
        /// Obtiene las imagenes del PDF adjunto al concepto indicado y las agrega al documento.
        /// </summary>
        /// <param name="docBuilder">Constructor del documento.</param>
        /// <param name="hecho">Hecho del concepto que contiene el binario</param>
        private void AgregaImagen(DocumentBuilder docBuilder, HechoDto hecho)
        {
            var imagenes = PDFUtil.GetImagesFromPDFAsPathFiles(hecho.Valor);
            var index    = 0;

            foreach (String imagePath in imagenes)
            {
                try
                {
                    docBuilder.InsertBreak(BreakType.SectionBreakNewPage);
                    PageSetup ps         = docBuilder.CurrentSection.PageSetup;
                    var       background = docBuilder.InsertImage(imagePath);
                    background.Width  = ps.PageWidth;
                    background.Height = ps.PageHeight;
                    background.RelativeHorizontalPosition = Aspose.Words.Drawing.RelativeHorizontalPosition.Page;
                    background.RelativeVerticalPosition   = Aspose.Words.Drawing.RelativeVerticalPosition.Page;
                    background.Left       = 0;
                    background.Top        = 0;
                    background.WrapType   = Aspose.Words.Drawing.WrapType.None;
                    background.BehindText = true;
                    index++;
                    //if (index < imagenes.Count)
                    //{
                    //    docBuilder.InsertBreak(BreakType.SectionBreakNewPage);
                    //}
                }
                catch (Exception ex)
                {
                    LogUtil.Error(ex);
                }
            }
        }
Ejemplo n.º 5
0
        private void CreatePreOrder(string filesPathItem)
        {
            if (DataDB.IsExcelAlreadyOrdered(filesPathItem))
            {
                Util.ShowMessage(AlarmType.WARNING, $"El archivo cargado ya ha sido ordenado anteriormente ({filesPathItem})");
                return;
            }
            this.ProcessTextBox.Visible = true;
            List <MaterialBOM> materialList = ExcelUtil.ConvertExcelToMaterialListFromBOM(filesPathItem, this.ProcessTextBox);

            this.ProcessTextBox.Visible = false;
            this.ProcessTextBox.Text    = string.Empty;
            if (materialList == null)
            {
                return;
            }
            if (materialList.Count == 0)
            {
                return;
            }
            Order receiveOrder = DataDB.InsertBOMMaterialList(materialList, filesPathItem);
            List <MaterialOrder> preorderList = receiveOrder.MaterialList;

            if (preorderList.Count != 0)
            {
                PDFUtil.CreatePreOrder(receiveOrder);
                Util.ShowMessage(AlarmType.SUCCESS, $"Se encontraron {preorderList.Count} materiales en almacén");
            }
            else
            {
                MessageBox.Show("No hay ningún producto disponible en almacén");
            }
        }
        /// <summary>
        /// Retorna un flujo de bytes con los PDF's adjuntos.
        /// </summary>
        /// <param name="instancia">Documento de instancia a evaluar.</param>
        /// <returns>Flujo de bytes con los documentos ajuntos.</returns>
        public static String ObtenDocumentosAdjuntos(DocumentoInstanciaXbrlDto instancia)
        {
            var conceptosPorId             = instancia.Taxonomia.ConceptosPorId;
            var diccionarioConceptosBase64 = new Dictionary <String, String>();

            foreach (var idConcepto in conceptosPorId.Keys)
            {
                var concepto = conceptosPorId[idConcepto];
                if (concepto.TipoDato.Contains("base64BinaryItemType"))
                {
                    IList <string> idsHechos;
                    if (instancia.HechosPorIdConcepto.TryGetValue(concepto.Id, out idsHechos) && idsHechos.Count > 0)
                    {
                        var token            = String.Empty;
                        var etiquetaConcepto = ReporteXBRLUtil.obtenerEtiquetaConcepto("es", ReporteXBRLUtil.ETIQUETA_DEFAULT, idConcepto, instancia);
                        for (var indexHecho = 0; indexHecho < idsHechos.Count; indexHecho++)
                        {
                            HechoDto hecho;
                            if (instancia.HechosPorId.TryGetValue(idsHechos[indexHecho], out hecho) && !String.IsNullOrWhiteSpace(hecho.Valor))
                            {
                                var titulo = etiquetaConcepto + token;
                                diccionarioConceptosBase64[titulo] = hecho.Valor;
                                token += " ";
                            }
                        }
                    }
                }
            }
            String salida = diccionarioConceptosBase64.Count > 0 ? PDFUtil.MesclaBase64PDFs(diccionarioConceptosBase64) : null;

            return(salida);
        }
Ejemplo n.º 7
0
        public Bill(String path, String lang)
        {
            CultureInfo ci = new CultureInfo(lang);

            String input = PDFUtil.ReadPdf(path);

            /*
             * Fecha de Expedición:
             * Fecha de Orden de Compra:
             * 2019-08-05T16:02:48-05:00 8/5/2019
             */

            this.code  = Utils.GetText(input, "Factura Folio Interno: ", "\n");
            this.date  = Utils.ToDate(Utils.GetText(input, "Fecha de Orden de Compra:\n", "T"), "yyyy-MM-dd"); // 2019-01-24
            this.total = Utils.ToDouble(Utils.GetText(input, "\nTotal\n", "\n"), ci);
            String codes = Utils.GetText(input, code + "\n", "\n");

            String intemsZone = Utils.GetText(input, "Total\n", "\nAVISO:\n");

            String[] pages     = Utils.SplitText(intemsZone, "\nEste documento es una representación impresa de un CFDI");
            String   itemsText = pages[0];

            for (int i = 1; i < pages.Length - 1; i++)
            {
                itemsText += Utils.GetText(pages[i], codes);
            }
            String[] lines = Utils.Split(itemsText, "\n");
            foreach (String line in lines)
            {
                if (Utils.Split(line, " ").Length > 8)
                {
                    this.items.Add(new BillItem(line, ci));
                }
            }
        }
Ejemplo n.º 8
0
        // private methods...
        /// <summary>
        /// Event hander for when a file is added, modified or deleted
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="fsea"></param>
        private static void OnCreated(object sender, FileSystemEventArgs fsea)
        {
            var pdfUtil = new PDFUtil(fsea.FullPath);
            var pdfTask = new BackgroundWorker();

            pdfTask.DoWork             += pdfTask_DoWork;
            pdfTask.RunWorkerCompleted += pdfTask_RunWorkerCompleted;
            pdfTask.RunWorkerAsync(pdfUtil);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Transform overdraft to html - pdf
        /// </summary>
        /// <param name="previewTransformParams"></param>
        /// <returns></returns>
        public async Task <PreviewTransformResult> TransformAsync(PreviewTransformParams previewTransformParams)
        {
            //Get data to transform
            List <Overdraft> overdrafts = await getDataAsync(previewTransformParams);

            //Get payroll company configuration
            var payrollCompanyConfiguration = await getPayrollCompanyConfigurationAsync(previewTransformParams);

            //Download XML
            Dictionary <Guid, string> xmls = await getXMLAsync(previewTransformParams, overdrafts);

            var previewTransformResult = new PreviewTransformResult();
            var xsltUtil = new XsltUtil();
            var pdfUtil  = new PDFUtil();

            //Arrange
            var details = new ConcurrentBag <PreviewTransformResultDetail>();

            foreach (var previewTransformDetail in previewTransformParams.PreviewTransformParamsDetails)
            {
                var previewTransformResultDetail = new PreviewTransformResultDetail();

                //Get xml
                previewTransformDetail.Overdraft         = overdrafts.FirstOrDefault(p => p.ID == previewTransformDetail.OverdraftID);
                previewTransformResultDetail.OverdraftID = previewTransformDetail.OverdraftID;

                if (null == previewTransformDetail.Overdraft)
                {
                    throw new CotorraException(105, "105", "No se encontró el sobrerecibo proporcionado para generar su PDF.", null);
                }

                xmls.TryGetValue(previewTransformDetail.Overdraft.UUID, out string xml);
                previewTransformResultDetail.XML = xml;

                //Original strings
                (var originalString, var stampingOriginalString) = getOriginalStrings(xml);

                var xsltArgumentList = getXSLTArguments(previewTransformParams, overdrafts, payrollCompanyConfiguration,
                                                        previewTransformResultDetail, originalString, stampingOriginalString);

                //Transform HTML
                var htmlResult = xsltUtil.Transform(previewTransformResultDetail.XML, XsltPath, xsltArgumentList);

                //Transform PDF
                var pdfResult = pdfUtil.Convert(htmlResult);

                //Fill the result
                previewTransformResultDetail.TransformHTMLResult = htmlResult;
                previewTransformResultDetail.TransformPDFResult  = pdfResult;

                details.Add(previewTransformResultDetail);
            }
            //Fill the list
            previewTransformResult.PreviewTransformResultDetails.AddRange(details);

            return(previewTransformResult);
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            PDFUtil pdf = new PDFUtil(File.ReadAllBytes(SRC));

            pdf.AddFooter("Hey This Is me Footer!!!!!");
            pdf.ExtractPDFPage(0, 2);
            var bytes = pdf.GetPDFDataAndClose(true);

            File.WriteAllBytes(DEST, bytes);
        }
Ejemplo n.º 11
0
        protected void get_pages_count(DocFileInfo file, string password, DocFileInfo destFile, ref string responseText)
        {
            bool invalidPassword = false;

            int count          = PDFUtil.get_pages_count(paramsContainer.Tenant.Id, file, password, ref invalidPassword);
            int convertedCount = count == 0 ? 0 : PDFUtil.get_converted_pages_count(paramsContainer.Tenant.Id, destFile);

            responseText = "{\"Count\":" + count.ToString() +
                           ",\"ConvertedCount\":" + convertedCount.ToString() +
                           (!invalidPassword ? string.Empty : ",\"InvalidPassword\":" + invalidPassword.ToString().ToLower()) +
                           "}";
        }
Ejemplo n.º 12
0
        private void BtnPrint_Click(object sender, EventArgs e)
        {
            Btn    btn   = (Btn)sender;
            Order  order = btn.Order;
            string path  = $@"{Util.CURRENT_PATH}\Order_{order.Id}.pdf";

            if (Util.ExistFile(path))
            {
                System.Diagnostics.Process.Start(path);
            }
            else
            {
                order = DataDB.GetOrderById(order.Id);
                PDFUtil.CreateAssignedOrderreport(order);
            }
        }
Ejemplo n.º 13
0
        public OrderList(String path)
        {
            String input = PDFUtil.ReadPdf(path);

            this.id        = Utils.GetText(input, "Entrega No.: ", "\n");
            this.date      = Utils.ToDate(Utils.GetText(input, "Fecha: ", "\n"), "dd.MM.yyyy");
            this.order     = Utils.GetText(input, "Pedido No.: ", "\n");
            this.code      = Utils.GetText(input, "Su no. de pedido: ", "\n");
            this.condition = Utils.GetText(input, "Condición de despacho: ", "\n");
            this.incoterm  = Utils.GetText(input, "Incoterm: ", "\n");

            String packsText = Utils.GetText(input, "\nempaque\n", "\nSuma de peso");

            String[] lines = Utils.Split(packsText, "\n");
            for (int i = 0; i < lines.Length; i++)
            {
                if (Utils.Split(lines[i], " ").Length > 5)
                {
                    String packedCode = Utils.Split(lines[i], " ")[1];
                    if (packedCode.EndsWith("*"))
                    {
                        packedCode = Utils.Split(lines[++i], " ")[0];
                    }
                    String itemsText = Utils.GetText(input, "\nHu-Nr.: " + packedCode);
                    itemsText = Utils.SplitText(itemsText, "\nHu-Nr.: ")[0];
                    String   zoneItems  = "";
                    String[] zonesItems = Utils.Split(itemsText, "UKZ\n");
                    for (int j = 1; j < zonesItems.Length; j++)
                    {
                        zoneItems += Utils.Split(zonesItems[j], "\nPágina\n")[0];
                        int le = zoneItems.LastIndexOf('\n');
                        zoneItems = zoneItems.Substring(0, le + 1);
                    }

                    String[] itemsLines = Utils.Split(zoneItems, "\n");
                    foreach (String itemLine in itemsLines)
                    {
                        String[] dataLine = Utils.Split(itemLine, " ");
                        if (dataLine.Length > 5 && Utils.IsInteger(dataLine[0]))
                        {
                            this.items.Add(new OrderListItem(packedCode, itemLine));
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        private void SetItemList()
        {
            int index = 0;

            foreach (Order order in shownOrdersList)
            {
                string          orderId  = order.Id.ToString();
                FlowLayoutPanel flowItem = new FlowLayoutPanel
                {
                    FlowDirection = FlowDirection.LeftToRight
                };
                Btn btnPrint = new Btn
                {
                    Width  = 50,
                    Height = 35,
                    Order  = order,
                    Text   = "Print",
                    Index  = index
                };
                btnPrint.Click += BtnPrint_Click;
                Label info = new Label
                {
                    Text   = $"{PDFUtil.GetProyectName(order.ExcelPath)}",
                    Width  = Panel.Width - 100,
                    Height = 40,
                    Font   = new System.Drawing.Font("Arial Narrow", 12, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)))
                };

                flowItem.Height = 40;
                flowItem.Width  = Panel.Width;
                flowItem.Name   = orderId;
                flowItem.Controls.Add(info);
                flowItem.Controls.Add(btnPrint);
                Panel.Controls.Add(flowItem);
                index++;
            }
        }
Ejemplo n.º 15
0
        public FileStreamResult printHardCardDetails(string hid)
        {
            string title = string.Empty;

            title = "";
            var model = new HardCard();

            model.HardCardId = Convert.ToInt32(hid);
            HardCardDal.getHardCardDetails(model);
            HardCardDal.getHardCardLookUpList(model);

            // Set up the document and the MS to write it to and create the PDF writer instance
            MemoryStream ms       = new MemoryStream();
            Document     document = new Document(PageSize.A4, 15, 10, 15, 35);
            PdfWriter    writer   = PdfWriter.GetInstance(document, ms);

            writer.PageEvent = new PDFReportEventHelper(title);

            // Open the PDF document
            document.Open();
            document.Add(PDFUtil.HeaderSection("Job Card"));

            #region Job Info
            var jobInfo = PDFUtil.createTableWithHeader("Job Information", new float[] { 2, 2, 2, 2 });

            jobInfo.AddCell(PDFUtil.CreateCell("Estimator", PDFUtil.font_body_bold, 2, false));
            jobInfo.AddCell(PDFUtil.CreateCell(model.JobInformationDetails.EstimatorsName, PDFUtil.spanNormalBlack));
            jobInfo.AddCell(PDFUtil.CreateCell("Job Number", PDFUtil.font_body_bold, 2, false));
            jobInfo.AddCell(PDFUtil.CreateCell(model.JobInformationDetails.Atlas_Job_Number, PDFUtil.spanNormalBlack));

            jobInfo.AddCell(PDFUtil.CreateCell("Est.Phone #", PDFUtil.font_body_bold, 2, false));
            jobInfo.AddCell(PDFUtil.CreateCell(AppUtil.formatPhoneNumber(model.JobInformationDetails.ContractPhoneNumber), PDFUtil.spanNormalBlack));
            jobInfo.AddCell(PDFUtil.CreateCell("BI Number", PDFUtil.font_body_bold, 2, false));
            jobInfo.AddCell(PDFUtil.CreateCell(model.JobInformationDetails.BidItemHeaderId, PDFUtil.spanNormalBlack));

            jobInfo.AddCell(PDFUtil.CreateCell("Job Name", PDFUtil.font_body_bold, 2, false));
            jobInfo.AddCell(PDFUtil.CreateCell(model.JobInformationDetails.JobName, PDFUtil.spanNormalBlack, colSpan: 3));

            jobInfo.AddCell(PDFUtil.CreateCell("Job Address", PDFUtil.font_body_bold, 2, false));
            jobInfo.AddCell(PDFUtil.CreateCell(model.JobInformationDetails.JobAddress, PDFUtil.spanNormalBlack, colSpan: 3));

            jobInfo.AddCell(PDFUtil.CreateCell("Job City", PDFUtil.font_body_bold, 2, false));
            jobInfo.AddCell(PDFUtil.CreateCell(model.JobInformationDetails.JobCity, PDFUtil.spanNormalBlack));
            jobInfo.AddCell(PDFUtil.CreateCell("Job State", PDFUtil.font_body_bold, 2, false));
            jobInfo.AddCell(PDFUtil.CreateCell(model.JobInformationDetails.JobState, PDFUtil.spanNormalBlack));

            jobInfo.AddCell(PDFUtil.CreateCell("Job Contact", PDFUtil.font_body_bold, 2, false));
            jobInfo.AddCell(PDFUtil.CreateCell(model.JobInformationDetails.JobContact, PDFUtil.spanNormalBlack));
            jobInfo.AddCell(PDFUtil.CreateCell("Call In Route", PDFUtil.font_body_bold, 2, false));
            jobInfo.AddCell(PDFUtil.CreateCell(model.JobInformationDetails.ListJobInfoResponse.
                                               FirstOrDefault(i => i.ResponseId.ToString() == model.JobInformationDetails.CallInRoute)?.Response, PDFUtil.spanNormalBlack));

            jobInfo.AddCell(PDFUtil.CreateCell("Contact Phone", PDFUtil.font_body_bold, 2, false));
            jobInfo.AddCell(PDFUtil.CreateCell(AppUtil.formatPhoneNumber(model.JobInformationDetails.JobPhone), PDFUtil.spanNormalBlack));
            jobInfo.AddCell(PDFUtil.CreateCell("Contact Cell", PDFUtil.font_body_bold, 2, false));
            jobInfo.AddCell(PDFUtil.CreateCell(AppUtil.formatPhoneNumber(model.JobInformationDetails.JobCell), PDFUtil.spanNormalBlack));

            document.Add(jobInfo);

            #endregion

            #region ContractorInfo
            var contractInfo = PDFUtil.createTableWithHeader("Contractor Information", new float[] { 2, 2, 2, 2 });
            contractInfo.AddCell(PDFUtil.CreateCell("Contractor Name", PDFUtil.font_body_bold, 2, false));
            contractInfo.AddCell(PDFUtil.CreateCell(model.ContractInformationDetails.ContractorName, PDFUtil.spanNormalBlack, colSpan: 3));


            contractInfo.AddCell(PDFUtil.CreateCell("Primary Contact Name", PDFUtil.font_body_bold, 2, false));
            contractInfo.AddCell(PDFUtil.CreateCell(model.ContractInformationDetails.PrimaryContact, PDFUtil.spanNormalBlack));
            contractInfo.AddCell(PDFUtil.CreateCell("Phone", PDFUtil.font_body_bold, 2, false));
            contractInfo.AddCell(PDFUtil.CreateCell(AppUtil.formatPhoneNumber(model.ContractInformationDetails.PrimaryPhone), PDFUtil.spanNormalBlack));

            contractInfo.AddCell(PDFUtil.CreateCell("Fence Type", PDFUtil.font_body_bold, 2, false));
            contractInfo.AddCell(PDFUtil.CreateCell(model.ContractInformationDetails.ListFenceTypes.
                                                    First(i => i.FenceTypeId.ToString() == model.ContractInformationDetails.FenceType).FenceTypeName, PDFUtil.spanNormalBlack, colSpan: 3));

            contractInfo.AddCell(PDFUtil.CreateCell("Special Notes", PDFUtil.font_body_bold, 2, false));
            contractInfo.AddCell(PDFUtil.CreateCell(model.ContractInformationDetails.SplNotes, PDFUtil.spanNormalBlack));
            contractInfo.AddCell(PDFUtil.CreateCell("Directions", PDFUtil.font_body_bold, 2, false));
            contractInfo.AddCell(PDFUtil.CreateCell(model.ContractInformationDetails.Directions, PDFUtil.spanNormalBlack));

            document.Add(contractInfo);

            #endregion

            #region Installation
            var installDetails = PDFUtil.createTableWithHeader("Installation", new float[] { 2, 2, 2, 2, 2, 2 });
            installDetails.AddCell(PDFUtil.CreateCell("Pre Make Gates", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListInstallationResponses.
                                                      First(i => i.ResponseId.ToString() == model.InstallationDetails.PremakeGate.ToString()).Response, PDFUtil.spanNormalBlack, colSpan: 5));


            installDetails.AddCell(PDFUtil.CreateCell("CBYD", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListInstallationResponses.
                                                      First(i => i.ResponseId.ToString() == model.InstallationDetails.CBYD.ToString()).Response, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("CBYD Date", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.CBYDDate, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("CBYD Number", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.CBYDNumber, PDFUtil.spanNormalBlack));

            installDetails.AddCell(PDFUtil.CreateCell("Start Date", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.StartDate, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("Finish Date", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.FinishDate, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("Hard Date", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListInstallationResponses.
                                                      FirstOrDefault(i => i.ResponseId.ToString() == model.InstallationDetails.HardDate)?.Response, PDFUtil.spanNormalBlack));

            installDetails.AddCell(PDFUtil.CreateCell("Gate Description", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.GateDescription1, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("Gate Installation", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListGateInstallation.
                                                      FirstOrDefault(i => i.GateInstallationID.ToString() == model.InstallationDetails.GateInstallationID1)?.Description, PDFUtil.spanNormalBlack, colSpan: 3));

            installDetails.AddCell(PDFUtil.CreateCell("Gate Description", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.GateDescription2, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("Gate Installation", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListGateInstallation.
                                                      FirstOrDefault(i => i.GateInstallationID.ToString() == model.InstallationDetails.GateInstallationID2)?.Description, PDFUtil.spanNormalBlack, colSpan: 3));

            installDetails.AddCell(PDFUtil.CreateCell("Gate Description", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.GateDescription3, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("Gate Installation", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListGateInstallation.
                                                      FirstOrDefault(i => i.GateInstallationID.ToString() == model.InstallationDetails.GateInstallationID3)?.Description, PDFUtil.spanNormalBlack, colSpan: 3));

            installDetails.AddCell(PDFUtil.CreateCell("Gate Description", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.GateDescription4, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("Gate Installation", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListGateInstallation.
                                                      FirstOrDefault(i => i.GateInstallationID.ToString() == model.InstallationDetails.GateInstallationID4)?.Description, PDFUtil.spanNormalBlack, colSpan: 3));

            installDetails.AddCell(PDFUtil.CreateCell("Gate Description", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.GateDescription5, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("Gate Installation", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListGateInstallation.
                                                      FirstOrDefault(i => i.GateInstallationID.ToString() == model.InstallationDetails.GateInstallationID5)?.Description, PDFUtil.spanNormalBlack, colSpan: 3));


            installDetails.AddCell(PDFUtil.CreateCell("Equipment Required", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListInstallationResponses.
                                                      First(i => i.ResponseId.ToString() == model.InstallationDetails.EquipmentRequired).Response, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("Dig Type", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListDigType.
                                                      First(i => i.DigTypeId == model.InstallationDetails.DigTypeID).DigType, PDFUtil.spanNormalBlack, colSpan: 3));

            installDetails.AddCell(PDFUtil.CreateCell("Water Available", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListInstallationResponses.
                                                      First(i => i.ResponseId.ToString() == model.InstallationDetails.WaterAvailible.ToString()).Response, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("Electricity Available", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListInstallationResponses.
                                                      First(i => i.ResponseId == model.InstallationDetails.ElectricityAvailible).Response, PDFUtil.spanNormalBlack, colSpan: 3));

            installDetails.AddCell(PDFUtil.CreateCell("Measure By Installer", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListInstallationResponses.
                                                      First(i => i.ResponseId.ToString() == model.InstallationDetails.MeasureByInstaller.ToString()).Response, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("Leave Samples By Installer", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.ListInstallationResponses.
                                                      First(i => i.ResponseId == model.InstallationDetails.LeaveSamplesByInstaller).Response, PDFUtil.spanNormalBlack, colSpan: 3));

            installDetails.AddCell(PDFUtil.CreateCell("Budgeted Install Days", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.BudgetedInstallDays, PDFUtil.spanNormalBlack));
            installDetails.AddCell(PDFUtil.CreateCell("Scope", PDFUtil.font_body_bold, 2, false));
            installDetails.AddCell(PDFUtil.CreateCell(model.InstallationDetails.Scope, PDFUtil.spanNormalBlack, colSpan: 3));
            document.Add(installDetails);

            #endregion

            document.NewPage();

            #region BuildChecklist
            var buildList = PDFUtil.createTableWithHeader("Build Checklist", new float[] { 2, 2, 2, 2, 3, 2 });
            buildList.AddCell(PDFUtil.CreateCell("Pool Code", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId.ToString() == model.BuildChecklistDetails.PoolCode.ToString()).Response, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("Dowelled", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.Dowelled).Response, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("Safety Officer Onsite", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.SafetyOfficerOnsite).Response, PDFUtil.spanNormalBlack));

            buildList.AddCell(PDFUtil.CreateCell("Build For Rack", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId.ToString() == model.BuildChecklistDetails.BuildForRack.ToString()).Response, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("Morticed", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.Morticed).Response, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("Saftey Meeting/Orientation Onsite", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.SafteyMeetingOrintationOnsiteReq).Response, PDFUtil.spanNormalBlack));

            buildList.AddCell(PDFUtil.CreateCell("Stepping Temp", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId.ToString() == model.BuildChecklistDetails.SteppingTemp.ToString()).Response, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("Nail On", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.NailOn).Response, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("Saftey Inspection Before Job Starts", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.SafteyInspectionReqBeforeJobStarts).Response, PDFUtil.spanNormalBlack));

            buildList.AddCell(PDFUtil.CreateCell("Fence Direction", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListFenceDirection.
                                                 First(i => i.FenceDirectionID.ToString() == model.BuildChecklistDetails.FenceDirectionID.ToString()).Description, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("Single Nailed", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.SingleNailed).Response, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("PPE Required", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.PPERequired).Response, PDFUtil.spanNormalBlack));

            buildList.AddCell(PDFUtil.CreateCell("Fence Install", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListFenceInstall.
                                                 First(i => i.FenceInstallID.ToString() == model.BuildChecklistDetails.FenceInstallID.ToString()).Description, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("Build Full Sections", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.BuildFullSections).Response, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("Equipment Operator Certs", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.EquipmentOperatorCertsReq).Response, PDFUtil.spanNormalBlack));

            buildList.AddCell(PDFUtil.CreateCell("Trim In Field", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.TrimInField).Response, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("Stain", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.Stain).Response, PDFUtil.spanNormalBlack, colSpan: 3));

            buildList.AddCell(PDFUtil.CreateCell("Post Pins", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListBuildResponses.
                                                 First(i => i.ResponseId == model.BuildChecklistDetails.PostPins).Response, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("Stain Color", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.StainColor, PDFUtil.spanNormalBlack, colSpan: 3));

            buildList.AddCell(PDFUtil.CreateCell("Tear Out Type", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.ListTearOutType.
                                                 First(i => i.TearOutTypeID == model.BuildChecklistDetails.TearOutTypeID).Description, PDFUtil.spanNormalBlack));
            buildList.AddCell(PDFUtil.CreateCell("Stain Brand", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.StainBrand, PDFUtil.spanNormalBlack, colSpan: 3));

            buildList.AddCell(PDFUtil.CreateCell("Other Hazards", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.OtherHazards, PDFUtil.spanNormalBlack, colSpan: 2));
            buildList.AddCell(PDFUtil.CreateCell("Notes", PDFUtil.font_body_bold, 2, false));
            buildList.AddCell(PDFUtil.CreateCell(model.BuildChecklistDetails.Notes, PDFUtil.spanNormalBlack, colSpan: 3));

            document.Add(buildList);
            #endregion

            document.Close();
            byte[]       file   = ms.ToArray();
            MemoryStream output = new MemoryStream();
            output.Write(file, 0, file.Length);
            output.Position = 0;

            HttpContext.Response.AddHeader("content-disposition", "inline; filename=HardCard" + hid + ".pdf");
            return(File(output, "application/pdf"));
        }
Ejemplo n.º 16
0
        protected void send_file(DocFileInfo file, bool logNeeded, bool addPDFCover = false, bool addPDFFooter = false,
                                 Guid?coverId = null, string pdfPassword = null, string contentType = null, bool isAttachment = true)
        {
            byte[] fileContent = file.toByteArray(paramsContainer.ApplicationID);

            if (fileContent.Length == 0)
            {
                send_empty_response();
                return;
            }

            //Save Log
            if (logNeeded && paramsContainer.CurrentUserID.HasValue)
            {
                LogController.save_log(paramsContainer.Tenant.Id, new Log()
                {
                    UserID           = paramsContainer.CurrentUserID,
                    Date             = DateTime.Now,
                    HostAddress      = PublicMethods.get_client_ip(HttpContext.Current),
                    HostName         = PublicMethods.get_client_host_name(HttpContext.Current),
                    Action           = Modules.Log.Action.Download,
                    SubjectID        = file.FileID,
                    Info             = file.toJson(paramsContainer.Tenant.Id),
                    ModuleIdentifier = ModuleIdentifier.DCT
                });
            }
            //end of Save Log

            if (file.Extension.ToLower() == "pdf")
            {
                addPDFCover = addPDFCover && file.OwnerNodeID.HasValue && coverId.HasValue &&
                              paramsContainer.ApplicationID.HasValue && paramsContainer.CurrentUserID.HasValue;

                if (addPDFFooter || addPDFCover)
                {
                    bool invalidPassword = false;

                    fileContent = PDFUtil.get_pdf_content(paramsContainer.Tenant.Id, fileContent, pdfPassword, ref invalidPassword);

                    if (invalidPassword)
                    {
                        string responseText = "{\"InvalidPassword\":" + true.ToString().ToLower() + "}";
                        paramsContainer.return_response(ref responseText);
                        return;
                    }
                }

                if (addPDFFooter)
                {
                    User currentUser = !paramsContainer.CurrentUserID.HasValue ? null :
                                       UsersController.get_user(paramsContainer.Tenant.Id, paramsContainer.CurrentUserID.Value);

                    if (currentUser == null)
                    {
                        currentUser = new User()
                        {
                            UserID    = Guid.NewGuid(),
                            UserName  = "******",
                            FirstName = "[anonymous]",
                            LastName  = "[anonymous]"
                        };
                    }

                    DownloadedFileMeta meta = new DownloadedFileMeta(PublicMethods.get_client_ip(HttpContext.Current),
                                                                     currentUser.UserName, currentUser.FirstName, currentUser.LastName, null);

                    fileContent = PDFTemplates.append_footer(fileContent, meta.toString());
                }

                if (addPDFCover)
                {
                    fileContent = Wiki2PDF.add_custom_cover(paramsContainer.Tenant.Id,
                                                            paramsContainer.CurrentUserID.Value, fileContent, coverId.Value, file.OwnerNodeID.Value);
                }

                if (!string.IsNullOrEmpty(pdfPassword))
                {
                    fileContent = PDFUtil.set_password(fileContent, pdfPassword);
                }
            }

            string retFileName = file.FileName + (string.IsNullOrEmpty(file.Extension) ? string.Empty : "." + file.Extension);

            paramsContainer.file_response(fileContent, retFileName, contentType: contentType, isAttachment: isAttachment);
        }
Ejemplo n.º 17
0
        public static byte[] export_as_pdf(Guid applicationId, Guid?currentUserId, bool isUser, DownloadedFileMeta meta,
                                           string title, string description, List <string> keywords, List <KeyValuePair <Guid, string> > wikiTitles,
                                           Dictionary <Guid, List <KeyValuePair <string, string> > > wikiParagraphs, Dictionary <string, string> metaData,
                                           List <string> authors, Guid?coverId, Guid?coverOwnerNodeId, string password, HttpContext context)
        {
            bool hasCustomCover = coverId.HasValue && coverOwnerNodeId.HasValue && currentUserId.HasValue;

            List <WikiPDFText> wikiCover = hasCustomCover ? new List <WikiPDFText>() :
                                           get_default_cover(applicationId, isUser, title, metaData, authors);

            string strKeywords = string.Join(" - ", keywords);

            WikiPDFText wikiTitle = new WikiPDFText(applicationId,
                                                    @"<br><br><p style='text-align:center;'><strong><span style='color:DarkSlateGray;'>" + title + "</span></strong></p><br><br>");
            List <WikiPDFText> wikiDesc = convert_div_to_p(applicationId, new List <WikiPDFText>()
            {
                new WikiPDFText(applicationId,
                                string.IsNullOrEmpty(description) ? "" : @"<br><p class='NodeAbs'>" + description + "</p><br>")
            });
            WikiPDFText wikiKeywords = new WikiPDFText(applicationId,
                                                       string.IsNullOrEmpty(strKeywords) ? "" : @"<br><p> " + strKeywords + " </p><br>");

            string      pdfTitles     = string.Empty;
            WikiPDFText wikiPDFTitles = null;

            List <WikiPDFText> strHTMLParagraphs = new List <WikiPDFText>();

            foreach (KeyValuePair <Guid, string> t in wikiTitles)
            {
                if (!wikiParagraphs.ContainsKey(t.Key) || wikiParagraphs[t.Key].Count == 0)
                {
                    continue;
                }

                bool hasTitle = !string.IsNullOrEmpty(t.Value);

                int counter = 0;

                if (hasTitle)
                {
                    pdfTitles += "<p><a href='#" + t.Key.ToString() + "'>" + t.Value + "</a></p><br>";
                    pdfTitles += ProviderUtil.list_to_string <string>(wikiParagraphs[t.Key].Where(
                                                                          u => !string.IsNullOrEmpty(u.Key) && !string.IsNullOrEmpty(u.Value)).Select(
                                                                          p => "<p><a style='color:gray;' href='#" + t.Key.ToString() + (++counter).ToString() + "'>" + p.Key + "</a></p><br>").ToList <string>(), ' ');
                }

                wikiPDFTitles = new WikiPDFText(applicationId, pdfTitles);

                counter = 0;

                WikiPDFText mt = !hasTitle ? null : new WikiPDFText(applicationId,
                                                                    @"<br><a name='" + t.Key.ToString() + "'><strong style='color:#00a;'>" + t.Value + "</strong></a>");

                List <KeyValuePair <string, string> > prgrs = wikiParagraphs[t.Key].Where(
                    u => !string.IsNullOrEmpty(u.Value)).Select(x => x).ToList();

                WikiPDFText tempParagraphs = new WikiPDFText(applicationId,
                                                             ProviderUtil.list_to_string <string>(prgrs.Select(u => u.Value).ToList(), ' '));
                if (mt != null && tempParagraphs.IsProbablyRTL)
                {
                    mt.set_is_rtl(true);
                }

                if (mt != null)
                {
                    strHTMLParagraphs.Add(mt);
                }

                foreach (KeyValuePair <string, string> kvp in prgrs)
                {
                    WikiPDFText pp = new WikiPDFText(applicationId, kvp.Value);

                    if (!string.IsNullOrEmpty(kvp.Key))
                    {
                        WikiPDFText pt = new WikiPDFText(applicationId, "<p><a style='color:#444;' name='" +
                                                         t.Key.ToString() + (++counter).ToString() + "'><strong>" + kvp.Key + "</strong></a></p>");

                        if (pp.IsProbablyRTL)
                        {
                            pt.set_is_rtl(true);
                        }

                        strHTMLParagraphs.Add(pt);
                    }

                    strHTMLParagraphs.Add(pp);
                }
            }

            strHTMLParagraphs = convert_div_to_p(applicationId, strHTMLParagraphs);

            using (MemoryStream mem = new MemoryStream())
            {
                using (Document pdfDoc = new Document(PageSize.A4))
                {
                    BaseFont baseFont = BaseFont.CreateFont(
                        PublicMethods.map_path("~/Fonts/windows/IRANSans.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                    Font font = new Font(baseFont, size: 9);

                    PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, mem);

                    PageEventHelper pageEvents = new PageEventHelper(applicationId, title, font, meta);
                    pdfWriter.PageEvent = pageEvents;

                    pdfWriter.RgbTransparencyBlending = true;
                    pdfDoc.Open();

                    StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver();
                    cssResolver.AddCssFile(PublicMethods.map_path("~/CSS/pdf.css"), true);

                    PdfPTable mainTable = new PdfPTable(1)
                    {
                        WidthPercentage = 100,
                        RunDirection    = PdfWriter.RUN_DIRECTION_RTL
                    };

                    mainTable.SplitLate = false;

                    PdfPCell coverCell = new PdfPCell()
                    {
                        FixedHeight         = 750,
                        RunDirection        = PdfWriter.RUN_DIRECTION_RTL,
                        HorizontalAlignment = Element.ALIGN_CENTER
                    };

                    PdfPCell titlesCell = new PdfPCell
                    {
                        Border              = 0,
                        RunDirection        = PdfWriter.RUN_DIRECTION_RTL,
                        HorizontalAlignment = Element.ALIGN_RIGHT,
                        PaddingRight        = 20f,
                        PaddingLeft         = 20f,
                        BackgroundColor     = BaseColor.LIGHT_GRAY
                    };

                    for (int c = 0; c < wikiCover.Count; c++)
                    {
                        _add_to_table(applicationId, context, mainTable, cssResolver, wikiCover[c], font, coverCell);
                    }
                    //_add_to_table(applicationId, context, mainTable, cssResolver, wikiTitle, font);
                    if (!string.IsNullOrEmpty(description))
                    {
                        for (int c = 0; c < wikiDesc.Count; c++)
                        {
                            _add_to_table(applicationId, context, mainTable, cssResolver, wikiDesc[c], font);
                        }
                    }
                    if (!string.IsNullOrEmpty(strKeywords))
                    {
                        _add_to_table(applicationId, context, mainTable, cssResolver, wikiKeywords, font);
                    }
                    //_add_to_table(applicationId, context, mainTable, cssResolver, wikiPDFTitles, font, titlesCell);
                    for (int c = 0; c < strHTMLParagraphs.Count; c++)
                    {
                        _add_to_table(applicationId, context, mainTable, cssResolver, strHTMLParagraphs[c], font);
                    }

                    pdfDoc.Add(mainTable);

                    pdfDoc.Close();

                    byte[] finalContent = mem.ToArray();

                    if (hasCustomCover)
                    {
                        finalContent = add_custom_cover(applicationId,
                                                        currentUserId.Value, finalContent, coverId.Value, coverOwnerNodeId.Value);
                    }

                    return(string.IsNullOrEmpty(password) ? finalContent : PDFUtil.set_password(finalContent, password));
                }
            }
        }
Ejemplo n.º 18
0
        public FileStreamResult printJobActivation(string prjid)
        {
            string title = string.Empty;

            var model = new JobActivationChecklist();

            model.PRJID = Convert.ToInt32(prjid);
            model       = ChecklistDal.getProjectActivationDetails(model);
            model       = ChecklistDal.JobActivationLookup(model);

            MemoryStream ms       = new MemoryStream();
            Document     document = new Document(PageSize.A4, 15, 10, 15, 35);
            PdfWriter    writer   = PdfWriter.GetInstance(document, ms);

            writer.PageEvent = new PDFReportEventHelper(title);

            // Open the PDF document
            document.Open();
            document.Add(PDFUtil.HeaderSection("Job Activation Checklist"));

            var projectTable = PDFUtil.createTableWithHeader("Project Information", new float[] { 3, 6 });

            projectTable.AddCell(PDFUtil.CreateCell("Atlas Job Number", PDFUtil.font_body_bold, 2, false));
            projectTable.AddCell(PDFUtil.CreateCell(model.projectInformation.JobNumber, PDFUtil.spanNormalBlack, 0, false));
            projectTable.AddCell(PDFUtil.CreateCell("Atlas Company Name", PDFUtil.font_body_bold, 2, false));
            projectTable.AddCell(PDFUtil.CreateCell(model.projectInformation.CompanyName, PDFUtil.spanNormalBlack, 0, false));
            projectTable.AddCell(PDFUtil.CreateCell("Customer/Contractor Name", PDFUtil.font_body_bold, 2, false));
            projectTable.AddCell(PDFUtil.CreateCell(model.projectInformation.CustomerProfile.Name, PDFUtil.spanNormalBlack, 0, false));
            projectTable.AddCell(PDFUtil.CreateCell("Address, City, State, Zip", PDFUtil.font_body_bold, 2, false));
            string CustomerAddr = string.Format("{0} | {1} | {2} | {3}",
                                                model.projectInformation.CustomerProfile.Address ?? "-",
                                                model.projectInformation.CustomerProfile.City ?? "-",
                                                model.projectInformation.CustomerProfile.State ?? "-",
                                                model.projectInformation.CustomerProfile.Zip ?? "-");

            projectTable.AddCell(PDFUtil.CreateCell(CustomerAddr, PDFUtil.spanNormalBlack, 0, false));
            projectTable.AddCell(PDFUtil.CreateCell("Phone Number, Extension", PDFUtil.font_body_bold, 2, false));
            string CustomerPhone = string.Format("{0} | {1}",
                                                 AppUtil.formatPhoneNumber(model.projectInformation.CustomerProfile.PhoneNumber) ?? "-",
                                                 AppUtil.formatPhoneNumber(model.projectInformation.CustomerProfile.Extension) ?? "-");

            projectTable.AddCell(PDFUtil.CreateCell(CustomerPhone, PDFUtil.spanNormalBlack, 0, false));
            projectTable.AddCell(PDFUtil.CreateCell("Project Name", PDFUtil.font_body_bold, 2, false));
            projectTable.AddCell(PDFUtil.CreateCell(model.projectInformation.ProjectProfile.Name, PDFUtil.spanNormalBlack, 0, false));
            projectTable.AddCell(PDFUtil.CreateCell("Address, City, State, Zip", PDFUtil.font_body_bold, 2, false));
            string ProjectAddr = string.Format("{0} | {1} | {2} | {3}",
                                               model.projectInformation.ProjectProfile.Address ?? "-",
                                               model.projectInformation.ProjectProfile.City ?? "-",
                                               model.projectInformation.ProjectProfile.State ?? "-",
                                               model.projectInformation.ProjectProfile.Zip ?? "-");

            projectTable.AddCell(PDFUtil.CreateCell(ProjectAddr, PDFUtil.spanNormalBlack, 0, false));
            projectTable.AddCell(PDFUtil.CreateCell("Contact Name/Phone Number, Ext", PDFUtil.font_body_bold, 2, false));
            string ProjectPhone = string.Format("{0} | {1} | {2}",
                                                model.projectInformation.CustomerProfile.ContactName ?? "-",
                                                AppUtil.formatPhoneNumber(model.projectInformation.CustomerProfile.PhoneNumber) ?? "-",
                                                AppUtil.formatPhoneNumber(model.projectInformation.CustomerProfile.Extension) ?? "-");

            projectTable.AddCell(PDFUtil.CreateCell(ProjectPhone, PDFUtil.spanNormalBlack, 0, false));
            projectTable.AddCell(PDFUtil.CreateCell("Customer Type", PDFUtil.font_body_bold, 2, false));
            projectTable.AddCell(PDFUtil.CreateCell(model.ListCustomersTypes.
                                                    First(i => i.CustomerTypeID.ToString() == model.projectInformation.CustomerType).Description, PDFUtil.spanNormalBlack, 0, false));
            projectTable.AddCell(PDFUtil.CreateCell("Job Type", PDFUtil.font_body_bold, 2, false));
            projectTable.AddCell(PDFUtil.CreateCell(model.ListJobTypes.
                                                    First(i => i.JobTypeId.ToString() == model.projectInformation.Jobtype).JobTypeDesc, PDFUtil.spanNormalBlack, 0, false));
            projectTable.AddCell(PDFUtil.CreateCell("Customer Bid/Job Reference #", PDFUtil.font_body_bold, 2, false));
            projectTable.AddCell(PDFUtil.CreateCell(model.projectInformation.CustomerBidReference, PDFUtil.spanNormalBlack, 0, false));
            projectTable.AddCell(PDFUtil.CreateCell("Scope of Work to be performed", PDFUtil.font_body_bold, 2, false));
            projectTable.AddCell(PDFUtil.CreateCell(model.projectInformation.ScopeWorkToBePerformed, PDFUtil.spanNormalBlack, 0, false));

            projectTable.AddCell(PDFUtil.CreateCell("Type of Labor", PDFUtil.font_body_bold, 2, false));
            projectTable.AddCell(PDFUtil.CreateCell(model.ListLabourTypes.First(i => i.MhRateId.ToString() == model.projectInformation.TypeOfLabour).MhRateName, PDFUtil.spanNormalBlack, 0, false));

            document.Add(projectTable);

            var ContractTable = PDFUtil.createTableWithHeader("Contract/Job Paperwork", new float[] { 3, 1, 1.5f, 5 });

            ContractTable.AddCell(PDFUtil.CreateCell("Copy of Contract or PO", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                     First(i => i.ResponseId.ToString() == model.contractPaperWork.CopyOfContractorPO).Response, PDFUtil.spanNormalBlack, 0, false));
            ContractTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.contractPaperWork.CopyOfContractorPOComments, PDFUtil.spanNormalBlack, 0, false));

            ContractTable.AddCell(PDFUtil.CreateCell("Broken scope into appropriate phases", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                     First(i => i.ResponseId.ToString() == model.contractPaperWork.BrokenScopephases).Response, PDFUtil.spanNormalBlack, 0, false));
            ContractTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.contractPaperWork.BrokenScopephasesComments, PDFUtil.spanNormalBlack, 0, false));

            ContractTable.AddCell(PDFUtil.CreateCell("Bid Roll-up (For each BI being activated)", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                     First(i => i.ResponseId.ToString() == model.contractPaperWork.BidRollUp).Response, PDFUtil.spanNormalBlack, 0, false));
            ContractTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.contractPaperWork.BidRollUpComments, PDFUtil.spanNormalBlack, 0, false));

            ContractTable.AddCell(PDFUtil.CreateCell("Pack CFS for each BI rollup", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                     First(i => i.ResponseId.ToString() == model.contractPaperWork.PackCFSPIRollUp).Response, PDFUtil.spanNormalBlack, 0, false));
            ContractTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.contractPaperWork.PackCFSPIRollUpcomments, PDFUtil.spanNormalBlack, 0, false));

            ContractTable.AddCell(PDFUtil.CreateCell("Applicable quote(s) for special material", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                     First(i => i.ResponseId.ToString() == model.contractPaperWork.ApplicableQuote).Response, PDFUtil.spanNormalBlack, 0, false));
            ContractTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.contractPaperWork.ApplicableQuoteComments, PDFUtil.spanNormalBlack, 0, false));

            ContractTable.AddCell(PDFUtil.CreateCell("Drawings/field conditions or grading reports", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                     First(i => i.ResponseId.ToString() == model.contractPaperWork.DrawingConditions).Response, PDFUtil.spanNormalBlack, 0, false));
            ContractTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.contractPaperWork.DrawingConditionsComments, PDFUtil.spanNormalBlack, 0, false));

            ContractTable.AddCell(PDFUtil.CreateCell("Site Photos", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                     First(i => i.ResponseId.ToString() == model.contractPaperWork.SitePhotos).Response, PDFUtil.spanNormalBlack, 0, false));
            ContractTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.contractPaperWork.SitePhotosComments, PDFUtil.spanNormalBlack, 0, false));

            ContractTable.AddCell(PDFUtil.CreateCell("Hard Card completely filled out", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                     First(i => i.ResponseId.ToString() == model.contractPaperWork.HardCard).Response, PDFUtil.spanNormalBlack, 0, false));
            ContractTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.contractPaperWork.HardCardComments, PDFUtil.spanNormalBlack, 0, false));

            ContractTable.AddCell(PDFUtil.CreateCell("Pay Envelope (residential only)", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                     First(i => i.ResponseId.ToString() == model.contractPaperWork.PayEnvelope).Response, PDFUtil.spanNormalBlack, 0, false));
            ContractTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            ContractTable.AddCell(PDFUtil.CreateCell(model.contractPaperWork.PayEnvelopeComments, PDFUtil.spanNormalBlack, 0, false));

            document.Add(ContractTable);

            document.NewPage();

            var BondingTable = PDFUtil.createTableWithHeader("Bonding/Insurance/Labor ", new float[] { 3, 1, 1.5f, 5 });

            BondingTable.AddCell(PDFUtil.CreateCell("Received bond (if required) and necessary insurance certification", PDFUtil.font_body_bold, 2, false));
            BondingTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                    First(i => i.ResponseId.ToString() == model.bondingInsurance.InsuranceCertification).Response, PDFUtil.spanNormalBlack, 0, false));
            BondingTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            BondingTable.AddCell(PDFUtil.CreateCell(model.bondingInsurance.InsuranceCertificationComments, PDFUtil.spanNormalBlack, 0, false));

            document.Add(BondingTable);

            var SafetyTable = PDFUtil.createTableWithHeader("Safety Requirements - For all 'Yes' answers, please provide additional details",
                                                            new float[] { 3, 1, 1.5f, 5 });

            SafetyTable.AddCell(PDFUtil.CreateCell("Is there a safety officer on site? If so, provide Contact Informatios there a safety officer on site? If so, provide Contact Information", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                   First(i => i.ResponseId.ToString() == model.safetyRequirements.SafetyOfficer).Response, PDFUtil.spanNormalBlack, 0, false));
            SafetyTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.safetyRequirements.SafetyOfficerComments, PDFUtil.spanNormalBlack, 0, false));

            SafetyTable.AddCell(PDFUtil.CreateCell("Any safety meetings/orientation or badging needed before the job starts?", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                   First(i => i.ResponseId.ToString() == model.safetyRequirements.SafetyMeeting).Response, PDFUtil.spanNormalBlack, 0, false));
            SafetyTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.safetyRequirements.SafetyMeetingComments, PDFUtil.spanNormalBlack, 0, false));

            SafetyTable.AddCell(PDFUtil.CreateCell("Any daily safety meetings, truck/tool inspections required?", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                   First(i => i.ResponseId.ToString() == model.safetyRequirements.DailySafetyMeeting).Response, PDFUtil.spanNormalBlack, 0, false));
            SafetyTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.safetyRequirements.DailySafetyMeetingComments, PDFUtil.spanNormalBlack, 0, false));

            SafetyTable.AddCell(PDFUtil.CreateCell("Any specific PPE needed (e.g. fall protection,flotation, fire clothing, etc.)", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                   First(i => i.ResponseId.ToString() == model.safetyRequirements.PPENeeded).Response, PDFUtil.spanNormalBlack, 0, false));
            SafetyTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.safetyRequirements.PPENeededComments, PDFUtil.spanNormalBlack, 0, false));

            SafetyTable.AddCell(PDFUtil.CreateCell("Is fall protection is required? Please provide details of the situation ?", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                   First(i => i.ResponseId.ToString() == model.safetyRequirements.FallProtection).Response, PDFUtil.spanNormalBlack, 0, false));
            SafetyTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.safetyRequirements.FallProtectionComments, PDFUtil.spanNormalBlack, 0, false));

            SafetyTable.AddCell(PDFUtil.CreateCell("Any equipment certifications required (e.g. Bobcats, Forklifts, High lift, etc)?", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                   First(i => i.ResponseId.ToString() == model.safetyRequirements.EquipmentCertification).Response, PDFUtil.spanNormalBlack, 0, false));
            SafetyTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.safetyRequirements.EquipmentCertificationComments, PDFUtil.spanNormalBlack, 0, false));

            SafetyTable.AddCell(PDFUtil.CreateCell("Other hazards (water, lane closure, dust/respirator, HEPA, vacuum, heavy lifting)", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.ListResponses.
                                                   First(i => i.ResponseId.ToString() == model.safetyRequirements.OtherHazards).Response, PDFUtil.spanNormalBlack, 0, false));
            SafetyTable.AddCell(PDFUtil.CreateCell("Comments", PDFUtil.font_body_bold, 2, false));
            SafetyTable.AddCell(PDFUtil.CreateCell(model.safetyRequirements.OtherHazardsComments, PDFUtil.spanNormalBlack, 0, false));

            document.Add(SafetyTable);

            var OtherImportantTable = PDFUtil.createTableWithHeader("Other Important Factors", new float[] { 3, 7 });

            OtherImportantTable.AddCell(PDFUtil.CreateCell("Please fill in any other pertinant information", PDFUtil.font_body_bold, 2, false));
            OtherImportantTable.AddCell(PDFUtil.CreateCell(model.otherImportantFactors.OtherPertinentInformation, PDFUtil.spanNormalBlack, 0, false));
            document.Add(OtherImportantTable);

            var footerTable = PDFUtil.createTableWithHeader("", new float[] { 1, 2, 1, 2 }, true);

            footerTable.AddCell(PDFUtil.CreateCell("Estimator Name", PDFUtil.font_body_bold, 2, false));
            footerTable.AddCell(PDFUtil.CreateCell(model.projectInformation.Estimator, PDFUtil.spanNormalBlack, 0, false));
            footerTable.AddCell(PDFUtil.CreateCell("Date Completed", PDFUtil.font_body_bold, 2, false));
            footerTable.AddCell(PDFUtil.CreateCell(model.DateCompleted, PDFUtil.spanNormalBlack, 0, false));

            footerTable.AddCell(PDFUtil.CreateCell("Approved By", PDFUtil.font_body_bold, 2, false));
            footerTable.AddCell(PDFUtil.CreateCell(model.ListUsers.First(i => i.UserId.ToString() == model.ApprovedBy).Name, PDFUtil.spanNormalBlack, 0, false));
            footerTable.AddCell(PDFUtil.CreateCell("Date Reviewed", PDFUtil.font_body_bold, 2, false));
            footerTable.AddCell(PDFUtil.CreateCell(model.DateReviewed, PDFUtil.spanNormalBlack, 0, false));
            document.Add(footerTable);

            document.Close();
            byte[]       file   = ms.ToArray();
            MemoryStream output = new MemoryStream();

            output.Write(file, 0, file.Length);
            output.Position = 0;

            HttpContext.Response.AddHeader("content-disposition", "inline; filename=JobActivation_" + prjid + ".pdf");
            return(File(output, "application/pdf"));
        }