public void DrawTextBox() { //New TextDocument TextDocument textdocument = new TextDocument(); textdocument.New(); //Standard Paragraph Paragraph paragraphOuter = new Paragraph(textdocument, ParentStyles.Standard.ToString()); //Create Frame for DrawTextBox Frame frameOuter = new Frame(textdocument, "frame1"); //Create DrawTextBox DrawTextBox drawTextBox = new DrawTextBox(textdocument); //Create a paragraph for the drawing frame Paragraph paragraphInner = new Paragraph(textdocument, ParentStyles.Standard.ToString()); //Create the frame with the Illustration resp. Graphic Frame frameIllustration = new Frame(textdocument, "frame2", "graphic1", _imagefile); //Add Illustration frame to the inner Paragraph paragraphInner.Content.Add(frameIllustration); //Add inner Paragraph to the DrawTextBox drawTextBox.Content.Add(paragraphInner); //Add the DrawTextBox to the outer Frame frameOuter.Content.Add(drawTextBox); //Add the outer Frame to the outer Paragraph paragraphOuter.Content.Add(frameOuter); //Add the outer Paragraph to the TextDocument textdocument.Content.Add(paragraphOuter); //Save the document textdocument.SaveTo(_framefile2); }
/// <summary> /// Scales the pdf image if nessarry by percent. /// </summary> /// <param name="img">The img.</param> /// <param name="frame">The frame.</param> /// <returns>The scaled image.</returns> private iTextSharp.text.Image ScaleIfNessarry(iTextSharp.text.Image img, Frame frame) { try { double scalingPrescision = 0.25; double scaledWidthPercent = 0; double scaledHeightPercent = 0; double odfScaledWidth = AODL.Document.Helper.SizeConverter.GetDoubleFromAnOfficeSizeValue(frame.SvgWidth); double odfScaledHeight = AODL.Document.Helper.SizeConverter.GetDoubleFromAnOfficeSizeValue(frame.SvgHeight); if ((frame.Height - odfScaledHeight) > scalingPrescision || (frame.Height - odfScaledHeight) < scalingPrescision) { scaledHeightPercent = ((100.0/frame.Height) * odfScaledHeight); Console.WriteLine("ScaledHeightPerc {0} , frame {1}, odfScaledHeight {2}", scaledHeightPercent, frame.Height, odfScaledHeight); } if ((frame.Width - odfScaledWidth) > scalingPrescision || (frame.Width - odfScaledWidth) < scalingPrescision) { scaledWidthPercent = ((100.0/frame.Width) * odfScaledWidth); } if (scaledHeightPercent != 0 || scaledWidthPercent != 0) { img.ScalePercent((float) scaledWidthPercent, (float) scaledHeightPercent); } return img; } catch(Exception) { throw; } }
/// <summary> /// Initializes a new instance of the <see cref="Graphic"/> class. /// </summary> /// <param name="document">The document.</param> /// <param name="frame">The frame.</param> /// <param name="graphiclink">The graphiclink.</param> public Graphic(IDocument document, Frame frame, string graphiclink) { this.Frame = frame; this.Document = document; this.GraphicFileName = graphiclink; this.NewXmlNode("Pictures/"+graphiclink); this.InitStandards(); this.Document.Graphics.Add(this); this.Document.DocumentMetadata.ImageCount += 1; }
public void GraphicsTest() { TextDocument textdocument = new TextDocument(); textdocument.New(); Paragraph p = ParagraphBuilder.CreateStandardTextParagraph(textdocument); Frame frame = new Frame(textdocument, "frame1", "graphic1", _imagefile); p.Content.Add(frame); textdocument.Content.Add(p); textdocument.SaveTo(AARunMeFirstAndOnce.outPutFolder+"grapic.odt"); }
/// <summary> /// Converts the specified frame into an PDF paragraph. /// </summary> /// <param name="frame">The frame.</param> /// <returns>The paragraph representing the passed frame.</returns> public iTextSharp.text.Paragraph Convert(Frame frame) { try { iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph(); foreach(iTextSharp.text.IElement pdfElement in MixedContentConverter.GetMixedPdfContent(frame.Content)) { paragraph.Add(pdfElement); } return paragraph; } catch(Exception) { throw; } }
public void Add2GraphicsWithSameNameFromDifferentLocations() { string file1 = _imagefile; //@"E:\fotos\schnee.jpg"; string file2 = _imagefile; //@"E:\fotos\resize\schnee.jpg"; TextDocument textdocument = new TextDocument(); textdocument.New(); Paragraph p = ParagraphBuilder.CreateStandardTextParagraph(textdocument); Frame frame = new Frame(textdocument, "frame1", "graphic1", file1); p.Content.Add(frame); Paragraph p1 = ParagraphBuilder.CreateStandardTextParagraph(textdocument); Frame frame1 = new Frame(textdocument, "frame2", "graphic2", file2); p1.Content.Add(frame1); textdocument.Content.Add(p); textdocument.Content.Add(p1); textdocument.SaveTo(AARunMeFirstAndOnce.outPutFolder+"graphic.odt"); }
/// <summary> /// Builds the illustration frame. /// </summary> /// <param name="document">The document.</param> /// <param name="frameStyleName">Name of the frame style.</param> /// <param name="graphicName">Name of the graphic.</param> /// <param name="pathToGraphic">The path to graphic.</param> /// <param name="illustrationText">The illustration text.</param> /// <param name="illustrationNumber">The illustration number.</param> /// <returns> /// A new Frame object containing a DrawTextBox which contains the /// illustration Graphic object and a text sequence representing /// the displayed illustration text. /// </returns> public static Frame BuildIllustrationFrame(IDocument document, string frameStyleName, string graphicName, string pathToGraphic, string illustrationText, int illustrationNumber) { DrawTextBox drawTextBox = new DrawTextBox(document); Frame frameTextBox = new Frame(document, frameStyleName); frameTextBox.DrawName = frameStyleName+"_"+graphicName; frameTextBox.ZIndex = "0"; Paragraph pIllustration = ParagraphBuilder.CreateStandardTextParagraph(document); pIllustration.StyleName = "Illustration"; Frame frame = new Frame(document, "InnerFrame_"+frameStyleName, graphicName, pathToGraphic); frame.ZIndex = "1"; pIllustration.Content.Add(frame); //add Illustration as text pIllustration.TextContent.Add(new SimpleText(document, "Illustration")); //add TextSequence TextSequence textSequence = new TextSequence(document); textSequence.Name = "Illustration"; textSequence.NumFormat = "1"; textSequence.RefName = "refIllustration"+illustrationNumber.ToString(); textSequence.Formula = "ooow:Illustration+1"; textSequence.TextContent.Add(new SimpleText(document, illustrationNumber.ToString())); pIllustration.TextContent.Add(textSequence); //add the ilustration text pIllustration.TextContent.Add(new SimpleText(document, illustrationText)); //add the Paragraph to the DrawTextBox drawTextBox.Content.Add(pIllustration); frameTextBox.SvgWidth = frame.SvgWidth; drawTextBox.MinWidth = frame.SvgWidth; drawTextBox.MinHeight = frame.SvgHeight; frameTextBox.Content.Add(drawTextBox); return frameTextBox; }
/// <summary> /// Sets the image properties. /// </summary> /// <param name="image">The image.</param> /// <param name="graphic">The graphic.</param> /// <returns>The pdf image with the converted odf graphic properties.</returns> private iTextSharp.text.Image SetImageProperties(iTextSharp.text.Image image, Frame frame) { try { if (frame.Style is FrameStyle) { if (((FrameStyle)frame.Style).GraphicProperties != null) { if (((FrameStyle)frame.Style).GraphicProperties.HorizontalPosition != null) { string pos = ((FrameStyle)frame.Style).GraphicProperties.HorizontalPosition; switch(pos) { case "center": image.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_CENTER; break; case "left": image.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_LEFT; break; case "right": image.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_RIGHT; break; default: break; } } if (((FrameStyle)frame.Style).GraphicProperties.MarginLeft != null) { string marginLeft = ((FrameStyle)frame.Style).GraphicProperties.MarginLeft; if (marginLeft != null) { double mLeft = AODL.Document.Helper.SizeConverter.GetDoubleFromAnOfficeSizeValue(marginLeft); if (AODL.Document.Helper.SizeConverter.IsCm(marginLeft)) { int pLeft = MeasurementHelper.CmToPoints(mLeft); image.IndentationLeft = (float) pLeft; } else { int pLeft = MeasurementHelper.CmToPoints(mLeft); image.IndentationLeft = (float) pLeft; } } } if (((FrameStyle)frame.Style).GraphicProperties.MarginRight != null) { string marginRight = ((FrameStyle)frame.Style).GraphicProperties.MarginRight; if (marginRight != null) { double mRight = AODL.Document.Helper.SizeConverter.GetDoubleFromAnOfficeSizeValue(marginRight); if (AODL.Document.Helper.SizeConverter.IsCm(marginRight)) { int pRight = MeasurementHelper.CmToPoints(mRight); image.IndentationRight = (float) pRight; } else { int pRight = MeasurementHelper.InchToPoints(mRight); image.IndentationRight = (float) pRight; } } } } } return image; } catch(Exception) { throw; } }
private void LoadFrameGraphic(Frame frame, Graphic content) { try { string graphicRealPath = Path.GetFullPath(content.GraphicRealPath); frame.LoadImageFromFile(graphicRealPath); } catch (AODLGraphicException e) { this.OnWarning( new AODLWarning("A couldn't create any content from an an first level node!.", content.Node, e)); } }
/// <summary> /// Creates the frame. /// </summary> /// <param name="frameNode">The framenode.</param> /// <returns>The Frame object.</returns> public Frame CreateFrame(XmlNode frameNode) { try { #region Old code Todo: delete // Frame frame = null; // XmlNode graphicnode = null; // XmlNode graphicproperties = null; // string realgraphicname = ""; // string stylename = ""; // stylename = this.GetStyleName(framenode.OuterXml); // XmlNode stylenode = this.GetAStyleNode("style:style", stylename); // realgraphicname = this.GetAValueFromAnAttribute(framenode, "@draw:name"); // // //Console.WriteLine("frame: {0}", framenode.OuterXml); // // //Up to now, the only sopported, inner content of a frame is a graphic // if (framenode.ChildNodes.Count > 0) // if (framenode.ChildNodes.Item(0).OuterXml.StartsWith("<draw:image")) // graphicnode = framenode.ChildNodes.Item(0).CloneNode(true); // // //If not graphic, it could be text-box, ole or something else // //try to find graphic frame inside // if (graphicnode == null) // { // XmlNode child = framenode.SelectSingleNode("//draw:frame", this._document.NamespaceManager); // if (child != null) // frame = this.CreateFrame(child); // return frame; // } // // string graphicpath = this.GetAValueFromAnAttribute(graphicnode, "@xlink:href"); // // if (stylenode != null) // if (stylenode.ChildNodes.Count > 0) // if (stylenode.ChildNodes.Item(0).OuterXml.StartsWith("<style:graphic-properties")) // graphicproperties = stylenode.ChildNodes.Item(0).CloneNode(true); // // if (stylename.Length > 0 && stylenode != null && realgraphicname.Length > 0 // && graphicnode != null && graphicpath.Length > 0 && graphicproperties != null) // { // graphicpath = graphicpath.Replace("Pictures", ""); // graphicpath = OpenDocumentTextImporter.dirpics+graphicpath.Replace('/', Path.DirectorySeparatorChar); // // frame = new Frame(this._document, stylename, // realgraphicname, graphicpath); // // frame.Style.Node = stylenode; // frame.Graphic.Node = graphicnode; // ((FrameStyle)frame.Style).GraphicProperties.Node = graphicproperties; // // XmlNode nodeSize = framenode.SelectSingleNode("@svg:height", // this._document.NamespaceManager); // // if (nodeSize != null) // if (nodeSize.InnerText != null) // frame.GraphicHeight = nodeSize.InnerText; // // nodeSize = framenode.SelectSingleNode("@svg:width", // this._document.NamespaceManager); // // if (nodeSize != null) // if (nodeSize.InnerText != null) // frame.GraphicWidth = nodeSize.InnerText; // } #endregion //Create a new Frame Frame frame = new Frame(this._document, null); frame.Node = frameNode; ContentCollection iColl = new ContentCollection(); //Revieve the FrameStyle IStyle frameStyle = this._document.Styles.GetStyleByName(frame.StyleName); if (frameStyle != null) frame.Style = frameStyle; else { this.OnWarning(new AODLWarning("Couldn't recieve a FrameStyle.", frameNode)); } //Create the frame content foreach(XmlNode nodeChild in frame.Node.ChildNodes) { IContent iContent = this.CreateContent(nodeChild); if (iContent != null) AddToCollection(iContent, iColl); //iColl.Add(iContent); else { this.OnWarning(new AODLWarning("Couldn't create a IContent object for a frame.", nodeChild)); } } frame.Node.InnerXml = ""; foreach(IContent iContent in iColl) { AddToCollection(iContent, frame.Content); //frame.Content.Add(iContent); if (iContent is Graphic) { LoadFrameGraphic(frame, iContent as Graphic); } if (iContent is EmbedObject) { //(EmbedObject(iContent)).Frame =frame; (iContent as EmbedObject).Frame = frame; } } return frame; } catch(Exception ex) { throw new AODLException("Exception while trying to create a Frame.", ex); } }
/// <summary> /// Gets the draw frame as HTML. /// </summary> /// <param name="frame">The frame.</param> /// <returns></returns> public string GetDrawFrameAsHtml(Frame frame) { string html = "<p>\n"; try { if (frame != null) { if (frame.Content != null) { //Check for possible Image Map bool containsImageMap = false; foreach(IContent iContent in frame.Content) if (iContent is ImageMap) { this._nextImageMapName = Guid.NewGuid().ToString(); containsImageMap = true; break; } if (!containsImageMap) this._nextImageMapName = null; html += this.GetIContentCollectionAsHtml(frame.Content); } } } catch(Exception ex) { throw new AODLException("Exception while trying to build a HTML string from a Frame object.", ex); } if (!html.Equals("<p>\n")) html += "</p>\n"; else html = ""; return html; }
public void DrawTextBoxTest() { TextDocument textdocument = new TextDocument(); textdocument.New(); Paragraph pOuter = ParagraphBuilder.CreateStandardTextParagraph(textdocument); DrawTextBox drawTextBox = new DrawTextBox(textdocument); Frame frameTextBox = new Frame(textdocument, "fr_txt_box"); frameTextBox.DrawName = "fr_txt_box"; frameTextBox.ZIndex = "0"; // Paragraph pTextBox = ParagraphBuilder.CreateStandardTextParagraph(textdocument); // pTextBox.StyleName = "Illustration"; Paragraph p = ParagraphBuilder.CreateStandardTextParagraph(textdocument); p.StyleName = "Illustration"; Frame frame = new Frame(textdocument, "frame1", "graphic1", _imagefile); frame.ZIndex = "1"; p.Content.Add(frame); p.TextContent.Add(new SimpleText(textdocument, "Illustration")); drawTextBox.Content.Add(p); frameTextBox.SvgWidth = frame.SvgWidth; drawTextBox.MinWidth = frame.SvgWidth; drawTextBox.MinHeight = frame.SvgHeight; frameTextBox.Content.Add(drawTextBox); pOuter.Content.Add(frameTextBox); textdocument.Content.Add(pOuter); textdocument.SaveTo(AARunMeFirstAndOnce.outPutFolder+"drawTextbox.odt"); }
public void ImageMapTest() { TextDocument document = new TextDocument(); document.New(); //Create standard paragraph Paragraph paragraphOuter = ParagraphBuilder.CreateStandardTextParagraph(document); //Create the frame with graphic Frame frame = new Frame(document, "frame1", "graphic1", _imagefile); //Create a Draw Area Rectangle DrawAreaRectangle drawAreaRec = new DrawAreaRectangle( document, "0cm", "0cm", "1.5cm", "2.5cm", null); drawAreaRec.Href = "http://OpenDocument4all.com"; //Create a Draw Area Circle DrawAreaCircle drawAreaCircle = new DrawAreaCircle( document, "4cm", "4cm", "1.5cm", null); drawAreaCircle.Href = "http://AODL.OpenDocument4all.com"; DrawArea[] drawArea = new DrawArea[2] { drawAreaRec, drawAreaCircle }; //Create a Image Map ImageMap imageMap = new ImageMap(document, drawArea); //Add Image Map to the frame frame.Content.Add(imageMap); //Add frame to paragraph paragraphOuter.Content.Add(frame); //Add paragraph to document document.Content.Add(paragraphOuter); //Save the document document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"simpleImageMap.odt"); }
/// <summary> /// Gets the frame style as HTML. /// </summary> /// <param name="frame">The frame.</param> /// <returns></returns> public string GetFrameStyleAsHtml(Frame frame) { string style = ""; try { if (frame != null) { string width = frame.SvgWidth; if (width != null) if (width.EndsWith("cm")) width = width.Replace("cm", ""); else if (width.EndsWith("in")) width = width.Replace("in", ""); string height = frame.SvgHeight; if (height != null) if (height.EndsWith("cm")) height = height.Replace("cm", ""); else if (height.EndsWith("in")) height = height.Replace("in", ""); try { if (width != null) { double wd = Convert.ToDouble(width, System.Globalization.NumberFormatInfo.InvariantInfo); string wdPx = ""; if (frame.SvgWidth.EndsWith("cm")) wdPx = SizeConverter.CmToPixelAsString(wd); else if (frame.SvgWidth.EndsWith("in")) wdPx = SizeConverter.InchToPixelAsString(wd); if (wdPx.Length > 0) style = "width=\""+wdPx+"\" "; } if (height != null) { double wd = Convert.ToDouble(height, System.Globalization.NumberFormatInfo.InvariantInfo); string wdPx = ""; if (frame.SvgHeight.EndsWith("cm")) wdPx = SizeConverter.CmToPixelAsString(wd); else if (frame.SvgHeight.EndsWith("in")) wdPx = SizeConverter.InchToPixelAsString(wd); if (wdPx.Length > 0) style = "height=\""+wdPx+"\" "; } } catch(Exception ex) { if (this.OnWarning != null) { AODLWarning warning = new AODLWarning("Exception while trying to build a graphic width & height.: " + frame.SvgWidth + "/" + frame.SvgHeight, ex); //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); //warning.OriginalException = ex; OnWarning(warning); } } } } catch(Exception ex) { throw new AODLException("Exception while trying to build a HTML style string from a FrameStyle.", ex); } return style; }
public void EventListenerTest() { try { TextDocument textdocument = new TextDocument(); textdocument.New(); // Create a frame (GraphicName == name property of frame) Frame frame = new Frame(textdocument, "frame1", "img1", _imagefile); // Create some event listeners (using OpenOffice friendly syntax). EventListener script1 = new EventListener(textdocument, "dom:mouseover", "javascript", "vnd.sun.star.script:HelloWorld.helloworld.js?language=JavaScript&location=share"); EventListener script2 = new EventListener(textdocument, "dom:mouseout", "javascript", "vnd.sun.star.script:HelloWorld.helloworld.js?language=JavaScript&location=share"); EventListeners listeners = new EventListeners(textdocument, new EventListener[] { script1, script2 }); // Create and add some area rectangles; reuse event listeners DrawAreaRectangle[] rects = new DrawAreaRectangle[2]; rects[0] = new DrawAreaRectangle(textdocument, "4cm", "4cm", "2cm", "2cm", listeners); //Reuse a clone of the EventListener rects[1] = new DrawAreaRectangle(textdocument, "1cm", "1cm", "2cm", "2cm", (EventListeners)listeners.Clone()); // Create and add an image map, referencing the area rectangles ImageMap map = new ImageMap(textdocument, rects); frame.Content.Add(map); // Add the frame to the text document textdocument.Content.Add(frame); // Save the document textdocument.SaveTo(_framefile); textdocument.Dispose(); } catch (Exception ex) { //Console.Write(ex.Message); } }
/// <summary> /// Gets the picture in OOXMLFormat /// </summary> /// <param name="doc">The document to add the image to</param> /// <param name="index">The index of the image in the list of pargraphs. /// This is used for generating an identifier for the image</param> /// <param name="imageCount">The number of images in the document. /// This is needed for the caption number</param> /// <returns>Picture in OOXML Document</returns> public List <AODL.Document.Content.IContent> GetODFParagraph(AODL.Document.TextDocuments.TextDocument doc, int index, ref int imageCount) { //Create a string with the filename to use. //This is the given filename or a temp file if there is only an image. string tempFileName = _filePath; if (string.IsNullOrEmpty(tempFileName)) { //If there is only an image and not a filepath create a tempfile. string dir = string.Format("{0}\\DocumentGenerator", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } tempFileName = string.Format("{0}\\Image{1}.jpg", dir, index); _image.Save(tempFileName); } //Create the main paragraph. AODL.Document.Content.Text.Paragraph p = ParagraphBuilder.CreateStandardTextParagraph(doc); if (!string.IsNullOrEmpty(_text)) { //Draw the text box for the label var drawTextBox = new DrawTextBox(doc); var frameTextBox = new AODL.Document.Content.Draw.Frame(doc, "fr_txt_box") { DrawName = "fr_txt_box", ZIndex = "0" }; //Create the paragraph for the image var pInner = ParagraphBuilder.CreateStandardTextParagraph(doc); pInner.StyleName = "Illustration"; //Create the image frame var frame = new AODL.Document.Content.Draw.Frame(doc, "frame1", string.Format("graphic{0}", index), tempFileName) { ZIndex = "1" }; //Add the frame. pInner.Content.Add(frame); //Add the title pInner.TextContent.Add(new SimpleText(doc, _text)); //Draw the text and image in the box. drawTextBox.Content.Add(pInner); frameTextBox.SvgWidth = frame.SvgWidth; drawTextBox.MinWidth = frame.SvgWidth; drawTextBox.MinHeight = frame.SvgHeight; frameTextBox.Content.Add(drawTextBox); p.Content.Add(frameTextBox); } else { //Create a frame with the image. var frame = new AODL.Document.Content.Draw.Frame(doc, "Frame1", string.Format("graphic{0}", index), tempFileName); p.Content.Add(frame); } //Finally delete image file if it is a temp file. //if (tempFileName != _filePath) File.Delete(tempFileName); return(new List <AODL.Document.Content.IContent> { p }); }