This project has moved. For the latest updates, please go here.

Command in Magick.net

Feb 26, 2015 at 2:38 PM
Hi I would like to setup PageSize using Magick.net
I need equalent method for this -define pdf:use-cropbox=true or -define pdf:use-trimbox=true
I have tried few things but nothing worked.
Could you any one help with the code in Magick.Net
Coordinator
Feb 26, 2015 at 9:22 PM
Edited Feb 26, 2015 at 9:23 PM
I am working on some new classes to make this easier. The one for PDF will be available in the next release of Magick.NET. You can then use the following code:
// You will be able to do this in the next release of Magick.NET
MagickReadSettings settings = new MagickReadSettings()
{
  Defines = new PdfReadDefines()
  {
    UseCropBox = true,
    UseTrimBox = false
  }
};

using (MagickImage image = new MagickImage("yourfile.pdf", settings))
{
}

// For now you will have to do this
using (MagickImage image = new MagickImage())
{
  image.SetDefine(MagickFormat.Pdf, "use-cropbox", true);
  image.SetDefine(MagickFormat.Pdf, "use-trimbox", false);
  image.Read("yourfile.pdf");
}
Feb 27, 2015 at 9:05 AM
Edited Feb 27, 2015 at 9:08 AM
Thank you for your reply.
This is very useful.
Is the below code works If I want to set use-cropbox true in MagicReadSettings?
  MagickReadSettings settings = new MagickReadSettings()
  {               
       Density = new MagickGeometry(300, 300) 
   };
   newSettings.SetDefine(MagickFormat.Pdf, "use-cropbox", "true");
   newSettings.SetDefine(MagickFormat.Pdf, "use-trimbox", "false");
Will above code behave same as below
 using (MagickImage image = new MagickImage())
  {
  image.SetDefine(MagickFormat.Pdf, "use-cropbox", true);
  image.SetDefine(MagickFormat.Pdf, "use-trimbox", false);
  image.Read("yourfile.pdf");
  }
Feb 27, 2015 at 9:34 AM
The below code behaves same and works as expected :) :)
       MagickReadSettings settings = new MagickReadSettings()
      {               
              Density = new MagickGeometry(300, 300) 
       };
       newSettings.SetDefine(MagickFormat.Pdf, "use-cropbox", "true");
       newSettings.SetDefine(MagickFormat.Pdf, "use-trimbox", "false");
Thank you once again for the help
It saved lot of time to me :) :)
Coordinator
Feb 27, 2015 at 9:51 AM
You are correct, the example above does the same. I am planning a new release this weekend so you could change your code to use the PdfReadDefines class then.
Feb 27, 2015 at 3:05 PM
Thank you.
Good to know that new release will be soon