private void WriteMimePart(Stream stream, string mimetype, string charset, string filename) { StringBuilder sb = new StringBuilder(); sb.Append("--").AppendLine(FBoundary); sb.Append("Content-Type: ").Append(mimetype).Append(";"); if (charset != String.Empty) { sb.Append(" charset=\"").Append(charset).AppendLine("\""); } else { sb.AppendLine(); } string body; byte[] buff = new byte[stream.Length]; stream.Position = 0; stream.Read(buff, 0, buff.Length); if (mimetype == "text/html") { sb.AppendLine("Content-Transfer-Encoding: quoted-printable"); body = ExportUtils.QuotedPrintable(buff); } else { sb.AppendLine("Content-Transfer-Encoding: base64"); body = System.Convert.ToBase64String(buff, Base64FormattingOptions.InsertLineBreaks); } sb.Append("Content-Location: ").AppendLine(ExportUtils.HtmlURL(filename)); sb.AppendLine(); sb.AppendLine(body); sb.AppendLine(); Stream.Write(Encoding.ASCII.GetBytes(sb.ToString()), 0, sb.Length); }
private void ExportHTMLIndex(Stream stream) { ExportUtils.Write(stream, String.Format(templates.IndexTemplate, new object[] { documentTitle, ExportUtils.HtmlURL(navFileName), ExportUtils.HtmlURL(targetFileName + (singlePage ? ".main" : "1") + ".html") })); }
private string EncodeURL(string value) { #if NETSTANDARD2_0 return(System.Net.WebUtility.UrlEncode(value)); #else return(ExportUtils.HtmlURL(value)); #endif }
private void ExportHTMLIndex(Stream Stream) { using (StreamWriter Out = new StreamWriter(Stream)) Out.Write(String.Format(FTemplates.IndexTemplate, new object[] { FDocumentTitle, ExportUtils.HtmlURL(FNavFileName), ExportUtils.HtmlURL(FTargetFileName + (FSinglePage ? ".main" : "1") + ".html") })); }
private void ExportHTMLNavigator(Stream stream) { string prefix = ExportUtils.HtmlURL(fileName); // {0} - pages count {1} - name of report {2} multipage document {3} prefix of pages // {4} first caption {5} previous caption {6} next caption {7} last caption // {8} total caption ExportUtils.Write(stream, String.Format(templates.NavigatorTemplate, new object[] { pagesCount.ToString(), documentTitle, (singlePage ? "0" : "1"), prefix, res.Get("First"), res.Get("Prev"), res.Get("Next"), res.Get("Last"), res.Get("Total") })); }
private void ExportHTMLNavigator(FileStream OutStream) { using (StreamWriter Out = new StreamWriter(OutStream)) { // {0} - pages count {1} - name of report {2} multipage document {3} prefix of pages // {4} first caption {5} previous caption {6} next caption {7} last caption // {8} total caption Out.Write(String.Format(FTemplates.NavigatorTemplate, new object[] { FPagesCount.ToString(), FDocumentTitle, (FSinglePage ? "0" : "1"), ExportUtils.HtmlURL(FFileName), Res.Get("First"), Res.Get("Prev"), Res.Get("Next"), Res.Get("Last"), Res.Get("Total") })); } }
private string HTMLGetImage(int PageNumber, int CurrentPage, int ImageNumber, string hash, bool Base, System.Drawing.Image Metafile, MemoryStream PictureStream, bool isSvg) { if (pictures) { System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Bmp; if (imageFormat == ImageFormat.Png) { format = System.Drawing.Imaging.ImageFormat.Png; } else if (imageFormat == ImageFormat.Jpeg) { format = System.Drawing.Imaging.ImageFormat.Jpeg; } else if (imageFormat == ImageFormat.Gif) { format = System.Drawing.Imaging.ImageFormat.Gif; } string formatNm = isSvg ? "svg" : format.ToString().ToLower(); string embedImgType = isSvg ? "svg+xml" : format.ToString(); string embedPreffix = "data:image/" + embedImgType + ";base64,"; FastString ImageFileNameBuilder = new FastString(48); string ImageFileName; if (!saveStreams) { ImageFileNameBuilder.Append(Path.GetFileName(targetFileName)).Append("."); } ImageFileNameBuilder.Append(hash). Append(".").Append(formatNm); ImageFileName = ImageFileNameBuilder.ToString(); if (!webMode && !(preview || print)) { if (Base) { if (Metafile != null && !EmbedPictures) { if (saveStreams) { MemoryStream ImageFileStream = new MemoryStream(); Metafile.Save(ImageFileStream, format); GeneratedUpdate(targetPath + ImageFileName, ImageFileStream); } else { using (FileStream ImageFileStream = new FileStream(targetPath + ImageFileName, FileMode.Create)) Metafile.Save(ImageFileStream, format); } } else if (PictureStream != null && !EmbedPictures) { if (this.format == HTMLExportFormat.HTML) { string fileName = targetPath + ImageFileName; FileInfo info = new FileInfo(fileName); if (!(info.Exists && info.Length == PictureStream.Length)) { if (saveStreams) { GeneratedUpdate(targetPath + ImageFileName, PictureStream); } else { using (FileStream ImageFileStream = new FileStream(fileName, FileMode.Create)) PictureStream.WriteTo(ImageFileStream); } } } else { PicsArchiveItem item; item.FileName = ImageFileName; item.Stream = PictureStream; bool founded = false; for (int i = 0; i < picsArchive.Count; i++) { if (item.FileName == picsArchive[i].FileName) { founded = true; break; } } if (!founded) { picsArchive.Add(item); } } } if (!saveStreams) { GeneratedFiles.Add(targetPath + ImageFileName); } } if (EmbedPictures && PictureStream != null) { return(embedPreffix + GetBase64Image(PictureStream, hash)); } else if (subFolder && singlePage && !navigator) { return(ExportUtils.HtmlURL(subFolderPath + ImageFileName)); } else { return(ExportUtils.HtmlURL(ImageFileName)); } } else { if (EmbedPictures) { return(embedPreffix + GetBase64Image(PictureStream, hash)); } else { if (print || preview) { printPageData.Pictures.Add(PictureStream); printPageData.Guids.Add(hash); } else if (Base) { pages[CurrentPage].Pictures.Add(PictureStream); pages[CurrentPage].Guids.Add(hash); } return(webImagePrefix + "=" + hash + webImageSuffix); } } } else { return(String.Empty); } }
private string HTMLGetImage(int PageNumber, int CurrentPage, int ImageNumber, string hash, bool Base, System.Drawing.Image Metafile, MemoryStream PictureStream) { if (FPictures) { System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Bmp; if (FImageFormat == ImageFormat.Png) { format = System.Drawing.Imaging.ImageFormat.Png; } else if (FImageFormat == ImageFormat.Jpeg) { format = System.Drawing.Imaging.ImageFormat.Jpeg; } else if (FImageFormat == ImageFormat.Gif) { format = System.Drawing.Imaging.ImageFormat.Gif; } StringBuilder ImageFileNameBuilder = new StringBuilder(48); string ImageFileName = ImageFileNameBuilder.Append(Path.GetFileName(FTargetFileName)). Append(".").Append(hash). Append(".").Append(format.ToString().ToLower()).ToString(); if (!FWebMode) { if (Base) { if (Metafile != null) { using (FileStream ImageFileStream = new FileStream(FTargetPath + ImageFileName, FileMode.Create)) Metafile.Save(ImageFileStream, format); } else if (PictureStream != null) { if (FFormat == HTMLExportFormat.HTML) { string fileName = FTargetPath + ImageFileName; FileInfo info = new FileInfo(fileName); if (!(info.Exists && info.Length == PictureStream.Length)) { using (FileStream ImageFileStream = new FileStream(fileName, FileMode.Create)) PictureStream.WriteTo(ImageFileStream); } } else { PicsArchiveItem item; item.FileName = ImageFileName; item.Stream = PictureStream; bool founded = false; for (int i = 0; i < FPicsArchive.Count; i++) { if (item.FileName == FPicsArchive[i].FileName) { founded = true; break; } } if (!founded) { FPicsArchive.Add(item); } } } GeneratedFiles.Add(FTargetPath + ImageFileName); } if (FSubFolder && FSinglePage && !FNavigator) { return(ExportUtils.HtmlURL(FSubFolderPath + ImageFileName)); } else { return(ExportUtils.HtmlURL(ImageFileName)); } } else { if (Base) { FPages[CurrentPage].Pictures.Add(PictureStream); FPages[CurrentPage].Guids.Add(hash); } return(FWebImagePrefix + "=" + hash); } } else { return(String.Empty); } }