public byte[] OrderToPdf(Order order)
        {
            Guard.NotNull(order, nameof(order));

            var controllerContext = CreateControllerContext();
            var pdfSettings       = _services.Settings.LoadSetting <PdfSettings>(order.StoreId);
            var routeValues       = new RouteValueDictionary(new { storeId = order.StoreId, lid = _services.WorkContext.WorkingLanguage.Id, area = "" });

            var model  = _orderHelper.PrepareOrderDetailsModel(order);
            var models = new List <OrderDetailsModel> {
                model
            };

            var settings = new PdfConvertSettings();

            settings.Size    = pdfSettings.LetterPageSizeEnabled ? PdfPageSize.Letter : PdfPageSize.A4;
            settings.Margins = new PdfPageMargins {
                Top = 35, Bottom = 35
            };
            settings.Page   = new PdfViewContent(OrderHelper.OrderDetailsPrintViewPath, models, controllerContext);
            settings.Header = new PdfRouteContent("PdfReceiptHeader", "Common", routeValues, controllerContext);
            settings.Footer = new PdfRouteContent("PdfReceiptFooter", "Common", routeValues, controllerContext);

            var pdfData = _pdfConverter.Convert(settings);

            return(pdfData);
        }
Пример #2
0
        public IActionResult Get()
        {
            var doc = new PdfDocument()
            {
                GlobalSettings =
                {
                    PaperSize   = PaperKind.A3,
                    Orientation = Orientation.Landscape,
                },

                Objects =
                {
                    new PdfPage()
                    {
                        Page = "http://google.com/",
                    },
                    new PdfPage()
                    {
                        Page = "https://github.com/",
                    }
                }
            };

            byte[] pdf = _converter.Convert(doc);


            return(new FileContentResult(pdf, "application/pdf"));
        }
Пример #3
0
        /// <summary>
        /// Funzione per la conversione di un file
        /// </summary>
        /// <param name="filePath">Nome del file da convertire comprensivo di path</param>
        /// <param name="outFilePath">Nome da assegnare al file convertito</param>
        /// <param name="recognizeText">True se è richiescto anche il riconoscimento testo (OCR)</param>
        /// <returns>True se la conversione è andata a buon fine</returns>
        public bool Convert(String filePath, String outFilePath, bool recognizeText)
        {
            // Valore da restituire
            bool toReturn = false;

            // Se il file non può essere convertito, viene lanciata un'eccezione
            if (!this.CanConvertFile(filePath))
            {
                throw new NotConvertibleFileException();
            }

            // Se il convertitore non è inizializzato, viene lanciata un'eccezione
            // In teoria questa eccezione non dovrebbe essere mai lanciata. E' stata
            // inserita per eventuali sviluppi / modifiche successive
            if (_pdfConverter == null)
            {
                throw new ConverterNotInitializedException();
            }

            // Conversione del file
            toReturn = _pdfConverter.Convert(filePath, outFilePath, recognizeText);

            // Restituzione dell'esito della conversione
            return(toReturn);
        }
        public async Task <IActionResult> ExportPdf(int id)
        {
            var          model  = _employee.GetEployeeById(id);
            PdfResultDto result = new PdfResultDto();

            result.ByteArray = await _pdfConverter.Convert("Home/__PdfRender", model);

            result.FileName = $"Employee-{model.Id}.pdf";

            return(Json(result));
        }
Пример #5
0
        /// <summary>
        /// Conversione in PDF mediante il convertitore correntemente impostato
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="outPdfFilePath"></param>
        /// <param name="recognizeText"></param>
        /// <returns></returns>
        public static bool Convert(string filePath, string outPdfFilePath, bool recognizeText)
        {
            logger.Debug(string.Format("INIT - BusinessLogic.Documenti.PdfConverter.Convert(filePath: '{0}', outPdfFilePath: '{1}', recognizeText: '{2}')",
                                       filePath, outPdfFilePath, recognizeText));

            bool retValue = false;

            try
            {
                if (CurrentMutex.WaitOne())
                {
                    // Se la conversione è attiva e se il file può essere convertito
                    if (CanConvertFile(filePath))
                    {
                        IPdfConverter converter = GetConverter();

                        if (converter != null)
                        {
                            retValue = converter.Convert(filePath, outPdfFilePath, recognizeText);
                        }
                        else
                        {
                            throw new ApplicationException("Convertitore PDF inline non istanziato, impossibile effettuare la conversione del documento");
                        }
                    }
                    else
                    {
                        logger.Debug("Conversione PDF inline non supportata per il formato del documento");
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Debug(ex);

                throw new ApplicationException("Errore nella conversione PDF inline del documento", ex);
            }
            finally
            {
                CurrentMutex.ReleaseMutex();

                if (CurrentMutex != null)
                {
                    CurrentMutex.Close();
                    _mutex = null;
                }

                logger.Debug("END - BusinessLogic.Documenti.PdfConverter.Convert");
            }

            return(retValue);
        }
Пример #6
0
        public async Task <IActionResult> Print(long id)
        {
            var order = await _orderRepository
                        .Query()
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.District)
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.StateOrProvince)
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.Country)
                        .Include(x => x.OrderItems).ThenInclude(x => x.Product)
                        .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.OptionCombinations).ThenInclude(x => x.Option)
                        .Include(x => x.CreatedBy)
                        .FirstOrDefaultAsync(x => x.Id == id);

            if (order == null)
            {
                return(NotFound());
            }

            var currentUser = await _workContext.GetCurrentUser();

            if (!User.IsInRole("admin") && order.VendorId != currentUser.VendorId)
            {
                return(BadRequest(new { error = "You don't have permission to manage this order" }));
            }

            var model = new OrderDetailVm
            {
                Id                   = order.Id,
                CreatedOn            = order.CreatedOn,
                OrderStatus          = (int)order.OrderStatus,
                OrderStatusString    = order.OrderStatus.ToString(),
                CustomerId           = order.CreatedById,
                CustomerName         = order.CreatedBy.FullName,
                CustomerEmail        = order.CreatedBy.Email,
                ShippingMethod       = order.ShippingMethod,
                PaymentMethod        = order.PaymentMethod,
                PaymentFeeAmount     = order.PaymentFeeAmount,
                Subtotal             = order.SubTotal,
                DiscountAmount       = order.DiscountAmount,
                SubTotalWithDiscount = order.SubTotalWithDiscount,
                TaxAmount            = order.TaxAmount,
                ShippingAmount       = order.ShippingFeeAmount,
                OrderTotal           = order.OrderTotal,
                ShippingAddress      = new ShippingAddressVm
                {
                    AddressLine1        = order.ShippingAddress.AddressLine1,
                    AddressLine2        = order.ShippingAddress.AddressLine2,
                    ContactName         = order.ShippingAddress.ContactName,
                    DistrictName        = order.ShippingAddress.District?.Name,
                    StateOrProvinceName = order.ShippingAddress.StateOrProvince.Name,
                    Phone = order.ShippingAddress.Phone
                },
                OrderItems = order.OrderItems.Select(x => new OrderItemVm
                {
                    Id               = x.Id,
                    ProductId        = x.Product.Id,
                    ProductName      = x.Product.Name,
                    ProductPrice     = x.ProductPrice,
                    Quantity         = x.Quantity,
                    DiscountAmount   = x.DiscountAmount,
                    TaxAmount        = x.TaxAmount,
                    TaxPercent       = x.TaxPercent,
                    VariationOptions = OrderItemVm.GetVariationOption(x.Product)
                }).ToList()
            };

            var invoiceHtml = await _viewRender.RenderViewToStringAsync("/Modules/SimplCommerce.Module.Orders/Views/Shared/InvoicePdf.cshtml", model);

            byte[] pdf = _pdfConverter.Convert(invoiceHtml);
            return(new FileContentResult(pdf, "application/pdf"));
        }