示例#1
0
        public static string ToHTML(string fBase64, string nomeoriginal)
        {
            using (var doc = new Spire.Doc.Document())
            {
                using (Stream stream = new MemoryStream(Convert.FromBase64String(fBase64)))
                {
                    doc.LoadFromStream(stream, Path.GetExtension(nomeoriginal).ToUpper().Contains("DOCX") ? Spire.Doc.FileFormat.Docx : Spire.Doc.FileFormat.Doc);
                    doc.HtmlExportOptions.ImageEmbedded              = true;
                    doc.HtmlExportOptions.IsExportDocumentStyles     = false;
                    doc.HtmlExportOptions.CssStyleSheetType          = Spire.Doc.CssStyleSheetType.Internal;
                    doc.HtmlExportOptions.HasHeadersFooters          = false;
                    doc.HtmlExportOptions.IsTextInputFormFieldAsText = true;

                    var outstr = new MemoryStream();
                    doc.SaveToStream(outstr, Spire.Doc.FileFormat.Html);
                    var rethtml = Encoding.GetEncoding("utf-8").GetString(outstr.ToArray()); //basicamente funciona com HTML

                    return(rethtml);
                }
            }
        }
示例#2
0
        private MemoryStream PrepareCommonOrderPrintData(IOrdersManager ordersManager, int id, string path, PrintTypes type,
            IInvoicesManager invoicesManager, ITaxesManager taxesManager, IInvoiceStornosManager invoiceStornosManager = null,
            ITransportOrdersManager transportOrdersManager = null,
            ITermsManager termsManager = null)
        {
            var result = new MemoryStream();
            try
            {
                Package pkg;
                PackagePart part;
                XmlReader xmlReader;
                XDocument xmlMainXMLDoc;
                GetXmlDoc(path, result, out pkg, out part, out xmlReader, out xmlMainXMLDoc);


                var images = new List<Image>();

                if (type == PrintTypes.DeliveryNote)
                {
                    var term = termsManager.GetById(id);
                    for (var i = 0; i < term.DeliveryNoteSignatures.Count; i++)
                    {
                        var deliveryNoteSignature = term.DeliveryNoteSignatures.ElementAt(term.DeliveryNoteSignatures.Count - i - 1);
                        //TODO doesnt work ((
                        //pkg.CreateRelationship(uri, TargetMode.Internal,
                        //    "Http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
                        //    "barcodeImageId");


                        byte[] bytes = Convert.FromBase64String(deliveryNoteSignature.Signature.Replace("data:image/png;base64,", ""));

                        Image image;
                        using (MemoryStream ms = new MemoryStream(bytes))
                        {
                            image = Image.FromStream(ms);
                        }

                        images.Add(image);
                    }
                }

                //replace fields
                var templateBody = ReplaceFields(ordersManager, id, type, xmlMainXMLDoc.Root.ToString(),
                    invoicesManager, taxesManager, null, invoiceStornosManager, transportOrdersManager, termsManager, images);

                xmlMainXMLDoc = SaveDoc(result, pkg, part, xmlReader, xmlMainXMLDoc, templateBody);

                InsertImages(result, images);

                var doc = new Spire.Doc.Document();
                doc.LoadFromStream(result, Spire.Doc.FileFormat.Docx);
                doc.JPEGQuality = 100;

                result = new MemoryStream();
                doc.SaveToStream(result, Spire.Doc.FileFormat.PDF);
            }
            catch
            {
            }

            return result;
        }