Git Product home page Git Product logo

Comments (7)

hahmed avatar hahmed commented on September 14, 2024

Does #4 fix this issue? I could move out the helper into its own class and make a pull request if that is the only feature outstanding?

from wkhtmltoxsharp.

pruiz avatar pruiz commented on September 14, 2024

Hi Haroon,

The feature you are asking for it's implemented in this pull-request
#4 which I have not been able
to merge yet due to time constraints. As I cannot apply a direct merge
using github due to some minor issues.

Pablo

On Mon, Apr 16, 2012 at 3:02 PM, Haroon <
[email protected]

wrote:

I was wondering how do I set the page width/size?

WkhtmlToPDF (according to
http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html)

Exposes the option –-page-width


Reply to this email directly or view it on GitHub:
#6

from wkhtmltoxsharp.

hahmed avatar hahmed commented on September 14, 2024

I have tested the width and height from this pull request #4, but it throws a memory is currupt exception?

from wkhtmltoxsharp.

pruiz avatar pruiz commented on September 14, 2024

Hi,

How are you testing your code changes? Memory corruption issues are
normally related to incorrect usage of the component by using it from
two or more consecutive app. Domains.. Which provokes a corruption of
the underlaying library memory..

Keep in mind that tlwe are using a native library under the hood

Sent from my iPhone

On 17/04/2012, at 12:11, Haroon
[email protected]
wrote:

I have tested the width and height from this pull request #4, but it throws a memory is currupt exception?


Reply to this email directly or view it on GitHub:
#6 (comment)

from wkhtmltoxsharp.

hahmed avatar hahmed commented on September 14, 2024

I am running my code inside an asp.net mvc controller - the code is run on the default server from visual studio... I am not running an Async controller.

This works without using the Page Width or Page Height props... As soon as I use those two properties I get the exception...

    private MultiplexingConverter _GetConverter()
    {
        var obj = new MultiplexingConverter();
        //obj.Begin += (s, e) => _Log.DebugFormat("Conversion begin, phase count: {0}", e.Value);
        //obj.Error += (s, e) => _Log.Error(e.Value);
        //obj.Warning += (s, e) => _Log.Warn(e.Value);
        //obj.PhaseChanged += (s, e) => _Log.InfoFormat("PhaseChanged: {0} - {1}", e.Value, e.Value2);
        //obj.ProgressChanged += (s, e) => _Log.InfoFormat("ProgressChanged: {0} - {1}", e.Value, e.Value2);
        //obj.Finished += (s, e) => _Log.InfoFormat("Finished: {0}", e.Value ? "success" : "failed!");
        return obj;
    }

    private byte[] GetMyPdf()
    {
        using (var wk = _GetConverter())
        {
            wk.GlobalSettings.Margin.Top = "2cm";
            wk.GlobalSettings.Margin.Bottom = "2cm";
            wk.GlobalSettings.Margin.Left = "2cm";
            wk.GlobalSettings.Margin.Right = "2cm";

            wk.GlobalSettings.Size.PageSize = PdfPageSize.A4; //works

            //wk.GlobalSettings.Size.Height= 40; // does not works
           // wk.GlobalSettings.Size.Width=20; //does not works



            wk.ObjectSettings.Web.EnablePlugins = false;
            wk.ObjectSettings.Web.EnableJavascript = false;

            using (var stream = new MemoryStream(ReadHtmlFromFile(@"C:\Projects\test.xhtml")))
            using (var sr = new StreamReader(stream))
            {
                var str = sr.ReadToEnd();
                var tmp = wk.Convert(str);
                return tmp;
            }
        }
    }

    private byte[] ReadHtmlFromFile(string filePath)
    {
        using (FileStream fileStream = System.IO.File.OpenRead(filePath))
        {
            MemoryStream memStream = new MemoryStream();
            memStream.SetLength(fileStream.Length);
            fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length);
            return memStream.ToArray();
        }
    }

My Controller:

public ActionResult GetMePDF()
    {
        var buffer = GetMyPdf();

        return File(buffer, "application/pdf");
    }

from wkhtmltoxsharp.

pruiz avatar pruiz commented on September 14, 2024

Can you try it from a simple console app?

Sent from my iPad

On 17/04/2012, at 14:34, Haroon
[email protected]
wrote:

I am running my code inside an asp.net mvc controller - the code is run on the default server from visual studio... I am not running an Async controller.

This works without using the Page Width or Page Height props... As soon as I use those two properties I get the exception...

   private MultiplexingConverter _GetConverter()
   {
       var obj = new MultiplexingConverter();
       //obj.Begin += (s, e) => _Log.DebugFormat("Conversion begin, phase count: {0}", e.Value);
       //obj.Error += (s, e) => _Log.Error(e.Value);
       //obj.Warning += (s, e) => _Log.Warn(e.Value);
       //obj.PhaseChanged += (s, e) => _Log.InfoFormat("PhaseChanged: {0} - {1}", e.Value, e.Value2);
       //obj.ProgressChanged += (s, e) => _Log.InfoFormat("ProgressChanged: {0} - {1}", e.Value, e.Value2);
       //obj.Finished += (s, e) => _Log.InfoFormat("Finished: {0}", e.Value ? "success" : "failed!");
       return obj;
   }

   private byte[] GetMyPdf()
   {
       using (var wk = _GetConverter())
       {
           wk.GlobalSettings.Margin.Top = "2cm";
           wk.GlobalSettings.Margin.Bottom = "2cm";
           wk.GlobalSettings.Margin.Left = "2cm";
           wk.GlobalSettings.Margin.Right = "2cm";

           wk.ObjectSettings.Web.EnablePlugins = false;
           wk.ObjectSettings.Web.EnableJavascript = false;

           using (var stream = new MemoryStream(ReadHtmlFromFile(@"C:\Projects\devnet\TemplateEditor\TemplateEditor\lib\test.xhtml")))
           using (var sr = new StreamReader(stream))
           {
               var str = sr.ReadToEnd();
               var tmp = wk.Convert(str);
               return tmp;
           }
       }
   }

   private byte[] ReadHtmlFromFile(string filePath)
   {
       using (FileStream fileStream = System.IO.File.OpenRead(filePath))
       {
           MemoryStream memStream = new MemoryStream();
           memStream.SetLength(fileStream.Length);
           fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length);
           return memStream.ToArray();
       }
   }

Reply to this email directly or view it on GitHub:
#6 (comment)

from wkhtmltoxsharp.

pruiz avatar pruiz commented on September 14, 2024

I just published a new version (1.2.5+) supporting PageSize properties (from a pull-req from @tomdenny), so I am closing this issue too.

from wkhtmltoxsharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.