PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How To: Export to EMF insted of BMP

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
patrik



Joined: 03 Aug 2007
Posts: 1

PostPosted: Fri Aug 03, 2007 9:57 pm    Post subject: How To: Export to EMF insted of BMP Reply with quote

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 Very Happy


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...
    }
Back to top
View user's profile Send private message
gastan



Joined: 18 Oct 2008
Posts: 25

PostPosted: Fri Oct 24, 2008 11:15 pm    Post subject: Reply with quote

cool deal
what's the point ?
is it possible to add this int migradoc document afterwards ?
Back to top
View user's profile Send private message
oliverbock



Joined: 22 May 2009
Posts: 2

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

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.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com