private int GetTableHeader(StringBuilder Page, ExportMatrix FMatrix, int PageNumber, int CurrentPage, int ImagesCount) { Page.Append("<table width=\""). Append(SizeValue(Math.Round(FMatrix.MaxWidth), Math.Round(FMatrix.MaxWidth), FWidthUnits)). Append("\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"table-layout: fixed;"); // add watermark if (FMatrix.Pages[0].WatermarkPictureStream != null) { string wName; if (FPrevWatermarkSize != FMatrix.Pages[0].WatermarkPictureStream.Length) { ExportIEMObject watermark = new ExportIEMObject(); watermark.Width = (FMatrix.Pages[0].Width - FMatrix.Pages[0].LeftMargin - FMatrix.Pages[0].RightMargin) * Units.Millimeters; watermark.Height = (FMatrix.Pages[0].Height - FMatrix.Pages[0].TopMargin - FMatrix.Pages[0].BottomMargin) * Units.Millimeters; watermark.PictureStream = FMatrix.Pages[0].WatermarkPictureStream; FPrevWatermarkSize = FMatrix.Pages[0].WatermarkPictureStream.Length; FPrevWatermarkName = HTMLGetImage(PageNumber, CurrentPage, ImagesCount++, watermark.Hash, watermark.Base, watermark.Metafile, watermark.PictureStream); } wName = FPrevWatermarkName; Page.Append(" background: url(").Append(wName).Append(") no-repeat;"); } if (FSinglePage && PageNumber > 1 && FPageBreaks) { Page.Append("\" class=\"page_break"); } Page.AppendLine("\" >"); return(ImagesCount); }
private string GetRTFMetafile(ExportIEMObject Obj) { byte[] picbuff = new Byte[PIC_BUFF_SIZE]; string scale = ((int)(100 / FDpiFactor)).ToString(); StringBuilder CellsStream = new StringBuilder(256); CellsStream.Append("{"); Obj.PictureStream.Position = 0; if (FPictures && Config.FullTrust && (FImageFormat == RTFImageFormat.Metafile)) { CellsStream.Append("\\sb0\\li0\\sl0\\slmult0\\qc\\clvertalc {"); float dx = Obj.Metafile.Width; float dy = Obj.Metafile.Height; CellsStream.Append("\\pict\\picw").Append(dx.ToString()); CellsStream.Append("\\pich").Append(dy.ToString()); CellsStream.Append("\\picscalex").Append(scale); CellsStream.Append("\\picscaley").Append(scale); CellsStream.Append("\\emfblip\r\n"); int n; do { n = Obj.PictureStream.Read(picbuff, 0, PIC_BUFF_SIZE); for (int z = 0; z < n; z++) { CellsStream.Append(ExportUtils.XConv[picbuff[z] >> 4]); CellsStream.Append(ExportUtils.XConv[picbuff[z] & 0xF]); } CellsStream.Append("\r\n"); }while (n == PIC_BUFF_SIZE); CellsStream.Append("}"); } else if (FPictures && (FImageFormat != RTFImageFormat.Metafile)) { CellsStream.Append("\\sb0\\li0\\sl0\\slmult0\\qc\\clvertalc {"); float dx = (int)Obj.Width; float dy = (int)Obj.Height; CellsStream.Append("\\pict\\picw").Append(dx.ToString()); CellsStream.Append("\\pich").Append(dy.ToString()); CellsStream.Append("\\picscalex").Append(scale); CellsStream.Append("\\picscaley").Append(scale); CellsStream.Append("\\"); CellsStream.Append(FImageFormat == RTFImageFormat.Jpeg ? "jpegblip\r\n" : "pngblip\r\n"); int n; do { n = Obj.PictureStream.Read(picbuff, 0, PIC_BUFF_SIZE); for (int z = 0; z < n; z++) { CellsStream.Append(ExportUtils.XConv[picbuff[z] >> 4]); CellsStream.Append(ExportUtils.XConv[picbuff[z] & 0xF]); } CellsStream.Append("\r\n"); }while (n == PIC_BUFF_SIZE); CellsStream.Append("}"); } CellsStream.Append("\\cell}\r\n"); return(CellsStream.ToString()); }
private string HTMLSaveImage(ExportIEMObject obj, int PageNumber, int CurrentPage, int ImageNumber) { if (FPictures) { return(HTMLGetImageTag(HTMLGetImage(PageNumber, CurrentPage, ImageNumber, obj.Hash, obj.Base, obj.Metafile, obj.PictureStream))); } else { return(String.Empty); } }
private int GetTable(StringBuilder Page, ExportMatrix FMatrix, int PageNumber, int CurrentPage, int ImagesCount) { for (int y = 0; y < FMatrix.Height - 1; y++) { int drow = (int)Math.Round((FMatrix.YPosById(y + 1) - FMatrix.YPosById(y))); if (drow == 0) { drow = 1; } Page.Append("<tr style=\"height:").Append(SizeValue(drow, FMatrix.MaxHeight, FHeightUnits)).AppendLine("\">"); for (int x = 0; x < FMatrix.Width - 1; x++) { int i = FMatrix.Cell(x, y); if (i != -1) { ExportIEMObject obj = FMatrix.ObjectById(i); if (obj.Counter == 0) { int fx, fy, dx, dy; FMatrix.ObjectPos(i, out fx, out fy, out dx, out dy); obj.Counter = 1; Page.Append("<td"). Append((dx > 1 ? " colspan=\"" + dx.ToString() + "\"" : String.Empty)). Append((dy > 1 ? " rowspan=\"" + dy.ToString() + "\"" : String.Empty)). Append(" class=\"").Append(FStylePrefix).Append("s").Append(obj.StyleIndex.ToString()). Append("\""); StringBuilder style = new StringBuilder(256); if (obj.Text.Length == 0) { style.Append("font-size:1px;"); } if (obj.PictureStream != null && obj.IsText) { style.Append("background-image: url("). Append(HTMLGetImage(PageNumber, CurrentPage, ImagesCount++, obj.Hash, obj.Base, obj.Metafile, obj.PictureStream)). Append(");"); } if (style.Length > 0) { Page.Append(" style=\"").Append(style).Append("\""); } Page.Append(">"); // TEXT if (obj.IsText) { if (obj.Text.Length > 0) { if (!String.IsNullOrEmpty(obj.URL)) { Page.Append("<a href=\"" + obj.URL + "\">"); } Page.Append(ExportUtils.HtmlString(obj.Text, obj.HtmlTags)); if (!String.IsNullOrEmpty(obj.URL)) { Page.Append("</a>"); } } else { Page.Append(NBSP); } } else { Page.Append(HTMLSaveImage(obj, PageNumber, CurrentPage, ImagesCount++)); } Page.AppendLine("</td>"); } } else { Page.AppendLine("</td>"); } } Page.AppendLine("</tr>"); } return(ImagesCount); }
private void ExportODF(Stream stream) { string s; int fx, fy, dx, dy, Page; string FTempFolder = Path.GetTempPath() + Path.GetRandomFileName(); Directory.CreateDirectory(FTempFolder); Directory.CreateDirectory(FTempFolder + "\\Pictures"); Directory.CreateDirectory(FTempFolder + "\\Thumbnails"); Directory.CreateDirectory(FTempFolder + "\\META-INF"); int PicCount = 0; Page = 0; OdfMakeDocStyles(FTempFolder + "\\styles.xml"); #region Content.xml using (FileStream file = new FileStream(FTempFolder + "\\content.xml", FileMode.Create)) using (StreamWriter Out = new StreamWriter(file)) { Out.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); Out.Write("<office:document-content "); Out.Write(OdfMakeXmlHeader()); Out.WriteLine(">"); Out.WriteLine("<office:scripts/>"); ExportIEMStyle Style; OdfFontFaceDecals(Out); Out.WriteLine("<office:automatic-styles>"); OdfColumnStyles(Out); OdfRowStyles(Out); for (int i = 0; i < FMatrix.StylesCount; i++) { Style = FMatrix.StyleById(i); Out.WriteLine("<style:style style:name=\"ce" + i.ToString() + "\" " + "style:family=\"table-cell\" style:parent-style-name=\"Default\">"); if (FExportType == 0) { Out.Write("<style:text-properties style:font-name=\"" + Style.Font.Name + "\" " + "fo:font-size=\"" + ExportUtils.FloatToString(Style.Font.Size) + "pt\" "); if ((Style.Font.Style & FontStyle.Underline) > 0) { Out.Write("style:text-underline-style=\"solid\" " + "style:text-underline-width=\"auto\" " + "style:text-underline-color=\"font-color\" "); } if ((Style.Font.Style & FontStyle.Italic) > 0) { Out.Write("fo:font-style=\"italic\" "); } if ((Style.Font.Style & FontStyle.Bold) > 0) { Out.Write("fo:font-weight=\"bold\" "); } Out.Write("fo:color=\"" + ExportUtils.HTMLColor(Style.TextColor) + "\""); Out.WriteLine("/>"); Out.Write("<style:paragraph-properties "); if (Style.HAlign == HorzAlign.Left) { Out.Write("fo:text-align=\"start\" "); } if (Style.HAlign == HorzAlign.Center) { Out.Write("fo:text-align=\"center\" "); } if (Style.HAlign == HorzAlign.Right) { Out.Write("fo:text-align=\"end\" "); } if (Style.Padding.Left > 0) { Out.Write("fo:margin-left=\"" + ExportUtils.FloatToString(Style.Padding.Left / odfDivider) + "cm\" "); } if (Style.Padding.Right > 0) { Out.Write("fo:margin-right=\"" + ExportUtils.FloatToString(Style.Padding.Right / odfDivider) + "cm\" "); } if (Style.Padding.Top > 0) { Out.Write("fo:margin-top=\"" + ExportUtils.FloatToString(Style.Padding.Top / odfDivider) + "cm\" "); } if (Style.Padding.Bottom > 0) { Out.Write("fo:margin-bottom=\"" + ExportUtils.FloatToString(Style.Padding.Bottom / odfDivider) + "cm\" "); } Out.WriteLine("/>"); } OdfTableCellStyles(Style, Out); } if (FExportType == 1) { Out.WriteLine("<style:style style:name=\"pb\" " + "style:family=\"paragraph\" style:display=\"false\"/>"); for (int i = 0; i < FMatrix.StylesCount; i++) { Style = FMatrix.StyleById(i); Out.WriteLine("<style:style style:name=\"p" + i.ToString() + "\" " + "style:family=\"paragraph\" style:parent-style-name=\"Default\">"); Out.Write("<style:text-properties style:font-name=\"" + Style.Font.Name + "\" fo:font-size=\"" + ExportUtils.FloatToString(Style.Font.Size) + "pt\" "); if ((Style.Font.Style & FontStyle.Underline) > 0) { Out.Write(" style:text-underline-style=\"solid\" " + "style:text-underline-width=\"auto\" " + "style:text-underline-color=\"font-color\" "); } if ((Style.Font.Style & FontStyle.Italic) > 0) { Out.Write(" style:font-style=\"italic\" "); } if ((Style.Font.Style & FontStyle.Bold) > 0) { Out.Write(" style:font-weight=\"bold\" "); } Out.WriteLine(" fo:color=\"" + ExportUtils.HTMLColor(Style.TextColor) + "\"/>"); Out.Write("<style:paragraph-properties "); if (Style.HAlign == HorzAlign.Left) { Out.Write("fo:text-align=\"start\" "); } if (Style.HAlign == HorzAlign.Center) { Out.Write("fo:text-align=\"center\" "); } if (Style.HAlign == HorzAlign.Right) { Out.Write("fo:text-align=\"end\" "); } if (Style.Padding.Left > 0) { Out.Write("fo:margin-left=\"" + ExportUtils.FloatToString(Style.Padding.Left / odfDivider) + "cm\" "); } if (Style.Padding.Right > 0) { Out.Write("fo:margin-right=\"" + ExportUtils.FloatToString(Style.Padding.Right / odfDivider) + "cm\" "); } if (Style.Padding.Top > 0) { Out.Write("fo:margin-top=\"" + ExportUtils.FloatToString(Style.Padding.Top / odfDivider) + "cm\" "); } if (Style.Padding.Bottom > 0) { Out.Write("fo:margin-bottom=\"" + ExportUtils.FloatToString(Style.Padding.Bottom / odfDivider) + "cm\" "); } Out.WriteLine("/>"); Out.WriteLine("</style:style>"); } } Out.WriteLine("<style:style style:name=\"gr1\" style:family=\"graphic\">"); Out.WriteLine("<style:graphic-properties draw:stroke=\"none\" " + "draw:fill=\"none\" draw:textarea-horizontal-align=\"left\" " + "draw:textarea-vertical-align=\"top\" draw:color-mode=\"standard\" " + "draw:luminance=\"0%\" draw:contrast=\"0%\" draw:gamma=\"100%\" " + "draw:red=\"0%\" draw:green=\"0%\" draw:blue=\"0%\" " + "fo:clip=\"rect(0cm 0cm 0cm 0cm)\" draw:image-opacity=\"100%\" " + "style:mirror=\"none\"/>"); Out.WriteLine("</style:style>"); Out.WriteLine("</office:automatic-styles>"); // body Out.WriteLine("<office:body>"); Out.WriteLine("<office:spreadsheet>"); Out.WriteLine("<table:table table:name=\"Table\" table:style-name=\"ta1\" table:print=\"false\">"); for (int x = 1; x < FMatrix.Width; x++) { Out.WriteLine("<table:table-column table:style-name=\"co" + ExportUtils.FloatToString((FMatrix.XPosById(x) - FMatrix.XPosById(x - 1)) / odfDivider) + "\"/>"); } for (int y = 0; y < FMatrix.Height - 1; y++) { Out.WriteLine("<table:table-row table:style-name=\"ro" + ExportUtils.FloatToString((FMatrix.YPosById(y + 1) - FMatrix.YPosById(y)) / odfDivider) + "\">"); if (FMatrix.YPosById(y) >= FMatrix.PageBreak(Page)) { Page++; if (FPageBreaks) { Out.WriteLine("<table:table-row table:style-name=\"ro_breaked\"/>"); } } for (int x = 0; x < FMatrix.Width; x++) { int i = FMatrix.Cell(x, y); if (i != -1) { ExportIEMObject Obj = FMatrix.ObjectById(i); if (Obj.Counter == 0) { Obj.Counter = 1; FMatrix.ObjectPos(i, out fx, out fy, out dx, out dy); Out.Write("<table:table-cell table:style-name=\"ce" + Obj.StyleIndex.ToString() + "\" "); if (dx > 1) { Out.Write("table:number-columns-spanned=\"" + dx.ToString() + "\" "); } if (dy > 1) { Out.Write("table:number-rows-spanned=\"" + dy.ToString() + "\" "); } Out.WriteLine(">"); if (Obj.IsText) { s = ExportUtils.XmlString(Obj.Text, Obj.HtmlTags); Out.Write("<text:p"); if (FExportType == 1) { Out.Write(" text:style-name=\"p" + Obj.StyleIndex.ToString() + "\""); } Out.WriteLine(">" + s + "</text:p>"); } else { if (Obj.Width > 0) { PicCount++; if (Config.FullTrust) { using (FileStream emfFile = new FileStream(FTempFolder + "\\Pictures\\pic" + PicCount.ToString() + ".emf", FileMode.Create)) emfFile.Write(Obj.PictureStream.ToArray(), 0, (int)Obj.PictureStream.Length); } else { using (FileStream pngFile = new FileStream(FTempFolder + "\\Pictures\\pic" + PicCount.ToString() + ".png", FileMode.Create)) pngFile.Write(Obj.PictureStream.ToArray(), 0, (int)Obj.PictureStream.Length); } if (FExportType == 1) { Out.WriteLine("<text:p>"); } // need for fix of vertical position Out.WriteLine("<draw:frame draw:z-index=\"" + (PicCount - 1).ToString() + "\" " + "draw:name=\"Pictures" + PicCount.ToString() + "\" " + "draw:style-name=\"gr1\" " + "draw:text-style-name=\"P1\" " + "svg:width=\"" + ExportUtils.FloatToString(Obj.Width / odfDivider) + "cm\" " + "svg:height=\"" + ExportUtils.FloatToString(Obj.Height / odfDivider) + "cm\" " + "svg:x=\"0cm\" svg:y=\"0cm\">"); s = Config.FullTrust ? ".emf" : ".png"; Out.WriteLine("<draw:image " + "xlink:href=\"Pictures/pic" + PicCount.ToString() + s + "\" " + "text:anchor-type=\"frame\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>"); Out.WriteLine("</draw:frame>"); if (FExportType == 1) { Out.WriteLine("</text:p>"); } } } Out.WriteLine("</table:table-cell>"); } else { Out.Write("<table:covered-table-cell table:style-name=\"ceb\""); if (FExportType == 1) { Out.WriteLine("><text:p text:style-name=\"pb\"/></table:covered-table-cell>"); } else { Out.WriteLine("/>"); } } } else { Out.Write("<table:table-cell"); if (FExportType == 1) { Out.WriteLine("><text:p text:style-name=\"pb\"/></table:table-cell>"); } else { Out.WriteLine("/>"); } } } Out.WriteLine("</table:table-row>"); } Out.WriteLine("</table:table>"); Out.WriteLine("</office:spreadsheet>"); Out.WriteLine("</office:body>"); Out.WriteLine("</office:document-content>"); } #endregion string ExportMime = FExportType == 0 ? "spreadsheet" : "text"; OdfCreateManifest(FTempFolder + "\\META-INF\\manifest.xml", PicCount, ExportMime); OdfCreateMime(FTempFolder + "\\mimetype", ExportMime); OdfCreateMeta(FTempFolder + "\\meta.xml", Creator); ZipArchive zip = new ZipArchive(); zip.AddDir(FTempFolder); zip.SaveToStream(Stream); Directory.Delete(FTempFolder, true); }