public static bool Genereer(Deelnemer deelnemer, DeelnemerVerhuisd deelnemerVerhuisd) { _deelnemer = deelnemer; _event = deelnemerVerhuisd; // start pdf document _document = new PdfDocument(); _document.Info.Title = "Verhuisbrief " + _deelnemer.Naam; _document.Info.Author = "Verhuisbrief Generator"; // voeg pagina toe _page = _document.AddPage(); _gfx = XGraphics.FromPdfPage(_page); // vul pagina PlaatsLogo(); PlaatsTitel(); PlaatsNAWGegevens(); PlaatsInhoud(); // sla document op SlaPdfOp(); return true; }
public void Create(string filename, int qcount, int cellsinq, List<string> cellslabels,int rowscount) { s_document = new PdfDocument(); _page = new PdfPage(); _page.Orientation = PageOrientation.Landscape; _page.Size = PageSize.A4; s_document.Pages.Add(_page); gfx = XGraphics.FromPdfPage(_page); DrawCenterMarker(7); DrawSideMarker(7, 10, 10); DrawSideMarker(7, 285, 10); DrawSideMarker(7, 10, 200); DrawSideMarker(7, 285, 200); AddFields(); AddQuestions(qcount,cellsinq,cellslabels,rowscount); // Save the s_document... s_document.Save(filename); // ...and start a viewer Process.Start(filename); }
//PdfSharp version public static IEnumerable <string> ExtractText(PdfSharp.Pdf.PdfPage page) { CObject content = ContentReader.ReadContent(page); var text = ExtractText(content); return(text); }
//private PdfHelper() //{ //} //public static PdfHelper Instance { get; } = new PdfHelper(); internal void SaveImageAsPdf(string imageFileName, string pdfFileName, int width = 600, bool deleteImage = false) { using (var document = new PdfSharp.Pdf.PdfDocument()) { PdfSharp.Pdf.PdfPage page = document.AddPage(); using (XImage img = XImage.FromFile(imageFileName)) { // Calculate new height to keep image ratio var height = (int)(((double)width / (double)img.PixelWidth) * img.PixelHeight); // Change PDF Page size to match image page.Width = width; page.Height = height; XGraphics gfx = XGraphics.FromPdfPage(page); gfx.DrawImage(img, 0, 0, width, height); } var PtPosition = imageFileName.LastIndexOf('.'); var PathTemp = imageFileName.Remove(PtPosition); var pathPdfFile = PathTemp + ".pdf"; document.Save(pathPdfFile /*pdfFileName*/); } if (deleteImage) { File.Delete(imageFileName); } }
public CParser(PdfPage page) { this.page = page; PdfContent content = page.Contents.CreateSingleContent(); byte[] bytes = content.Stream.Value; this.lexer = new CLexer(bytes); }
internal void RenderPage(PdfPage page, FixedPage fixedPage) { this.page = page; this.context = new DocumentRenderingContext(page.Owner); //this.page.Width = fixedPage.Width; //this.page.Height = fixedPage.Height; //this.gsStack = new GraphicsStateStack(this); PdfContent content = null; //switch (options) //{ // case XGraphicsPdfPageOptions.Replace: // page.Contents.Elements.Clear(); // goto case XGraphicsPdfPageOptions.Append; // case XGraphicsPdfPageOptions.Prepend: // content = page.Contents.PrependContent(); // break; // case XGraphicsPdfPageOptions.Append: content = page.Contents.AppendContent(); // break; //} page.RenderContent = content; this.writer = new PdfContentWriter(this.context, this.page); //Initialize(); this.writer.BeginContent(false); this.writer.WriteElements(fixedPage.Content); this.writer.EndContent(); }
//PDFSharp - less features but same company as MigraDoc public PdfDocument ConvertToPdf2(ArrayList translationInput, int caseNumber, int evidenceNumber) { PdfDocument document = new PdfDocument(); document.Info.Title = "Decrypted Translations"; PdfSharp.Pdf.PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XFont font = new XFont("Verdna", 11, XFontStyle.Regular); var formatter = new PdfSharp.Drawing.Layout.XTextFormatter(gfx); var rectangle = new XRect(10, 10, page.Width, page.Height); string newText = ""; //string newText2 = ""; int i = 0; foreach (string text in translationInput) { i++; Console.WriteLine(i + " " + text); newText = newText + i + ". " + text + "\r\n"; } formatter.DrawString(newText, font, XBrushes.Black, rectangle); string filename = "CsNum" + caseNumber + ".EviNum" + evidenceNumber + ".pdf"; document.Save(filename); //Process.Start(filename); return(document); }
public static byte[] AppendImageToPdf(byte[] pdf, byte[] img, Point position, double scale) { using (System.IO.MemoryStream msPdf = new System.IO.MemoryStream(pdf)) { using (System.IO.MemoryStream msImg = new System.IO.MemoryStream(img)) { System.Drawing.Image image = System.Drawing.Image.FromStream(msImg); PdfSharp.Pdf.PdfDocument document = PdfSharp.Pdf.IO.PdfReader.Open(msPdf); PdfSharp.Pdf.PdfPage page = document.Pages[0]; PdfSharp.Drawing.XGraphics gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(page); PdfSharp.Drawing.XImage ximg = PdfSharp.Drawing.XImage.FromGdiPlusImage(image); gfx.DrawImage( ximg, position.X, position.Y, ximg.Width * scale, ximg.Height * scale ); using (System.IO.MemoryStream msFinal = new System.IO.MemoryStream()) { document.Save(msFinal); return(msFinal.ToArray()); } } } }
public override void Visit(ExportPage page) { PdfPage = pdfDocument.AddPage(); xGraphics = XGraphics.FromPdfPage(PdfPage); textFormatter = new XTextFormatter(xGraphics); base.Visit(page); }
public Export_to_Pdf() { InitializeComponent(); //Create object for pdf. document = new PdfDocument(); page = document.AddPage(); gfx = XGraphics.FromPdfPage(page); //Set by default values. font = new XFont("Arial", 12, XFontStyle.Regular); header_font = new XFont("Arial", 12, XFontStyle.Regular); page.Size = PageSize.A4; page.Orientation = PageOrientation.Portrait; ////////////////////////////////////////////////////////////////////// //Create a fake questionanire to test the print process to pdf. if (questionaire != null) { List<Question> question_list = new List<Question>(); List<Answer> answer_list = new List<Answer>(); Answer ans = new Answer(); ans.Answer_descr = "einai to dsfgdsfgsd"; answer_list.Add(ans); answer_list.Add(ans); answer_list.Add(ans); Question quest = new Question() { AnswerList = answer_list }; quest.Question_descr = "H ekfoonisi tis erotisis aytis einai blablbalbablbalblab"; for (int i = 0; i < 10; i++) { question_list.Add(quest); } questionaire = new Quastionnaire.Model.Questionaire() { Questionaire_descr = "sdfsakdfjdflshsadflkjashflasdfkh", QuestionList = question_list }; } ////////////////////////////////////////////////////////////////////// }
private void btnJPGtoPDF_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.InitialDirectory = "C:\\PDFDemoTemp"; dlg.Filter = "JPEG files (*.jpg)|*.jpg|All files (*.*)|*.*"; dlg.Multiselect = true; if (dlg.ShowDialog() == DialogResult.OK) { PdfDocument document = new PdfDocument(); document.Info.Title = "Created using PDFsharp"; foreach (string fileSpec in dlg.FileNames) { PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); DrawImage(gfx, fileSpec, 0, 0, (int)page.Width, (int)page.Height); } if (document.PageCount > 0) { document.Save(@"C: \Users\winst\Desktop\testResultOneImagePerPage.pdf"); //경로가 절대 주소여서 바꿔줘야 합니다. } } }
private void addNextPDF() { PdfPage page = new PdfPage(); page.Size = PageSize.A4; double h = SystemParameters.PrimaryScreenHeight; double w = SystemParameters.PrimaryScreenWidth; //XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); var rateW = page.Width / w; var rateH = page.Height / h; var strokes = CanvasStroke.ToList(); List<Point[]> pl = new List<Point[]>(); foreach (Stroke stroke in strokes) { StylusPointCollection points = stroke.StylusPoints; StylusPointCollection newPoints = new StylusPointCollection(); var pointList = points.ToList(); foreach (StylusPoint pt in pointList) { StylusPoint newPt = new StylusPoint(pt.X * rateW, pt.Y * rateH); newPoints.Add(newPt); } Point[] p = (Point[])newPoints; pList.Add(p); pl.Add(p); CanvasStroke.Remove(stroke); } pointL.Add(pl); }
private void btnFitPageToImage_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.InitialDirectory = "C:\\PDFDemoTemp"; dlg.Filter = "JPEG files (*.jpg)|*.jpg|All files (*.*)|*.*"; dlg.Multiselect = true; if (dlg.ShowDialog() == DialogResult.OK) { PdfDocument document = new PdfDocument(); document.Info.Title = "Created using PDFsharp"; PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); foreach (string fileSpec in dlg.FileNames) { System.Drawing.Image img = System.Drawing.Image.FromFile(fileSpec); page.Width = img.Width; page.Height = img.Height; DrawImage(gfx, fileSpec, 0, 0, (int)page.Width, (int)page.Height); } if (document.PageCount > 0) { document.Save(@"C:\PDFDemoTemp\ResultFitPageToImage.pdf"); } } }
private void btnMultiplePDF_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.InitialDirectory = "C:\\PDFDemoTemp"; dlg.Filter = "JPEG files (*.jpg)|*.jpg|All files (*.*)|*.*"; dlg.Multiselect = true; if (dlg.ShowDialog() == DialogResult.OK) { PdfDocument document = new PdfDocument(); document.Info.Title = "Created using PDFsharp"; PdfPage page = document.AddPage(); int StartX = 0 - (int)page.Width / 2; int StartY = 0 - (int)page.Height / 2; XGraphics gfx = XGraphics.FromPdfPage(page); foreach (string fileSpec in dlg.FileNames) { DrawImage(gfx, fileSpec, StartX, StartY, (int)page.Width * 2, (int)page.Height * 2); StartX += (int)page.Width / 2; StartY += (int)page.Height / 2; } if (document.PageCount > 0) { document.Save(@"C:\PDFDemoTemp\ResultZoomInOnImage.pdf"); } } }
void CreatePage() { Page = _document.AddPage(); Page.Size = PageSize.A4; Gfx = XGraphics.FromPdfPage(Page); _currentPosition = _topPosition; }
/// <summary> /// Create new page /// </summary> void CreatePage() { Page = _document.AddPage(); Page.Size = PageSize.A4; Gfx = XGraphics.FromPdfPage(Page); _currentPosition = _topPosition; }
/// <summary> /// Initializes a new instance of the <see cref="PdfOutline"/> class. /// </summary> /// <param name="title">The outline text.</param> /// <param name="destinationPage">The destination page.</param> /// <param name="opened">Specifies whether the node is displayed expanded (opened) or collapsed.</param> /// <param name="style">The font style used to draw the outline text.</param> /// <param name="textColor">The color used to draw the outline text.</param> public PdfOutline(string title, PdfPage destinationPage, bool opened, PdfOutlineStyle style, XColor textColor) { Title = title; DestinationPage = destinationPage; Opened = opened; Style = style; TextColor = textColor; }
private IEnumerable<IScannedImage> GetImagesFromPage(PdfPage page) { // Get resources dictionary PdfDictionary resources = page.Elements.GetDictionary("/Resources"); if (resources == null) { yield break; } // Get external objects dictionary PdfDictionary xObjects = resources.Elements.GetDictionary("/XObject"); if (xObjects == null) { yield break; } // Iterate references to external objects foreach (PdfItem item in xObjects.Elements.Values) { var reference = item as PdfReference; if (reference == null) { continue; } var xObject = reference.Value as PdfDictionary; // Is external object an image? if (xObject != null && xObject.Elements.GetString("/Subtype") == "/Image") { // Support multiple filter schemes // For JPEG: "/DCTDecode" OR ["/DCTDecode", "/FlateDecode"] // For PNG: "/FlateDecode" var element = xObject.Elements.Single(x => x.Key == "/Filter"); var elementAsArray = element.Value as PdfArray; var elementAsName = element.Value as PdfName; if (elementAsArray != null) { // JPEG ["/DCTDecode", "/FlateDecode"] yield return ExportJpegImage(page, Filtering.Decode(xObject.Stream.Value, "/FlateDecode")); } else if (elementAsName != null) { switch (elementAsName.Value) { case "/DCTDecode": yield return ExportJpegImage(page, xObject.Stream.Value); break; case "/FlateDecode": yield return ExportAsPngImage(page, xObject); break; default: throw new NotImplementedException("Unsupported image encoding"); } } else { throw new NotImplementedException("Unsupported filter"); } } } }
static PdfPrintTarget() { m_doc = new PdfDocument(); m_page = m_doc.AddPage(); m_info = XGraphics.FromPdfPage(m_page); m_size = PageSizeConverter.ToSize(m_page.Size); m_mmkx = m_size.Width / 210.0f; m_mmky = m_size.Height / 297.0f; }
public OHS_Page(PdfPage page, ProfileInfo userProfile, List<Parameter> userParameters) { this.page = page; this.userProfile = userProfile; foreach (Parameter p in userParameters) this.userParameters.Add(p.Name, p); quaterWidth = page.Width / 4; }
public XGraphicsPdfRenderer(PdfPage page, XGraphics gfx, XGraphicsPdfPageOptions options) { _page = page; _colorMode = page._document.Options.ColorMode; _options = options; _gfx = gfx; _content = new StringBuilder(); page.RenderContent._pdfRenderer = this; _gfxState = new PdfGraphicsState(this); }
/// <summary> /// Initializes a new instance of the <see cref="PdfContentWriter"/> class /// for creating a content stream of the specified page. /// </summary> public PdfContentWriter(DocumentRenderingContext context, PdfPage page) // , XGraphics gfx, XGraphicsPdfPageOptions options) { this.context = context; this.page = page; this.contentStreamDictionary = page; //this.colorMode = page.document.Options.ColorMode; //this.options = options; this.content = new StringBuilder(); this.graphicsState = new PdfGraphicsState(this); }
public void DrawPage(PdfPage page) { XGraphics gfx = XGraphics.FromPdfPage(page); DrawTitle(page, gfx, "Text"); DrawText(gfx, 1); DrawTextAlignment(gfx, 2); MeasureText(gfx, 3); }
/// <summary> /// Gets page size in mm or inch. /// </summary> public static string PageSize(PdfPage page, bool metric) { if (metric) return String.Format("{0:0.#} x {1:0.#} mm", XUnit.FromPoint(page.Width).Millimeter, XUnit.FromPoint(page.Height).Millimeter); else return String.Format("{0:0.#} x {1:0.#} inch", XUnit.FromPoint(page.Width).Inch, XUnit.FromPoint(page.Height).Inch); }
private void btnOk_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; List <int> pageIndexes = new List <int>(); for (int i = 0; i < lvPages.Items.Count; i++) { if (lvPages.Items[i].Checked) { pageIndexes.Add(i); } } /*Bitmap[] bmps = MupdfSharp.PageRenderer.Render(path, PAGETHEIGHTPIXEL, pageIndexes.ToArray()); * for(int i = 0; i < bmps.Length; i++) * { * Bitmap tmp = bmps[i]; * bmps[i] = tmp.MakeBackgroundTransparent(Color.White); * tmp.Dispose(); * }*/ if (!Directory.Exists(TmpManager.GetTmpDir() + "\\render")) { Directory.CreateDirectory(TmpManager.GetTmpDir() + "\\render"); } Pages = new KPage[pageIndexes.Count]; pdf.PdfDocument pdfdoc = pdf_io.PdfReader.Open(path, pdf_io.PdfDocumentOpenMode.Modify | pdf_io.PdfDocumentOpenMode.Import); for (int i = 0; i < pageIndexes.Count; i++) { int p = pageIndexes[i]; KPage page = new KPage(KDocument.EmptyDocument); pdf.PdfPage pPage = pdfdoc.Pages[p]; float w = (float)pPage.Width.Millimeter; float h = (float)pPage.Height.Millimeter; if (pPage.Rotate == 90 || pPage.Rotate == 270) { Util.Swap(ref w, ref h); } page.Format = new PageFormat(w, h); page.Background = null; page.ShowDate = false; page.OriginalPage = pPage; /*page.BackgroundImage * = new Renderer.Image(bmps[i]);*/ page.PdfRenderPath = TmpManager.NewFilename(TmpManager.GetTmpDir() + "\\render", "page", ".png"); Pages[i] = page; } pdfdoc.Close(); }
public MemoryStream Message2Pdf(MimeMessage message) { MemoryStream msMail = new MemoryStream(); string html = message.GetTextBody(MimeKit.Text.TextFormat.Html); string txt = message.GetTextBody(MimeKit.Text.TextFormat.Text); HtmlToPdf converter = new HtmlToPdf(); SelectPdf.PdfDocument pdfdok = null; if (html != null) { pdfdok = converter.ConvertHtmlString(html); } else { if (string.IsNullOrEmpty(txt)) { txt = "Tom email"; } pdfdok = converter.ConvertHtmlString(txt); } pdfdok.Save(msMail); msMail.Position = 0; XPdfForm form = XPdfForm.FromStream(msMail); PdfSharp.Pdf.PdfDocument outputDocument = new PdfSharp.Pdf.PdfDocument(); XGraphics gfx; int count = form.PageCount; for (int idx = 0; idx < count; idx++) { PdfSharp.Pdf.PdfPage page = outputDocument.AddPage(); if (form.PageCount > idx) { // Get a graphics object for page gfx = XGraphics.FromPdfPage(page); if (idx == 0) { DrawPageHeading(page, gfx, message); // Draw the page like an image gfx.DrawImage(form, new XRect(form.PointWidth * 0.02, form.PointHeight * 0.10, form.PointWidth * 0.90, form.PointHeight * 0.90)); } else { gfx.DrawImage(form, new XRect(form.PointWidth, form.PointHeight, form.PointWidth, form.PointHeight)); } } } msMail = new MemoryStream(); outputDocument.Save(msMail, false); return(msMail); }
/// <summary> /// Initializes a new instance of the <see cref="PdfRenderContext" /> class. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background color.</param> public PdfRenderContext(double width, double height, OxyColor background) { this.RendersToScreen = false; this.doc = new PdfDocument(); var page = new PdfPage { Width = new XUnit(width), Height = new XUnit(height) }; this.doc.AddPage(page); this.g = XGraphics.FromPdfPage(page); if (background.IsVisible()) { this.g.DrawRectangle(ToBrush(background), 0, 0, width, height); } }
public void DrawPage(PdfPage page) { XGraphics gfx = XGraphics.FromPdfPage(page); DrawTitle(page, gfx, "Paths"); DrawPathOpen(gfx, 1); DrawPathClosed(gfx, 2); DrawPathAlternateAndWinding(gfx, 3); DrawGlyphs(gfx, 5); DrawClipPath(gfx, 6); }
public void DrawPage(PdfPage page) { XGraphics gfx = XGraphics.FromPdfPage(page); DrawTitle(page, gfx, "Shapes"); DrawRectangle(gfx, 1); DrawRoundedRectangle(gfx, 2); DrawEllipse(gfx, 3); DrawPolygon(gfx, 4); DrawPie(gfx, 5); DrawClosedCurve(gfx, 6); }
public void DrawPage(PdfPage page) { XGraphics gfx = XGraphics.FromPdfPage(page); DrawTitle(page, gfx, "Lines & Curves"); DrawLine(gfx, 1); DrawLines(gfx, 2); DrawBezier(gfx, 3); DrawBeziers(gfx, 4); DrawCurve(gfx, 5); DrawArc(gfx, 6); }
public ConversionViewModel() { //collect the ratios PdfPage page = new PdfPage(); _paperRatios = new Dictionary<PageSize, double>(); foreach (PageSize p in Enum.GetValues(typeof(PageSize))) { if (p != PageSize.Undefined) { page.Size = p; _paperRatios.Add(p, page.Width.Value / page.Height.Value); } } }
public XGraphicsPdfRenderer(PdfPage page, XGraphics gfx, XGraphicsPdfPageOptions options) { this.page = page; this.colorMode = page.document.Options.ColorMode; this.options = options; #if MIGRADOC this.options = options & ~XGraphicsPdfPageOptions.PDFlibHack; pdflibHack = (options & XGraphicsPdfPageOptions.PDFlibHack) != 0; #endif this.gfx = gfx; this.content = new StringBuilder(); page.RenderContent.pdfRenderer = this; this.gfxState = new PdfGraphicsState(this); }
public void DrawPage(PdfPage page) { XGraphics gfx = XGraphics.FromPdfPage(page); DrawTitle(page, gfx, "Images"); DrawImage(gfx, 1); DrawImageScaled(gfx, 2); DrawImageRotated(gfx, 3); DrawImageSheared(gfx, 4); DrawGif(gfx, 5); DrawPng(gfx, 6); DrawTiff(gfx, 7); DrawFormXObject(gfx, 8); }
/// <summary> /// Generates a PDF document from the collection of enumerations with each image representing /// a new page. /// </summary> /// <param name="images">The collection of images to convert to pages.</param> /// <returns>The <see cref="PdfDocument"/> containing the images.</returns> public static PdfDocument ToPdf(this IEnumerable<Image> images) { PdfDocument document = new PdfDocument(); foreach (var image in images) { PdfPage page = new PdfPage() { Width = image.Width, Height = image.Height }; document.AddPage(page); XGraphics xGraphics = XGraphics.FromPdfPage(page); XImage xImage = XImage.FromGdiPlusImage(image); xGraphics.DrawImage(xImage, 0, 0, image.Width, image.Height); } return (document); }
public void Render(PdfPage page) { PageHeight = page.Height; PageWidth = page.Width; using (var gfx = XGraphics.FromPdfPage(page)) { DrawGrid(gfx); var positions = CalculateRects().Zip(_cards, (rect, card) => new { Rect = rect, Card = card }); foreach (var position in positions) { var card = position.Card; var rect = position.Rect; card.Render(rect, gfx, _fontName); } } }
public IEnumerable<PdfPage> GenerateFromStream(Stream source, PdfDocument pdf) { var page = new PdfPage(pdf); using (var gfx = XGraphics.FromPdfPage(page)) { using (var img = XImage.FromGdiPlusImage(Image.FromStream(source))) { page.Width = img.PointWidth; page.Height = img.PointHeight; gfx.DrawImage(img, 0, 0); } } return new[] { page }; }
private void btnHello_Click(object sender, EventArgs e) { PdfDocument document = new PdfDocument(); document.Info.Title = "Created with PDFsharp"; PdfPage page = document.AddPage(); //page.Size = PdfSharp.PageSize.A5; XGraphics gfx = XGraphics.FromPdfPage(page); XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic); gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center); const string filename = "c:\\PDFDemoTemp\\ResultHelloWorld.pdf"; document.Save(filename); }
public TextFormatter() { // Create a new PDF document _document = new PdfDocument(); _document.Info.Title = "Poor Man's Text Formatter"; // Create an empty page _page = _document.AddPage(); // Get an XGraphics object for drawing _graphics = XGraphics.FromPdfPage(_page); _indent = 1; _fontSize = 14; row = 0; _rowWidth = indentWidth; _fill = false; }
/// <summary> /// Gets the page with the specified index. /// </summary> public PdfPage this[int index] { get { if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException("index", index, PSSR.PageIndexOutOfRange); PdfDictionary dict = (PdfDictionary)((PdfReference)PagesArray.Elements[index]).Value; if (!(dict is PdfPage)) dict = new PdfPage(dict); return (PdfPage)dict; } //set //{ // if (index < 0 || index >= this.pages.Count) // throw new ArgumentOutOfRangeException("index", index, PSSR.PageIndexOutOfRange); // this.pages[index] = value; //} }
private void comPDF0(List <string> filelist, string path0) { Sharp.PdfDocument outputDocument = new Sharp.PdfDocument(); outputDocument.PageLayout = Sharp.PdfPageLayout.TwoColumnLeft; foreach (string f in filelist) { Sharp.PdfDocument inputDocument = SharpIO.PdfReader.Open(f, SharpIO.PdfDocumentOpenMode.Import); int count = inputDocument.PageCount; for (int idx = 0; idx < count; idx++) { Sharp.PdfPage page = inputDocument.Pages[idx]; outputDocument.AddPage(page); } inputDocument.Close(); } string filename = path0; outputDocument.Save(filename); }
public void Create(string filename, int qcount, int cellsinq, List<string> cellslabels, int rowscount) { s_document = new PdfDocument(); _page = new PdfPage(); _page.Orientation = PageOrientation.Landscape; _page.Size = PageSize.A4; s_document.Pages.Add(_page); gfx = XGraphics.FromPdfPage(_page); DrawCutLine(); PdfRectangle leftpage = new PdfRectangle(new XPoint(0, 0), new XPoint(_page.Width / 2, _page.Height)); PdfRectangle rightpage = new PdfRectangle(new XPoint(_page.Width / 2, 0), new XPoint(_page.Width, _page.Height)); //left part float leftcenter = (float)(_page.Width / 4) * 1f; DrawCenterMarker(7, leftcenter); DrawSideMarker(7, 10, 10); DrawSideMarker(7, XUnit.FromPoint(leftpage.Width).Millimeter-10, 10); DrawSideMarker(7, 10, XUnit.FromPoint(leftpage.Height).Millimeter - 10); DrawSideMarker(7, XUnit.FromPoint(leftpage.Width).Millimeter - 10, XUnit.FromPoint(leftpage.Height).Millimeter - 10); AddFields(leftpage); AddQuestions(qcount, cellsinq, cellslabels, rowscount, leftpage); //right part float rigthcenter = (float)(_page.Width / 4) * 3f; DrawCenterMarker(7, rigthcenter); DrawSideMarker(7, XUnit.FromPoint(rightpage.X1).Millimeter+10, XUnit.FromPoint(rightpage.Y1).Millimeter+10); DrawSideMarker(7, XUnit.FromPoint(rightpage.X2).Millimeter - 10, XUnit.FromPoint(rightpage.Y1).Millimeter + 10); DrawSideMarker(7, XUnit.FromPoint(rightpage.X1).Millimeter + 10, XUnit.FromPoint(rightpage.Y2).Millimeter - 10); DrawSideMarker(7, XUnit.FromPoint(rightpage.X2).Millimeter - 10, XUnit.FromPoint(rightpage.Y2).Millimeter - 10); AddFields(rightpage); AddQuestions(qcount, cellsinq, cellslabels, rowscount, rightpage); // Save the s_document... s_document.Save(filename); // ...and start a viewer Process.Start(filename); }
public static void PDFExport(string Paydate) { string InvoiceNumber = "" + SelectedInvoiceNumber + ""; PdfDocument document = new PdfDocument(); document.Info.Title = "Invoice"; document.Info.Author = "Jack Huckins"; document.Info.Subject = "Service Invoice"; PdfPage page = new PdfPage(); page = document.AddPage(); page.Width = XUnit.FromInch(8.5); page.Height = XUnit.FromInch(11); XGraphics gfx = default(XGraphics); gfx = XGraphics.FromPdfPage(page); XForm form = new XForm(document, XUnit.FromMillimeter(300), XUnit.FromMillimeter(300)); XGraphics formGfx = default(XGraphics); formGfx = XGraphics.FromForm(form); XGraphicsState state = default(XGraphicsState); state = formGfx.Save(); //..... Invoice Results GetInvResults(Paydate); PrepareInvoiceTop(formGfx, state, InvoiceNumber); PrepareInvoiceData(6, 217, formGfx); PrepareFooter(formGfx); state = formGfx.Save(); formGfx.Dispose(); gfx.DrawImage(form, 0, 0); //document.Save("c:\\Invoices\\Inv " + InvoiceNumber + ".pdf") SetReportPath(); document.Save(ReportPath); TimeConnector.Data.ActionLog.Insert("PDF Export", "" + InvoiceNumber + ""); //UpdatePDFLabel("30 second Check", Form1.lblPDFStatus); //var _with1 = ViewPDF; //_with1.PdfName = Export.ReportPath; //_with1.Show(); }
private void button1_Click(object sender, EventArgs e) { string pdfPath = "/"; //PDF 경로 string pdfname = "test.pdf"; //PDF 파일 이름 string[] jpgFiles = System.IO.Directory.GetFiles(pdfPath, "*.jpg"); //파일 읽어옴 PdfDocument document = new PdfDocument(); document.Info.Title = "Created using PDFsharp"; for (int i = 0; i < jpgFiles.Length; i++) { PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); DrawImage(gfx, jpgFiles[i], 0, 0, (int)page.Width, (int)page.Height); } if (document.PageCount > 0) { document.Save(pdfPath + pdfname); } }
private void comPDF0(String filename1, String filename2, String out3) { Sharp.PdfDocument inputDocument1 = SharpIO.PdfReader.Open(filename1, SharpIO.PdfDocumentOpenMode.Import); Sharp.PdfDocument inputDocument2 = SharpIO.PdfReader.Open(filename2, SharpIO.PdfDocumentOpenMode.Import); Sharp.PdfDocument outputDocument = new Sharp.PdfDocument(); // Show consecutive pages facing. Requires Acrobat 5 or higher. outputDocument.PageLayout = Sharp.PdfPageLayout.TwoColumnLeft; int count = Math.Max(inputDocument1.PageCount, inputDocument2.PageCount); for (int idx = 0; idx < count; idx++) { Sharp.PdfPage page1 = inputDocument1.PageCount > idx ? inputDocument1.Pages[idx] : new Sharp.PdfPage(); Sharp.PdfPage page2 = inputDocument2.PageCount > idx ? inputDocument2.Pages[idx] : new Sharp.PdfPage(); // Add both pages to the output document page1 = outputDocument.AddPage(page1); page2 = outputDocument.AddPage(page2); } string filename = out3; outputDocument.Save(filename); }
void SplitDestinationPage(PdfArray destination) // Reference: 8.2 Destination syntax / Page 582 { // ReSharper disable HeuristicUnreachableCode //#pragma warning disable 162 // The destination page may not yet have been transformed to PdfPage. PdfDictionary destPage = (PdfDictionary)((PdfReference)destination.Elements[0]).Value; PdfPage page = destPage as PdfPage; if (page == null) { page = new PdfPage(destPage); } DestinationPage = page; PdfName type = destination.Elements[1] as PdfName; if (type != null) { PageDestinationType = (PdfPageDestinationType)Enum.Parse(typeof(PdfPageDestinationType), type.Value.Substring(1), true); switch (PageDestinationType) { // [page /XYZ left top zoom] -- left, top, and zoom can be null. case PdfPageDestinationType.Xyz: Left = destination.Elements.GetNullableReal(2); Top = destination.Elements.GetNullableReal(3); Zoom = destination.Elements.GetNullableReal(4); // For this parameter, null and 0 have the same meaning. break; // [page /Fit] case PdfPageDestinationType.Fit: // /Fit has no parameters. break; // [page /FitH top] -- top can be null. case PdfPageDestinationType.FitH: Top = destination.Elements.GetNullableReal(2); break; // [page /FitV left] -- left can be null. case PdfPageDestinationType.FitV: Left = destination.Elements.GetNullableReal(2); break; // [page /FitR left bottom right top] -- left, bottom, right, and top must not be null. // TODO An exception in GetReal leads to an inconsistent document. Deal with that - e.g. by registering the corruption and preventing the user from saving the corrupted document. case PdfPageDestinationType.FitR: Left = destination.Elements.GetReal(2); Bottom = destination.Elements.GetReal(3); Right = destination.Elements.GetReal(4); Top = destination.Elements.GetReal(5); break; // [page /FitB] case PdfPageDestinationType.FitB: // /Fit has no parameters. break; // [page /FitBH top] -- top can be null. case PdfPageDestinationType.FitBH: Top = destination.Elements.GetReal(2); break; // [page /FitBV left] -- left can be null. case PdfPageDestinationType.FitBV: Left = destination.Elements.GetReal(2); break; default: throw new ArgumentOutOfRangeException(); } } //#pragma warning restore 162 // ReSharper restore HeuristicUnreachableCode }
/// <summary> /// Adds the specified PdfPage to this document and maybe returns a new PdfPage object. /// The value returned is a new object if the added page comes from a foreign document. /// </summary> public PdfPage Add(PdfPage page) { return(Insert(Count, page)); }
/// <summary> /// Initializes a new instance of the <see cref="PdfOutline"/> class. /// </summary> /// <param name="title">The outline text.</param> /// <param name="destinationPage">The destination page.</param> /// <param name="opened">Specifies whether the node is displayed expanded (opened) or collapsed.</param> public PdfOutline(string title, PdfPage destinationPage, bool opened) { Title = title; DestinationPage = destinationPage; Opened = opened; }
/// <summary> /// Removes the specified page from the document. /// </summary> public void Remove(PdfPage page) { PagesArray.Elements.Remove(page.Reference); Elements.SetInteger(PdfPages.Keys.Count, PagesArray.Elements.Count); }
// create charges file public void CreateCharges(string nom, string prenom, string niveau) { // Create a new PDF document PdfSharp.Pdf.PdfDocument document = new PdfSharp.Pdf.PdfDocument(); document.Info.Title = "Created with PDFsharp"; // Create an empty page PdfSharp.Pdf.PdfPage page = document.AddPage(); // Get an XGraphics object for drawing page.Size = PageSize.A5; page.Orientation = PageOrientation.Landscape; XGraphics gfx = XGraphics.FromPdfPage(page); // Create a font XFont fonti = new XFont("Verdana", 20, XFontStyle.Regular); XFont font = new XFont("Verdana", 16, XFontStyle.Regular); XFont fonta = new XFont("Verdana", 12, XFontStyle.Regular); // create an image string fileLocation = System.IO.Path.Combine(Environment.CurrentDirectory, @"Bridges.png"); XImage img = XImage.FromFile(fileLocation); const double tx = 190, ty = 100, txa = 1010; double wid = img.PixelWidth * 18 / img.HorizontalResolution; double hei = img.PixelHeight * 18 / img.HorizontalResolution; gfx.DrawImage(img, (tx - wid) / 2, (ty - hei) / 2, wid, hei); gfx.DrawImage(img, (txa - wid) / 2, (ty - hei) / 2, wid, hei); // Draw the text gfx.DrawString("Bridges Of Knowledge Center", font, XBrushes.Black, new XRect(0, -160, page.Width, page.Height), XStringFormats.Center); gfx.DrawString("Nom: " + nom, font, XBrushes.Black, new XRect(-(180 - nom.Length * 4), -50, page.Width, page.Height), XStringFormats.Center); gfx.DrawString("Prenom: " + prenom, font, XBrushes.Black, new XRect(-(168 - prenom.Length * 4), -10, page.Width, page.Height), XStringFormats.Center); gfx.DrawString("Niveau: " + niveau, font, XBrushes.Black, new XRect(-(172 - niveau.Length * 4), 30, page.Width, page.Height), XStringFormats.Center); gfx.DrawString("Paiement: 400 DZD", font, XBrushes.Black, new XRect(-162, 70, page.Width, page.Height), XStringFormats.Center); gfx.DrawString("Le : " + DateTime.Now.ToString("dd/MM/yyyy", new CultureInfo("fr-FR")), fonta, XBrushes.Black, new XRect(180, 120, page.Width, page.Height), XStringFormats.Center); gfx.DrawString("à : " + DateTime.Now.ToString("hh:mm tt"), fonta, XBrushes.Black, new XRect(174, 140, page.Width, page.Height), XStringFormats.Center); gfx.DrawString("© " + DateTime.Now.Year + ".", fonta, XBrushes.Black, new XRect(0, 200, page.Width, page.Height), XStringFormats.Center); XPen pen = new XPen(XColors.Navy, .5); gfx.DrawLine(pen, 70, 365, 520, 365); gfx.DrawString("Cité Hchachna en face CEM 1272 - Batna.", fonta, XBrushes.Black, new XRect(-135, 165, page.Width, page.Height), XStringFormats.Center); gfx.DrawString("Fixe : 033 28 30 67. Mobile : 0655 16 09 34", fonta, XBrushes.Black, new XRect(135, 165, page.Width, page.Height), XStringFormats.Center); XImage image = XImage.FromFile(@"face.png"); XImage imagea = XImage.FromFile(@"twitter.png"); XImage imageb = XImage.FromFile(@"insta.png"); XImage imagec = XImage.FromFile(@"google.png"); XImage imaged = XImage.FromFile(@"link.png"); const double dx = 500, dy = 790, dxa = 550, dxb = 600, dxc = 650, dxd = 700; double width = image.PixelWidth * 4.5 / image.HorizontalResolution; double height = image.PixelHeight * 4.5 / image.HorizontalResolution; gfx.DrawImage(image, (dx - width) / 2, (dy - height) / 2, width, height); gfx.DrawImage(imagea, (dxa - width) / 2, (dy - height) / 2, width, height); gfx.DrawImage(imageb, (dxb - width) / 2, (dy - height) / 2, width, height); gfx.DrawImage(imagec, (dxc - width) / 2, (dy - height) / 2, width, height); gfx.DrawImage(imaged, (dxd - width) / 2, (dy - height) / 2, width, height); // Save the document... FillExcelYear(nom, prenom, niveau, username); // Process open file dialog box results string mira = i + "spec.pdf"; string petha = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Printex"); document.Save(System.IO.Path.Combine(petha, mira)); // ...and start a viewer. //Process.Start(mira); var prima = new Imprimir(); prima.Viewer.Navigate(System.IO.Path.Combine(petha, mira)); prima.Show(); }
/// <summary> /// Initializes a new instance of the <see cref="PdfOutline"/> class. /// </summary> /// <param name="title">The outline text.</param> /// <param name="destinationPage">The destination page.</param> public PdfOutline(string title, PdfPage destinationPage) { Title = title; DestinationPage = destinationPage; }
private async void button2_Click(object sender, EventArgs e) { client = new FireSharp.FirebaseClient(config); if (!nameBox.Text.Equals(null) || !unameBox.Text.Equals(null) || !passBox1.Text.Equals(null) || !passBox2.Text.Equals(null) || !hstudyBox.Text.Equals(null) || !desigBox.Text.Equals(null) || !phnBox.Text.Equals(null) || !mailBox.Text.Equals(null) || !idBox.Text.Equals(null) || deptCBox.SelectedIndex == -1 || sessionBox.SelectedIndex == -1 || pictureBox1.Image == null) { if (passBox1.Text.Equals(passBox2.Text)) { StudentData d = new StudentData(); d.id = hstudyBox.Text; d.pass = passBox1.Text; SetResponse res = null; if (uType.Equals("Student")) { res = await client.SetTaskAsync("Student" + "Login/" + sessionBox.SelectedItem.ToString() + "/" + ch3 + unameBox.Text, d); } else if (uType.Equals("Alumni")) { AlumniData d1 = new AlumniData(); d1.name = nameBox.Text; d1.id = idBox.Text; d1.pass = passBox1.Text; d1.hStudy = hstudyBox.Text; d1.desig = desigBox.Text; d1.pAddrees = paddressBox.Text; d1.phn = phnBox.Text; d1.mailid = mailBox.Text; String picSource = "D://3-1//Project c#//StudentTeacher//picSource//" + unameBox.Text + sessionBox.SelectedItem.ToString() + ".jpg"; d1.picid = picSource; res = await client.SetTaskAsync("AlumniLogin/" + ch3 + "/" + sessionBox.SelectedItem.ToString() + "/" + unameBox.Text, d1); File.Delete(picSource); //MessageBox.Show(imgLoc + " " + picSource); System.IO.File.Copy(imgLoc, picSource); //MessageBox.Show(imgLoc+" "+picSource); String text = "\nName: " + nameBox.Text + "\nId: " + idBox.Text + "\nHigher Study Info: " + hstudyBox.Text + "\nDesignation: " + desigBox.Text + "\nPressent Address: " + paddressBox.Text + "\nContact No.: " + phnBox.Text + "\nEmai: " + mailBox.Text + "\nDepartment: " + deptCBox.SelectedItem.ToString() + "\nSession: " + sessionBox.SelectedItem.ToString(); PdfSharp.Pdf.PdfDocument document = new PdfSharp.Pdf.PdfDocument(); PdfSharp.Pdf.PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XFont font = new XFont("Times New Roman", 10, XFontStyle.Bold); PdfSharp.Drawing.Layout.XTextFormatter tf = new PdfSharp.Drawing.Layout.XTextFormatter(gfx); XRect rect = new XRect(40, 100, 250, 220); gfx.DrawRectangle(XBrushes.SeaShell, rect); tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft); string pdfFilename = "D://3-1//Project c#//StudentTeacher//pdfSource//" + sessionBox.SelectedItem.ToString() + unameBox.Text + ".pdf"; document.Save(pdfFilename); Process.Start(pdfFilename); if (d1.pass.Equals(passBox1.Text)) { MessageBox.Show("Registration Successfull.."); this.Hide(); } } else if (uType.Equals("Teacher")) { res = await client.SetTaskAsync(uType + "Login/" + unameBox.Text, d); } } else { MessageBox.Show("Passwords Are Not Identical.."); } } else { MessageBox.Show("Some Fields are Not yet Filled or Selected...."); } }
// create a preview public void CreatePreview() { XRect rect; XPen pen; PdfSharp.Pdf.PdfDocument document = new PdfSharp.Pdf.PdfDocument(); document.Info.Title = "Created with PDFsharp"; // Create an empty page PdfSharp.Pdf.PdfPage page = document.AddPage(); // Get an XGraphics object for drawing page.Size = PageSize.A5; page.Orientation = PageOrientation.Landscape; XGraphics gfx = XGraphics.FromPdfPage(page); double x = 50, y = 100; XFont fontH1 = new XFont("Times", 18, XFontStyle.Bold); XFont font = new XFont("Times", 12); XFont fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic); double ls = font.GetHeight(gfx); // Draw some text gfx.DrawString("Create PDF on the fly with PDFsharp", fontH1, XBrushes.Black, x, x); gfx.DrawString("With PDFsharp you can use the same code to draw graphic, " + "text and images on different targets.", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("The object used for drawing is the XGraphics object.", font, XBrushes.Black, x, y); y += 2 * ls; // Draw an arc pen = new XPen(XColors.Red, 4); pen.DashStyle = XDashStyle.Dash; gfx.DrawArc(pen, x + 20, y, 100, 60, 150, 120); // Draw a star XGraphicsState gs = gfx.Save(); gfx.TranslateTransform(x + 140, y + 30); for (int idx = 0; idx < 360; idx += 10) { gfx.RotateTransform(10); gfx.DrawLine(XPens.DarkGreen, 0, 0, 30, 0); } gfx.Restore(gs); // Draw a rounded rectangle rect = new XRect(x + 230, y, 100, 60); pen = new XPen(XColors.DarkBlue, 2.5); XColor color1 = XColor.FromKnownColor(KnownColor.DarkBlue); XColor color2 = XColors.Red; XLinearGradientBrush lbrush = new XLinearGradientBrush(rect, color1, color2, XLinearGradientMode.Vertical); gfx.DrawRoundedRectangle(pen, lbrush, rect, new XSize(10, 10)); // Draw a pie pen = new XPen(XColors.DarkOrange, 1.5); pen.DashStyle = XDashStyle.Dot; gfx.DrawPie(pen, XBrushes.Blue, x + 360, y, 100, 60, -130, 135); // Draw some more text y += 60 + 2 * ls; gfx.DrawString("With XGraphics you can draw on a PDF page as well as on any System.Drawing.Graphics object.", font, XBrushes.Black, x, y); y += ls * 1.1; gfx.DrawString("Use the same code to", font, XBrushes.Black, x, y); x += 10; y += ls * 1.1; gfx.DrawString("• draw on a newly created PDF page", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw above or beneath of the content of an existing PDF page", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw in a window", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw on a printer", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw in a bitmap image", font, XBrushes.Black, x, y); x -= 10; y += ls * 1.1; gfx.DrawString("You can also import an existing PDF page and use it like an image, e.g. draw it on another PDF page.", font, XBrushes.Black, x, y); y += ls * 1.1 * 2; gfx.DrawString("Imported PDF pages are neither drawn nor printed; create a PDF file to see or print them!", fontItalic, XBrushes.Firebrick, x, y); y += ls * 1.1; gfx.DrawString("Below this text is a PDF form that will be visible when viewed or printed with a PDF viewer.", fontItalic, XBrushes.Firebrick, x, y); y += ls * 1.1; XGraphicsState state = gfx.Save(); XRect rcImage = new XRect(100, y, 100, 100 * Math.Sqrt(2)); gfx.DrawRectangle(XBrushes.Snow, rcImage); string kara = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Printex"); gfx.DrawImage(XPdfForm.FromFile(System.IO.Path.Combine(kara, "slother.pdf")), rcImage); gfx.Restore(state); }
public void Reset() { this.currentElement = null; this.index = -1; }
private bool IsPageSplit(PdfSharp.Pdf.PdfPage page) { return(page.Annotations.Count == 1 && GetUrlLink(page.Annotations[0]) == SplitDocumentUri); }
void DrawPageHeading(PdfSharp.Pdf.PdfPage page, XGraphics gfx, MimeMessage message) { var From = message.From.ToString(); From = Regex.Replace(From, @"""", ""); var ResentDate = message.ResentDate.DateTime.ToString(); var Date = message.Date.DateTime.ToString(); var To = message.To.ToString(); To = Regex.Replace(To, @"""", ""); var Subject = message.Subject; string filer = ""; foreach (var msg_attachment in message.Attachments) { if ((msg_attachment is MimePart)) { var part = msg_attachment as MimePart; if (filer.Length > 0) { filer += "," + part.FileName; } else { filer += part.FileName; } } } // HACK² gfx.MUH = PdfFontEncoding.Unicode; gfx.MFEH = PdfFontEmbedding.Default; // You always need a MigraDoc document for rendering. MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document(); // Create a new style called Table based on style Normal var style = doc.Styles.AddStyle("Table", "Normal"); style.Font.Name = "Verdana"; style.Font.Name = "Arial"; style.Font.Size = 9; Section sec = doc.AddSection(); var table = sec.AddTable(); table.Style = "Table"; // Before you can add a row, you must define the columns Column column = table.AddColumn("3cm"); column.Format.Alignment = ParagraphAlignment.Left; column = table.AddColumn("17cm"); column.Format.Alignment = ParagraphAlignment.Left; Row row = table.AddRow(); row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph("Fra:"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Left; row.Cells[1].Borders.Visible = false; row.Cells[1].AddParagraph(From); row.Cells[1].Format.Font.Bold = false; row.Cells[1].Format.Alignment = ParagraphAlignment.Left; row.Format.SpaceAfter = 2; row = table.AddRow(); row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph("Sendt: "); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Left; row.Cells[1].Borders.Visible = false; row.Cells[1].AddParagraph(Date); row.Cells[1].Format.Font.Bold = false; row.Cells[1].Format.Alignment = ParagraphAlignment.Left; row.Format.SpaceAfter = 2; row = table.AddRow(); row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph("Til:"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Left; row.Cells[1].Borders.Visible = false; row.Cells[1].AddParagraph(To); row.Cells[1].Format.Font.Bold = false; row.Cells[1].Format.Alignment = ParagraphAlignment.Left; row.Format.SpaceAfter = 2; row = table.AddRow(); row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph("Emne:"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Left; row.Cells[1].Borders.Visible = false; row.Cells[1].AddParagraph(Subject); row.Cells[1].Format.Font.Bold = false; row.Cells[1].Format.Alignment = ParagraphAlignment.Left; if (filer.Length > 0) { row.Format.SpaceAfter = 2; row = table.AddRow(); row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph("Vedhæftede filer:"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Left; row.Cells[1].Borders.Visible = false; row.Cells[1].AddParagraph(filer); row.Cells[1].Format.Font.Bold = false; row.Cells[1].Format.Alignment = ParagraphAlignment.Left; } // Create a renderer and prepare (=layout) the document MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc); docRenderer.PrepareDocument(); var box = page.MediaBox.ToXRect(); box.Inflate(-20, -25); // Render the paragraph. You can render tables or shapes the same way. docRenderer.RenderObject(gfx, box.Location.X, box.Location.X, box.Width, table); }