public virtual void AddLine(PdfPageDetails page, Dictionary <PdfFontDetails, int> fontRef,
                                    PdfTextLineDetails line, StringBuilder sb)
        {
            sb.Append($@"
        <div class=""line"" style=""")
            .Append("right:").Append((int)line.Right)
            .Append("px;left:").Append((int)line.Left)
            .Append("px;top:").Append((int)(line.Top))
            .Append("px;width:").Append((int)(line.Width))
            .Append("px;bottom:").Append((int)(page.Height - line.Bottom))
            .Append("px\" >");
            PdfLinkResult link = null;

            foreach (var text in line.Texts)
            {
                if (text.LinkParent != null)
                {
                    if (text.LinkParent != link)
                    {
                        AddLink(link = text.LinkParent, fontRef, sb);
                    }
                    continue;
                }

                AddText(text, fontRef, sb);
            }

            sb.Append(@"</div>");
        }
示例#2
0
 private void AddShapes(PdfPageDetails page, StringBuilder sb)
 {
     if (page.Shapes.Count == 0)
     {
         return;
     }
     shapeWriter?.AddShapes(page, sb);
 }
示例#3
0
        public string ConvertPage(PdfPageDetails page)
        {
            var sb       = new StringBuilder();
            var fontRef  = CreateFontRef(page.Fonts);
            var allLines = page.Lines;

            StartHtml(sb, Title(page), page.RightToLeft, fontRef, allLines);
            AddPage(page, fontRef, sb);
            EndHtml(sb);
            return(sb.ToString());
        }
        public override void AddShapes(PdfPageDetails page, StringBuilder sb)
        {
            sb.Append(@"
    <svg class=""canvas"" height=""").Append(Math.Round(page.Height))
            .Append("\" width=\"").Append(Math.Round(page.Width))
            .Append("\" style=\"margin-top:-").Append(Math.Round(page.Height) + 2)
            .Append("px;\">");
            foreach (var shape in page.Shapes)
            {
                AddShape(shape, sb);
            }

            sb.Append(@"
    </svg>");
        }
示例#5
0
        protected virtual void AddPage(PdfPageDetails page, Dictionary <PdfFontDetails, int> fontRef, StringBuilder sb)
        {
            AddHeader(page, sb);
            sb.Append(@"
    <article class=""article"" dir=""").Append(page.RightToLeft ? "rtl" : "ltr")
            .Append("\" style=\"width: ").Append(Math.Round(page.Width))
            .Append("px;height:").Append(Math.Round(page.Height))
            .Append("px;\">");
            foreach (var pdfImage in page.Images)
            {
                imageWriter.AddImage(page, pdfImage, sb);
            }

            foreach (var line in page.Lines)
            {
                textWriter.AddLine(page, fontRef, line, sb);
            }

            sb.Append(@"
    </article>");
            AddShapes(page, sb);
        }
        public override void AddShapes(PdfPageDetails page, StringBuilder sb)
        {
            sb.Append(@"
    <canvas class=""canvas"" id=""canvas-").Append(page.PageNumber)
            .Append("\" style=\"width: ")
            .Append(Math.Round(page.Width))
            .Append("px;height:").Append(Math.Round(page.Height))
            .Append("px;margin-top:-").Append(Math.Round(page.Height) + 2)
            .Append("px;\" width=\" ")
            .Append(Math.Round(page.Width))
            .Append("\" height=\"").Append(Math.Round(page.Height)).Append("\"></canvas>");

            sb.Append(@"
    <script>
        currentCanvas= document.getElementById('canvas-").Append(page.PageNumber).Append(@"');");
            foreach (var shape in page.Shapes)
            {
                AddShape(shape, sb);
            }

            sb.Append(@"
    </script>");
        }
        public virtual void AddImage(PdfPageDetails page, PdfImageDetails image, StringBuilder sb)
        {
            sb.Append(@"
        <img class=""image"" height=""").Append(image.Height)
            .Append("\" width=\"")
            .Append(image.Width).Append("\" src=\"");
            if (embeddedImages || dirImages == null)
            {
                sb.Append("data:image/png;base64, ")
                .Append(Convert.ToBase64String(image.Buffer));
            }
            else
            {
                string path;
                lock (this)
                {
                    FileInfo file;
                    do
                    {
                        file = new FileInfo(Path.Combine(dirImages, "image" + indexImage++ + ".png"));
                    }while (file.Exists);
                    path = file.FullName;
                    File.WriteAllBytes(path, image.Buffer);
                }

                sb.Append(path);
            }

//            if (image.Alt != null)
//                sb.Append("\" alt=\"").Append(image.Alt);

            sb.Append("\" style=\"")
            .Append(page.RightToLeft ? "right" : "left")
            .Append(":").Append((int)((page.RightToLeft ? image.Right : image.Left)))
            .Append("px; top:").Append((int)(image.Top)).Append("px\">");
            ;
        }
示例#8
0
 public abstract void AddShapes(PdfPageDetails page, StringBuilder sb);
示例#9
0
 protected virtual string Title(PdfPageDetails page)
 {
     return("pdf page " + page.PageNumber);
 }
示例#10
0
     protected virtual void AddHeader(PdfPageDetails page, StringBuilder sb)
     {
         sb.Append(@"
 <h2 class=""header"" style=""width: ").Append(Math.Round(page.Width))
         .Append("px;\">Page ").Append(page.PageNumber).Append("</h2>");
     }