cancel
Showing results for 
Search instead for 
Did you mean: 

Setting margins works with ExportToDisk, but not with ExportToStream...

Former Member
0 Kudos

I'm filling out a report with SetParameterValue, and not with database, and setting the margins with:


templateCredencial.ReportDefinition.Sections["DetailSection1"].ReportObjects[elementNumber].Top; 
templateCredencial.ReportDefinition.Sections["DetailSection1"].ReportObjects[elementNumber].Left;

After that when i call ExportToDisk to write as pdf, the margins that i setted are there, but when i use ExportToStream like that:


MemoryStream stream = (MemoryStream)credentialTemplate.ExportToStream(ExportFormatType.PortableDocFormat)

And call stream.ToArray() as return in FileResult, the pdf that shows up on browser is without the margins that i setted. Does anyone have idea how can i return the pdf to the browser with correct margins without get file from disk, using only the stream?

Accepted Solutions (1)

Accepted Solutions (1)

former_member188030
Active Contributor
0 Kudos

Hi,

More information required -

- Version of Crystal Reports with detail patch level

- Version of Visual Studio

- Windows version? 32 or 64 bit?

- win or web app?

Try a sample application with the code given in below SAP Note with a simple report (without parameters).

[1198587 - How to export a report to stream in C Sharp (C#) for Visual Studio .NET |http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333133393338333533383337%7D.do]

See if the sample app reproduces the issue.

Search the forums for the issues related to 'ExportToStream' method.

Thanks,

Bhushan.

Former Member
0 Kudos

@Bhushan Hyalij

More information required -

- Version of Crystal Reports with detail patch level: 2010 ide patch.

- Version of Visual Studio: 2010 ultimate

- Windows version? 32 or 64 bit?: 32bit

- win or web app?: web app (asp.net mvc 3)

former_member188030
Active Contributor
0 Kudos

Take a look at the

[CR for VS 2010 .NET SDK Developer Guide|http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/crnet_dg_2010_en.zip]

[CR for VS 2010 .NET InProc RAS SDK Developer Guide|http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/xi4_rassdk_net_dg_en.zip]

See if you can find the appropriate API's to set the margins at runtime.

Bhushan.

Answers (1)

Answers (1)

0 Kudos

Hello,

When Exporting to Stream CR will use the margins from your default Printer settings, there is no member to alter them in that method.

Change your Margins using the PageMargins function and see if that works. Search the Object Browser to see how.

Thanks

Don

Former Member
0 Kudos

I did this:


PageMargins margins = new PageMargins();
margins = credentialTemplate.PrintOptions.PageMargins;
margins.topMargin = 100;
margins.leftMargin = 100;
credentialTemplate.PrintOptions.ApplyPageMargins(margins);

After:


MemoryStream stream = (MemoryStream)credentialTemplate.ExportToStream(ExportFormatType.PortableDocFormat);
byte[] pdfFile = stream.ToArray();

return File(pdfFile, "application/pdf");

So, same result... nothing happens with the margins, did i right?

0 Kudos

Hello,

I don't know because you did not say what the results were or answer any other questions I asked.

Why can't you simply export to Disk and then stream that file?

Don

Former Member
0 Kudos

I don't know because you did not say what the results were or answer any other questions I asked.

I said what the results were in first post:

And call stream.ToArray() as return in FileResult, the pdf that shows up on browser is without the margins that i setted. Does anyone have idea how can i return the pdf to the browser with correct margins without get file from disk, using only the stream?

And, where are you other questions? Sorry, i didn't see it.

Why can't you simply export to Disk and then stream that file?

I need performance, and if i need to write a pdf with 10mb, and after read it, and next return (with asp.net mvc 3) to browser like a FileResult, i 'll lose performance.

What is the right way to change the margins and return it like a byte array without losing the margins that i setted?