コード例 #1
0
        public byte[] ConvertXmlToPdfWithStylesheet(byte[] documentContent, byte[] xsltContent, string fileName, string label)
        {
            logger.DebugFormat("ConvertXmlToPdfWithStylesheet {0} ({1}) {2}", fileName, PathUtil.EXTENSIONPDF, label);
            string xslt = Encoding.UTF8.GetString(xsltContent);

            if (!_xmlToHtmlConverter.IsDocumentProcessable(fileName.ToPath().GetExtension()))
            {
                return(new byte[] { });
            }

            string originalFileName = fileName;

            if (!ConfigurationHelper.GetValueOrDefault <bool>("CompliantPrinting.DisableDSW7Compliant", false))
            {
                if (!originalFileName.ToPath().HasExtension())
                {
                    originalFileName = PathUtil.UNDEFINEDFILENAME.ToPath().ChangeExtension("." + originalFileName);
                }
            }
            byte[] convertedDocument = ConvertToPdf(documentContent, xslt, PathUtil.EXTENSIONPDF, originalFileName, out bool isEncrypted);
            if (!isEncrypted)
            {
                return(AddLabelToConvertedDocument(PathUtil.EXTENSIONPDF, label, null, convertedDocument, documentContent));
            }
            return(convertedDocument);
        }
コード例 #2
0
        private static PdfContentInfo ConvertByExternalConverter(IContent contentInfo, CompliantTransformer tx)
        {
            byte[]      pdfContent = null;
            ContentInfo content    = null;
            string      extension  = String.Empty;

            XmlToHtmlConverter xmlToHtmlConverter = new XmlToHtmlConverter();

            byte[] htmlConversion = null;
            if (xmlToHtmlConverter.IsDocumentProcessable(contentInfo.Extension))
            {
                if (!string.IsNullOrEmpty(tx.CustomStyleContent))
                {
                    htmlConversion = xmlToHtmlConverter.Convert(contentInfo.Content, tx.CustomStyleContent, contentInfo.Extension, PathUtil.EXTENSIONPDF, false);
                }
                else
                {
                    htmlConversion = xmlToHtmlConverter.Convert(contentInfo.Content, contentInfo.Extension, PathUtil.EXTENSIONPDF, AttachConversionMode.Default);
                }
            }
            // salvataggio del contenuto in html
            if (htmlConversion != null)
            {
                extension = ".html";
                string filename = contentInfo.FileName.Replace(contentInfo.Extension, extension);
                content = new ContentInfo(filename, htmlConversion);
            }
            else
            {
                extension = contentInfo.Extension;
                content   = new ContentInfo(contentInfo.FileName, contentInfo.Content);
            }

            var converter = PrintRedirectConfigurations.GetConverter(extension);

            switch (converter)
            {
            case ConverterType.OpenOffice:
            case ConverterType.Redirect:
                pdfContent = new ExternalRedirectService().Convert(content.Content, content.FileName, "pdf", converter, tx.AttachConversionMode);
                if (pdfContent.IsNullOrEmpty())
                {
                    converter  = converter == ConverterType.OpenOffice ? ConverterType.Redirect : ConverterType.OpenOffice;
                    pdfContent = new ExternalRedirectService().Convert(content.Content, content.FileName, "pdf", converter, tx.AttachConversionMode);
                }
                break;

            case ConverterType.Tif:
                pdfContent = new TifToPdfConverter().Convert(content.Content, content.FileName, "pdf", tx.AttachConversionMode);
                break;

            case ConverterType.Image:
                pdfContent = new ImageToPdfConverter().Convert(content.Content, content.FileName, "pdf", tx.AttachConversionMode);
                break;

            case ConverterType.Txt:
            {
                pdfContent = new TxtToPdfConverter().Convert(content.Content, content.FileName, "pdf", tx.AttachConversionMode);
            }
            break;

            default:
                throw new FormatException("CompliantPrintingHelper.ConvertByExternalConverter: formato non supportato.");
            }

            if (pdfContent.IsNullOrEmpty())
            {
                throw new InvalidOperationException("CompliantPrintingHelper.ConvertByExternalConverter: conversione fallita.");
            }

            return(new PdfContentInfo(content.FileName, pdfContent));
        }