Closed hahmed closed 8 years ago
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?
Hi Haroon,
The feature you are asking for it's implemented in this pull-request https://github.com/pruiz/WkHtmlToXSharp/pull/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 < reply@reply.github.com
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: https://github.com/pruiz/WkHtmlToXSharp/issues/6
I have tested the width and height from this pull request #4, but it throws a memory is currupt exception?
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 reply@reply.github.com 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: https://github.com/pruiz/WkHtmlToXSharp/issues/6#issuecomment-5171904
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");
}
Can you try it from a simple console app?
Sent from my iPad
On 17/04/2012, at 14:34, Haroon reply@reply.github.com 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: https://github.com/pruiz/WkHtmlToXSharp/issues/6#issuecomment-5173944
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.
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