/// <summary> /// Write the tags to the given pdf document. /// </summary> /// <param name="tags"></param> /// <param name="document"></param> public void Write(IEnumerable <ITag> tags, PdfBuilder document) { foreach (ITag tag in tags) { document.Write(tag); } }
private string CreatePdf(SiteBase s, Dictionary <string, Dictionary <string, JOffer> > offerMap) { PdfBuilder pdf = new PdfBuilder(s); pdf.CreateHeaders(); foreach (string link in offerMap.Keys.ToList()) { Dictionary <string, JOffer> map = offerMap[link]; List <JOffer> offers = new List <JOffer>(); if (map.Count > 0) { foreach (Category item in Const.categories) { if ((map.ContainsKey(item.Name)) && (map[item.Name] != null)) { map[item.Name].SetSiteName(link); offers.Add(map[item.Name]); } else { offers.Add(new JOffer()); } } } pdf.addRow(offers.ToArray()); } pdf.Close(); return(pdf.fileName); }
/// <summary> /// Render the given list block to the PDF document. /// </summary> /// <param name="renderer">The PDF renderer.</param> /// <param name="html">The list block to be renderered.</param> protected override void Write(PdfBuilder renderer, ListBlock list) { renderer.StartNewParagraph(); int i = 1; // Implicit cast from Block to ListItemBlock here. Markdig's builtin html // renderer also makes this assumption. foreach (ListItemBlock child in list) { // Write the bullet. // todo: should use proper indentation (\t) here. string bullet = list.IsOrdered ? $"{i}." : list.BulletType.ToString(); // Calling StartListItem() will prevent the list item's contents // from creating a new paragraph. renderer.StartListItem($" {bullet} "); // Write the contents of the list item. renderer.WriteChildren(child); // Write a newline character. We don't want multiple list items on the same line. // renderer.AppendText(Environment.NewLine, TextStyle.Normal, false); renderer.FinishListItem(); i++; } renderer.StartNewParagraph(); }
/// <summary> /// Render the given image tag to the PDF document. /// </summary> /// <param name="image">Image tag to be rendered.</param> /// <param name="renderer">PDF renderer to use for rendering the tag.</param> protected override void Render(Image image, PdfBuilder renderer) { // Add the image to a new paragraph. renderer.StartNewParagraph(); renderer.AppendImage(image.GetRaster(searchPath)); renderer.StartNewParagraph(); }
/// <summary> /// Render the given table cell to the PDF document. /// </summary> /// <param name="renderer">The PDF renderer.</param> /// <param name="cell">The table cell to be renderered.</param> protected override void Write(PdfBuilder renderer, TableCell cell) { renderer.StartTableCell(); // todo: cells spanning multiple rows/columns. renderer.WriteChildren(cell); renderer.FinishTableCell(); }
/// <summary> /// Render the given Paragraph tag to the PDF document. /// </summary> /// <param name="paragraph">Paragraph tag to be rendered.</param> /// <param name="renderer">PDF renderer to use for rendering the tag.</param> protected override void Render(Section section, PdfBuilder renderer) { // If the section contains no content (child tags), then don't // bother writing the heading. if (!section.IsEmpty()) { // Add a heading at the current heading level. if (!string.IsNullOrEmpty(section.Title)) { renderer.AppendHeading(section.Title); } // Increment the heading level, so that any child tags' headings // are written as subheadings. renderer.PushSubHeading(); // Add child tags. foreach (ITag child in section.Children) { renderer.Write(child); } renderer.PopSubHeading(); } }
/// <summary> /// Goes through each <see cref="Section"/> in the <see cref="Pdf"/> and adds a Header and Footer component. /// </summary> /// <param name="pdfBuilder">pdfBuilder</param> /// <param name="headerText">headerText</param> /// <param name="footerText">footerText</param> public static void CreateHeaderAndFooterForPdf(this PdfBuilder pdfBuilder, string headerText, string footerText) { foreach (Section section in pdfBuilder.AsposePdf.Sections) { pdfBuilder.CreateHeaderAndFooterForPdfForSection(section, headerText, footerText); } }
public void SetUp() { document = new MigraDocCore.DocumentObjectModel.Document(); pdfBuilder = new PdfBuilder(document, PdfOptions.Default); pdfBuilder.UseTagRenderer(new MockTagRenderer()); renderer = new TableTagRenderer(); }
public static Document CreateStandardDocument(bool vertical = true) { Document document = new Document(); var section = document.AddSection(); PageSetup pageSetup = document.DefaultPageSetup.Clone(); pageSetup.LeftMargin = Unit.FromCentimeter(1); pageSetup.RightMargin = Unit.FromCentimeter(1); pageSetup.TopMargin = Unit.FromCentimeter(1); pageSetup.BottomMargin = Unit.FromCentimeter(1); pageSetup.Orientation = vertical ? Orientation.Portrait : Orientation.Landscape; section.PageSetup = pageSetup; document.Styles.Normal.ParagraphFormat.SpaceAfter = Unit.FromPoint(10); section.AddParagraph(); PdfBuilder builder = new PdfBuilder(document, PdfOptions.Default); builder.AppendImage(Image.LoadFromResource("AIBanner.png")); document.LastSection.AddParagraph(); return(document); }
/// <summary> /// Append the given input file to a pdf document. /// </summary> /// <param name="builder">Pdf builder API.</param> /// <param name="file">Input file.</param> private void AppendToDocument(PdfBuilder builder, string file) { try { Simulations model = FileFormat.ReadFromFile <Simulations>(file, e => throw e, false); // This is a hack. We can't resolve links for "validation" files // which contain experiments, sims, etc, because the simulations // aren't prepared for a run, so some links may not be resolvable. // Fortunately, components in these files generally don't require // links to be resolved in order to document themselves. Therefore, // we only attempt to resolve links for model resources (*.json). if (Path.GetExtension(file) == ".json") { model.Links.Resolve(model, true, true, false); } foreach (ITag tag in DocumentModel(model)) { builder.Write(tag); } } catch (Exception err) { throw new Exception($"Unable to generate documentation for file {file}", err); } }
/// <summary> /// Render the given DirectedGraphTag tag to the PDF document. /// </summary> /// <param name="tag">Directed graph tag to be rendered.</param> /// <param name="renderer">PDF renderer to use for rendering the tag.</param> protected override void Render(DirectedGraphTag tag, PdfBuilder renderer) { renderer.GetPageSize(out double width, out double height); renderer.StartNewParagraph(); renderer.AppendImage(WriteToImage(tag.Graph, (int)width, (int)width)); renderer.StartNewParagraph(); }
public void TestRenderInvalidType() { PdfBuilder builder = new PdfBuilder(new Document(), PdfOptions.Default); ITag tag = new MockTag(p => { }); ITagRenderer renderer = new Renderer(); Assert.Throws <InvalidCastException>(() => renderer.Render(tag, builder)); }
public void Setup() { document = new MigraDocCore.DocumentObjectModel.Document(); // Workaround for a quirk in the migradoc API. _ = document.AddSection().Elements; pdfBuilder = new PdfBuilder(document, PdfOptions.Default); renderer = new HtmlBlockRenderer(); }
private void PageFooter(PdfBuilder builder, PageFooterEventArgs e) { var postionY = builder.PagePositionY; builder.PagePositionY = 10; builder.AddText(String.Format("...PAGE FOOTER... | Page: {0}", builder.PageCount.ToString())); builder.PagePositionY = postionY; }
/// <summary> /// Render the given LineBreakInline object to the PDF document. /// </summary> /// <param name="renderer">The PDF renderer.</param> /// <param name="obj">The LineBreakInline object to be renderered.</param> protected override void Write(PdfBuilder renderer, LineBreakInline obj) { // Html version of this class has an option to render soft line breaks // as a hard line break. We could implement something similar. string textToInsert = obj.IsHard ? Environment.NewLine : " "; renderer.AppendText(textToInsert, TextStyle.Normal); }
public string StartGeneration(PdfModel model) { var pdfBuilder = new PdfBuilder(); var task = pdfBuildr.BuildAsync(model); var ticket = Guid.NewGuid().ToString("N"); _workMap[ticket] = task; return ticket; }
public void SetUp() { doc = new Document(); citations = new Dictionary <string, ICitation>(); citationResolver = new Mock <ICitationHelper>(); citationResolver.Setup(c => c.Lookup(It.IsAny <string>())).Returns <string>(n => { citations.TryGetValue(n, out ICitation result); return(result); }); builder = new PdfBuilder(doc, new PdfOptions(null, citationResolver.Object)); }
public void TestRender() { PdfBuilder builder = new PdfBuilder(new Document(), PdfOptions.Default); ITag tag = new SubTag(); ITagRenderer renderer = new Renderer(); Assert.Throws <NotImplementedException>(() => renderer.Render(tag, builder)); }
public void Setup() { document = new MigraDocCore.DocumentObjectModel.Document(); // Workaround for a quirk in the migradoc API. _ = document.AddSection().Elements; pdfBuilder = new PdfBuilder(document, PdfOptions.Default); renderer = new ListBlockRenderer(); sampleBlock = CreateListBlock('-', "a list item"); }
/// <summary> /// Render the given Map tag to the PDF document. /// </summary> /// <param name="map">Map tag to be rendered.</param> /// <param name="document">PDF renderer to use for rendering the tag.</param> protected override void Render(MapTag map, PdfBuilder document) { document.GetPageSize(out double width, out double height); int resolution = (int)Math.Min(width, height); document.StartNewParagraph(); document.AppendImage(map.ToImage(resolution)); document.StartNewParagraph(); }
/// <summary> /// Render the given autolink inline object to the PDF document. /// </summary> /// <param name="renderer">The PDF renderer.</param> /// <param name="obj">The autolink inline object to be renderered.</param> protected override void Write(PdfBuilder renderer, AutolinkInline obj) { string prefix = obj.IsEmail ? "mailto:" : ""; string uri = $"{prefix}{obj.Url}"; renderer.SetLinkState(uri); renderer.AppendText(uri, TextStyle.Normal); renderer.ClearLinkState(); }
public void Setup() { document = new MigraDocCore.DocumentObjectModel.Document(); // Workaround for a quirk in the migradoc API. _ = document.AddSection().Elements; pdfBuilder = new PdfBuilder(document, PdfOptions.Default); renderer = new CodeBlockRenderer(); block = CreateCodeBlock("this is source code"); }
public void Setup() { document = new Document(); // Workaround for a quirk in the migradoc API. _ = document.AddSection().Elements; pdfBuilder = new PdfBuilder(document, PdfOptions.Default); renderer = new LiteralInlineRenderer(); inline = new LiteralInline("sample literal"); }
public void Setup() { document = new Document(); // Workaround for a quirk in the migradoc API. _ = document.AddSection().Elements; pdfBuilder = new PdfBuilder(document, PdfOptions.Default); renderer = new ThematicBreakBlockRenderer(); hr = new ThematicBreakBlock(new ThematicBreakParser()); }
/// <summary> /// Render the given Paragraph tag to the PDF document. /// </summary> /// <param name="paragraph">Paragraph tag to be rendered.</param> /// <param name="renderer">PDF renderer to use for rendering the tag.</param> protected override void Render(Paragraph paragraph, PdfBuilder renderer) { // Add the Paragraph to a new paragraph. if (!string.IsNullOrWhiteSpace(paragraph.Text)) { MarkdownDocument document = MarkdownParser.Parse(paragraph.Text, pipeline); renderer.Render(document); } }
public void SetUp() { document = new MigraDocCore.DocumentObjectModel.Document(); // Workaround for a quirk in the migradoc API. _ = document.AddSection().Elements; pdfBuilder = new PdfBuilder(document, PdfOptions.Default); pdfBuilder.UseTagRenderer(new MockTagRenderer()); renderer = new ParagraphTagRenderer(); }
/// <summary> /// Generate the auto-documentation at the given output path. /// </summary> /// <param name="path">Path to which the file will be generated.</param> public void Generate(string path) { // This document instance will be used to write all of the input files' // documentation to a single document. Document document = PdfWriter.CreateStandardDocument(); PdfBuilder builder = new PdfBuilder(document, options); // Read the file. Simulations rootNode = FileFormat.ReadFromFile <Simulations>(filePath, e => throw e, false); // Attempt to resolve the model path inside the file. IVariable variable = rootNode.FindByPath(modelPath); // Ensure that we found a model. object result = variable?.Value; IModel model = result as IModel; if (variable == null) { throw new Exception($"Failed to resolve path {modelPath} in file {filePath}"); } if (result == null) { throw new Exception($"When resolving path {modelPath} in file {filePath}: {modelPath} resolved to null"); } if (model == null) { throw new Exception($"Attempted to read model from path {modelPath} in file {filePath}, but the path resolves to an object of type {result.GetType()}"); } // Attempt to resolve links for the given model. rootNode.Links.Resolve(model, true, true, false); // Document the model. IEnumerable <ITag> tags = model.Document(); // Document the rest of the file afterwards if necessary. if (documentRestOfFile) { tags = tags.AppendMany(rootNode.Document()); } // Write tags to document. foreach (ITag tag in tags) { builder.Write(tag); } // Write bibliography at end of document. builder.WriteBibliography(); // Write to PDF file at the specified path. string outFile = Path.Combine(path, OutputFileName); PdfWriter.Save(document, outFile); }
public void Setup() { document = new Document(); // Workaround for a quirk in the migradoc API. _ = document.AddSection().Elements; pdfBuilder = new PdfBuilder(document, PdfOptions.Default); renderer = new HtmlInlineRenderer(); inline = new HtmlInline(); inline.Tag = sampleHtml = "<td>"; }
public void Setup() { document = new Document(); // Workaround for a quirk in the migradoc API. _ = document.AddSection().Elements; pdfBuilder = new PdfBuilder(document, PdfOptions.Default); renderer = new AutolinkInlineRenderer(); autolink = new AutolinkInline(); autolink.Url = sampleUri = "theurl"; }
/// <summary> /// Convert a given list of tags into a PDF document and /// save the document to the given path. /// </summary> /// <param name="fileName">File name of the generated pdf.</param> /// <param name="tags">Tags to be converted to a PDF.</param> public void Write(string fileName, IEnumerable <ITag> tags) { Document pdf = CreateStandardDocument(); PdfBuilder pdfRenderer = new PdfBuilder(pdf, options); Write(tags, pdfRenderer); pdfRenderer.WriteBibliography(); Save(pdf, fileName); }
public static void Main(string[] args) { var options = new Options(); CommandLine.ICommandLineParser cmdParser = new CommandLine.CommandLineParser(new CommandLine.CommandLineParserSettings(System.Console.Error)); if (cmdParser.ParseArguments(args, options)) { string connectionString = string.Format("URI=file:{0}", options.Database); #if (NET) var connection = new System.Data.SQLite.SQLiteConnection(connectionString); #else var connection = new Mono.Data.Sqlite.SqliteConnection(connectionString); #endif connection.Open(); var command = connection.CreateCommand(); command.CommandText = "CREATE TABLE IF NOT EXISTS at (id INTEGER PRIMARY KEY NOT NULL,name VARCHAR,surname VARCHAR,year INTEGER,gender CHAR,time VARCHAR)"; command.ExecuteNonQuery(); var repo = new AthleteRepository(command); switch (options.Action) { case Action.Module: { // 10mm d=> 28pt // 15mm => 42pt //float marginLeft, float marginRight, float marginTop, float marginBottom var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10, 10, 36, 36); iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream("./module.pdf", System.IO.FileMode.Create)); document.Open(); var builder = new ModuleBuilder(document, options.YearEdition, 10); for (int page = 0; page < 10; page++) { builder.AddPage(); } document.Close(); break; } case Action.Insert: { System.Console.WriteLine("Drop all results?[y/N]?"); string yes = System.Console.ReadLine(); if (yes == "y") { FileHelpers.FileHelperEngine<Athlete> engine = new FileHelpers.FileHelperEngine<Athlete>(); Athlete[] athletes = engine.ReadFile(options.Input); repo.DeleteAll(); foreach (var a in athletes) { System.Console.WriteLine(a.Name); repo.Insert(a); } } break; } case Action.CreateList: case Action.CreateResult: { string catFileName = GetCatFileName(options); string reportFileName = GetReportFileName(options); var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10, 10, 36, 36); iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(reportFileName, System.IO.FileMode.Create)); document.Open(); IBuilder builder = null; if (options.Action == Action.CreateList) { builder = new ListBuilder(document); } else { builder = new PdfBuilder(document); } Category[] cats = GetCategories(catFileName); foreach (Category cat in cats) { if (log.IsDebugEnabled) log.Debug("parse" + cat.Id); builder.BeginReport(cat.Title, options.YearEdition); var athletes = repo.Query(string.Format (cat.Sql, options.YearEdition)); foreach (Athlete athlete in athletes) { builder.Add(athlete); } builder.EndReport(); } document.Close(); break; } case Action.Interactive: { Category[] cats = GetCategories(GetCatFileName(options)); var parser = new TimeParser(); foreach (Category cat in cats) { System.Console.WriteLine("========{0}=========", cat.Id); var athletes = repo.Query(string.Format (cat.Sql, options.YearEdition)); foreach (Athlete athlete in athletes) { System.Console.Write("{0:00} {1}\t{2}({3}):", athlete.Id, athlete.Surname, athlete.Name, athlete.Gender); string time = string.Empty; string fmt = string.Empty; do { time = System.Console.ReadLine(); fmt = parser.Parse(time); if (!string.IsNullOrEmpty(fmt) ) { System.Console.WriteLine(fmt); repo.UpdateTime(athlete.Id, fmt); } else { if (time != "s") { System.Console.WriteLine("invalid.."); } } } while (string.IsNullOrEmpty(fmt) && time != "s"); } } break; } } connection.Close(); } }