PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Oct 19, 2024 9:57 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Aug 03, 2007 9:57 pm 
Offline

Joined: Fri Aug 03, 2007 9:40 pm
Posts: 1
Enhanced Metafiles (EMF) are vector files capable of high resolution graphics and small in size.

Open test.emf in Windows Picture and Fax Viewer and try the zoom :D


Change miBmp_Click in '\Samples C#\DocumentViewer\Viewer.cs' to the following.

Code:
    private void miBmp_Click(object sender, System.EventArgs e)
    {
      int page = this.pagePreview.Page;

      // Reuse the renderer from the preview
      DocumentRenderer renderer = this.pagePreview.Renderer;
      PageInfo info = renderer.FormattedDocument.GetPageInfo(page);

      // Create an image
      int dpi = 150;
      int dx, dy;
      if (info.Orientation == PdfSharp.PageOrientation.Portrait)
      {
        dx = (int)(info.Width.Inch * dpi);
        dy = (int)(info.Height.Inch * dpi);
      }
      else
      {
        dx = (int)(info.Height.Inch * dpi);
        dy = (int)(info.Width.Inch * dpi);
      }

//      Image image = new Bitmap(dx, dy, PixelFormat.Format32bppRgb);

      // Get the graphics object for creating the metafile
      FileStream fileStream = new FileStream("test.emf", FileMode.OpenOrCreate, FileAccess.Write);
       Graphics gr = CreateGraphics();
      IntPtr hDC = gr.GetHdc();

      Metafile image = new Metafile(fileStream, hDC, new Rectangle(0, 0, dx, dy), MetafileFrameUnit.Pixel, EmfType.EmfPlusOnly);

      // Don't need this graphics object any more
      gr.ReleaseHdc(hDC);
      gr.Dispose();

      // Create a Graphics object for the image and scale it for drawing with 72 dpi
      Graphics graphics = Graphics.FromImage(image);
      graphics.Clear(System.Drawing.Color.White);
      float scale = dpi / 72f;
      graphics.ScaleTransform(scale, scale);

     // Create an XGraphics object and render the page
     XGraphics gfx = XGraphics.FromGraphics(graphics, new XSize(info.Width.Point, info.Height.Point));
     renderer.RenderPage(gfx, page);
     gfx.Dispose();

      // Close the file
      fileStream.Close();

//      image.Save("test.png", ImageFormat.Png);

      Process.Start("mspaint", "test.emf");  // Use MSPaint, not Photoshop...
//      Process.Start("mspaint", "test.png");  // Use MSPaint, not Photoshop...
    }


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 24, 2008 11:15 pm 
Offline
Supporter

Joined: Sat Oct 18, 2008 4:15 pm
Posts: 50
cool deal
what's the point ?
is it possible to add this int migradoc document afterwards ?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri May 22, 2009 6:14 am 
Offline

Joined: Fri May 22, 2009 6:11 am
Posts: 4
Very useful when your application needs to render to more than PDF. e.g. Using one bit of drawing code (using XGraphics) can draw metafiles for the clipboard, PDFs for saving to file, and using normal Graphics objects to print and for screen display.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 33 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group