Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8995091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:34:23+00:00 2026-06-15T23:34:23+00:00

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.IO; using System.Drawing;

  • 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Drawing;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;

namespace Lightnings_Extractor
{
    class PDF
    {
        public PDF()
        {
            // Create a new PDF document
            PdfDocument document = new PdfDocument();
            document.Info.Title = "Created with PDFsharp";

            // Create an empty page
            PdfPage page = document.AddPage(); 
            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page); 
            // Create a font
            XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic); 
            // Draw the text
            gfx.DrawString("Hello, World!", font, XBrushes.Black,
            new XRect(0, 0, page.Width, page.Height),
            XStringFormats.Center); 
            // Save the document...
            const string filename = @"d:\HelloWorld.pdf";
            document.Save(filename);
            // ...and start a viewer.
            Process.Start(filename);
        }

        private void DrawImage(XGraphics gfx, int number)
        {
        }
    }
}

I’m taking the sample from this link: http://www.pdfsharp.net/wiki/Graphics-sample.ashx
There is a sample there: Draw an image in original size

void DrawImage(XGraphics gfx, int number)
{
  BeginBox(gfx, number, "DrawImage (original)");

  XImage image = XImage.FromFile(jpegSamplePath);

  // Left position in point
  double x = (250 - image.PixelWidth * 72 / image.HorizontalResolution) / 2;
  gfx.DrawImage(image, x, 0);

  EndBox(gfx);
}

What am I missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:34:24+00:00Added an answer on June 15, 2026 at 11:34 pm

    BeginBox and EndBox are helper methods defined at the bottom of the sample page.

    Note that these methods are only to create the surrounding box and is probably not what you need to achieve the functionality you really want (in this case, to draw an image in original size). So I would just remove those two lines from the code.

    public void BeginBox(XGraphics gfx, int number, string title)
    {
      const int dEllipse = 15;
      XRect rect = new XRect(0, 20, 300, 200);
      if (number % 2 == 0)
        rect.X = 300 - 5;
      rect.Y = 40 + ((number - 1) / 2) * (200 - 5);
      rect.Inflate(-10, -10);
      XRect rect2 = rect;
      rect2.Offset(this.borderWidth, this.borderWidth);
      gfx.DrawRoundedRectangle(new XSolidBrush(this.shadowColor), rect2, new XSize(dEllipse + 8, dEllipse + 8));
      XLinearGradientBrush brush = new XLinearGradientBrush(rect, this.backColor, this.backColor2, XLinearGradientMode.Vertical);
      gfx.DrawRoundedRectangle(this.borderPen, brush, rect, new XSize(dEllipse, dEllipse));
      rect.Inflate(-5, -5);
    
      XFont font = new XFont("Verdana", 12, XFontStyle.Regular);
      gfx.DrawString(title, font, XBrushes.Navy, rect, XStringFormats.TopCenter);
    
      rect.Inflate(-10, -5);
      rect.Y += 20;
      rect.Height -= 20;
    
      this.state = gfx.Save();
      gfx.TranslateTransform(rect.X, rect.Y);
    }
    
    public void EndBox(XGraphics gfx)
    {
      gfx.Restore(this.state);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Diagnostics { class Program {
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace ConsoleApplication1 { class
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace EfTestFactory { public abstract class
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Text; namespace secondMvc.MyControls
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
This is my problem: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1
I have the following code using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.IO; using System.Xml; using System.Xml.Linq;
This C#/WPF code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.