I'm using Rotativa to generate PDFs from Html Razor views.
v1.5.0 display images correctly, but doesn't paginate correctly
v1.6.1 correctly paginates from the html, but "ghosts" the images Per this bug:
this is because of wkhtmltopdf which has a bug... it's supposed to be fixed in the trunk, but it's not in the versions I downloaded from their page.
The workaround is to convert the JPEG to one of the other "not jacked up" image formats..
In our case we converted to PNG. There is some loss of clarity, but we can live with that.
try
{
byte [] byteArrayIn = ( byte[] )@Model.ETA640StudentProfileVM[ currentRecord ].ImageObj;
byte[] byteArrayOut = null;
MemoryStream ms = new MemoryStream( byteArrayIn, 0, byteArrayIn.Length );
ms.Write( byteArrayIn, 0, byteArrayIn.Length );
Image returnImage = Image.FromStream( ms, true );
using (var output = new MemoryStream())
{
returnImage.Save( output, System.Drawing.Imaging.ImageFormat.Png );
byteArrayOut = output.ToArray();
};
@:<img src="data:image/png;base64,@(Html.Raw( Convert.ToBase64String( byteArrayOut )))" alt="Image Not Available" height="155" />
}
catch
{
@:<img src="" alt="Error Generating Image" height="155" />
}
Wednesday, April 16, 2014
Thursday, March 27, 2014
Memory Leak doing alot of NHibernate processing in a loop?
Do you have a memory leak using NHibernate?
Are you doing a lot of processing in a loop, get, process, save, repeat,?
Well, firstly it's not really a leak... it's how Nhibernate works, and seeing as a leak
indicates you're probably not using NHibernate remotely how it's supposed to be used...
But then again , so are we... I have a winforms application generating reports for lots of students in a row... Once processed I'm completely done with the student and not going back...
So I needed to flush everything out of the Nhibernate cache, both layer 1 and 2.
Now If you're going to use this realize it almost certainly means you're using Nhibernate incorrectly...
and you'd probably be better off just going back to Ado... more speed, less memory used...
But that said, here's how to flush it all
SuperFlushJcdcSessionFirstAndSecondCaches();
Ha Hah just kidding, here's the part you really want...
public void SuperFlushJcdcSessionFirstAndSecondCaches(
{
INHFactory eFolderDocFactory = ObjectFactory.GetNamedInstance<INHFactory>( "JCDC" );
ISessionFactory sessionFactory = eFolderDocFactory.GetFactory();
// FROM http://stackoverflow.com/questions/2660714/how-to-clear-the-entire-second-level-cache-in-nhibernate - EWB
sessionFactory.EvictQueries();
foreach ( var collectionMetadata in sessionFactory.GetAllCollectionMetadata() )
{ sessionFactory.EvictCollection( collectionMetadata.Key );
}
foreach ( var classMetadata in sessionFactory.GetAllClassMetadata() )
{ sessionFactory.EvictEntity( classMetadata.Key )
}
}
Are you doing a lot of processing in a loop, get, process, save, repeat,?
Well, firstly it's not really a leak... it's how Nhibernate works, and seeing as a leak
indicates you're probably not using NHibernate remotely how it's supposed to be used...
But then again , so are we... I have a winforms application generating reports for lots of students in a row... Once processed I'm completely done with the student and not going back...
So I needed to flush everything out of the Nhibernate cache, both layer 1 and 2.
Now If you're going to use this realize it almost certainly means you're using Nhibernate incorrectly...
and you'd probably be better off just going back to Ado... more speed, less memory used...
But that said, here's how to flush it all
SuperFlushJcdcSessionFirstAndSecondCaches();
Ha Hah just kidding, here's the part you really want...
public void SuperFlushJcdcSessionFirstAndSecondCaches(
{
INHFactory eFolderDocFactory = ObjectFactory.GetNamedInstance<INHFactory>( "JCDC" );
ISessionFactory sessionFactory = eFolderDocFactory.GetFactory();
// FROM http://stackoverflow.com/questions/2660714/how-to-clear-the-entire-second-level-cache-in-nhibernate - EWB
sessionFactory.EvictQueries();
foreach ( var collectionMetadata in sessionFactory.GetAllCollectionMetadata() )
{ sessionFactory.EvictCollection( collectionMetadata.Key );
}
foreach ( var classMetadata in sessionFactory.GetAllClassMetadata() )
{ sessionFactory.EvictEntity( classMetadata.Key )
}
}
Friday, March 7, 2014
Brace Matching Hotkeys in Visual Studio...
I'm sure most of you are know about the matching brace highlighting feature in Visual Studio...
If you double click to select a brace, it's matching brace is highlighted in the same color...
Great, awesome for the file types where it works.. but what about the file types where it DOESN'T work?
Here where my tip of the <however often I decide to add tips> comes in...
In any file, say a razor view, click next to a brace, hit <ctrl>, ]... It jumps to the matching brace...
Bam,
Darn handy.
(I use resharper and the resharper keyboard settings , so YMMV, etc)
Sunday, February 23, 2014
Saturday, February 15, 2014
Flow jet cutting from an illustrator file.
There is a special export trick for exporting AI files to work in flow.
It's on page 8 of the flowjet SBU document
here it is in summary
edit_>preferences->units make sure it's inches
File-> save as-> save as .ai file
when you click save, in teh top field select "illustrator 3" as your version #
openthe file in corel draw
gott file-> export, delct DXF - AutoCad
when you select export in the top field select "autocad r10"
the segments will be disconnected bu flowpath can autopath it.
There is a special export trick for exporting AI files to work in flow.
It's on page 8 of the flowjet SBU document
here it is in summary
edit_>preferences->units make sure it's inches
File-> save as-> save as .ai file
when you click save, in teh top field select "illustrator 3" as your version #
openthe file in corel draw
gott file-> export, delct DXF - AutoCad
when you select export in the top field select "autocad r10"
the segments will be disconnected bu flowpath can autopath it.
Friday, January 17, 2014
RDLC alternating row color, by group instead of by line
A common task in RDLC reporting is alternate row styling, here are the 3 most common types.
Regular alternating row styles
= iif(RowNumber(Nothing) mod 2, "LightGrey", "Transparent")
Alternating group colors:
http://bidn.com/blogs/briankmcdonald/bidn-blog/713/alternating-group-colors
Alternating group colors with alternating row colors inside the group.
http://www.bidn.com/blogs/briankmcdonald/bidn-blog/717/alternating-group-colors-and-alternating-row-colors
Regular alternating row styles
= iif(RowNumber(Nothing) mod 2, "LightGrey", "Transparent")
Alternating group colors:
http://bidn.com/blogs/briankmcdonald/bidn-blog/713/alternating-group-colors
Alternating group colors with alternating row colors inside the group.
http://www.bidn.com/blogs/briankmcdonald/bidn-blog/717/alternating-group-colors-and-alternating-row-colors
Wednesday, September 4, 2013
Structuremap 202 errors..... The two most powerful lines for fixing 202 type errors in Structure map.
If you are using strcutrue map you are familiar with 202 errors.
If you've seen my list of them and their causes it's a big help in fixing them.
Either way here are two powerful lines for diagnosing what's wrong.
#1:
Debug.WriteLine( ObjectFactory.WhatDoIHave() );
Writes out everything loaded by Structure map... like this:
....
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ICodeDAL (JCDCHelper.DBCodes.Interfaces.ICodeDAL) JCDCHelper.DBCodes.DataObjects.CodeDAL, JCDCHelper.DBCodes, Version=3.1.2.2, Culture=neutral, PublicKeyToken=null JCDCHelper.DBCodes.DataObjects.CodeDAL, JCDCHelper.DBCodes, Version=3.1.2.2, Culture=neutral, PublicKeyToken=null
Scoped as: PerRequest
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ISpamisCodeDAL (JCDCHelper.DBCodes.Interfaces.ISpamisCodeDAL) JCDCHelper.DBCodes.DataObjects.SpamisCodeDAL, JCDCHelper.DBCodes, Version=3.1.2.2, Culture=neutral, PublicKeyToken=null JCDCHelper.DBCodes.DataObjects.SpamisCodeDAL, JCDCHelper.DBCodes, Version=3.1.2.2, Culture=neutral, PublicKeyToken=null
Scoped as: PerRequest
....
and #2:
ObjectFactory.AssertConfigurationIsValid();
Looks for obvious errors and gives you better information to fix them... are you haunted by the words "Or one of it's dependencies" this is the tool for you.
Give them a try... Not magic bullets, but a huge help.
Good luck
Cal-
If you've seen my list of them and their causes it's a big help in fixing them.
Either way here are two powerful lines for diagnosing what's wrong.
#1:
Debug.WriteLine( ObjectFactory.WhatDoIHave() );
Writes out everything loaded by Structure map... like this:
....
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ICodeDAL (JCDCHelper.DBCodes.Interfaces.ICodeDAL) JCDCHelper.DBCodes.DataObjects.CodeDAL, JCDCHelper.DBCodes, Version=3.1.2.2, Culture=neutral, PublicKeyToken=null JCDCHelper.DBCodes.DataObjects.CodeDAL, JCDCHelper.DBCodes, Version=3.1.2.2, Culture=neutral, PublicKeyToken=null
Scoped as: PerRequest
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ISpamisCodeDAL (JCDCHelper.DBCodes.Interfaces.ISpamisCodeDAL) JCDCHelper.DBCodes.DataObjects.SpamisCodeDAL, JCDCHelper.DBCodes, Version=3.1.2.2, Culture=neutral, PublicKeyToken=null JCDCHelper.DBCodes.DataObjects.SpamisCodeDAL, JCDCHelper.DBCodes, Version=3.1.2.2, Culture=neutral, PublicKeyToken=null
Scoped as: PerRequest
....
and #2:
ObjectFactory.AssertConfigurationIsValid();
Looks for obvious errors and gives you better information to fix them... are you haunted by the words "Or one of it's dependencies" this is the tool for you.
Give them a try... Not magic bullets, but a huge help.
Good luck
Cal-
Subscribe to:
Posts (Atom)