Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Export to PDF not working in Windows Azure hosting environment (Read 19085 times)
martink
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Jan 4th, 2014
Export to PDF not working in Windows Azure hosting environment
Jan 10th, 2014 at 10:07am
Print Post  
Hello,

I am using your Diagramming tools for asp.net. I have a web application hosted on windows azure (web sites). When I try to export a diagram to pdf it gives me the error showed in the first attachment. However the pdf is generated but without the labels. I remember having a similar issue when using the DevExpress reporting components and those guys then came with a fix. I can help you fix the issue.
Note that the diagram used currently does not have icons so it's pretty normal that there are no icons inside the generated pdf file.

Regards,
Martin
  

screenshots.zip (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to PDF not working in Windows Azure hosting environment
Reply #1 - Jan 10th, 2014 at 11:15am
Print Post  
Hi,

Try exporting with the SuppressUnmanagedCode property enabled, that should avoid the GetHdc() call. We use native code to get some font metrics necessary for PDF font tables generation, and if you suppress it, you must also set the FontCachePath property. See the remarks in this help topic for more information:
http://www.mindfusion.eu/onlinehelp/netdiagram/index.htm?P_MindFusion_Diagrammin...

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
martink
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Jan 4th, 2014
Re: Export to PDF not working in Windows Azure hosting environment
Reply #2 - Jan 10th, 2014 at 12:10pm
Print Post  
Hi Stoyo,

I will try that over the weekend and will let you know if there are issues.

Thank you,
Martin
  
Back to top
 
IP Logged
 
martink
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Jan 4th, 2014
Re: Export to PDF not working in Windows Azure hosting environment
Reply #3 - Jan 12th, 2014 at 8:11pm
Print Post  
Hi,

I tried with the following code in order to avoid the issue on Windows Azure:

Dim pdf As New MindFusion.Diagramming.Export.PdfExporter()
        pdf.SuppressUnmanagedCode = True
        pdf.FontCachePath = Server.MapPath("~/pdflib-fontrecords.xml")

        Dim path As String = Server.MapPath("~/file.pdf")
        pdf.Export(DiagramView1.Diagram, path)

Unfortunately I get the error "Cannot find PDF font metrics cache file. Make sure pdflib-fontrecords.xml is in the application's folder, ot assign its location to the FontCachePath property.".
The "pdflib-fontrecords.xml" file is added to the project. I can download it from the same location without a problem. Please advice how to proceed or show me a sample code.

Regards,
Martin
  

missing_file_issue.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to PDF not working in Windows Azure hosting environment
Reply #4 - Jan 13th, 2014 at 1:52pm
Print Post  
Hi,

From what I can understand, Server.MapPath does not work in Windows Azure, but you are expected to define some type of local storage and access its path by calling GetLocalResource("localStorageName").RootPath. You can find examples here:

http://blogs.msdn.com/b/jnak/archive/2008/11/07/reading-a-server-side-xml-file-o...
http://www.intertech.com/Blog/windows-azure-local-file-storage-how-to-guide-and-...

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to PDF not working in Windows Azure hosting environment
Reply #5 - Jan 13th, 2014 at 2:04pm
Print Post  
Actually that first example mentions MapPath can map to the app_data folder, so you might also try deploying the cache file there. However app_data only allows read-only access, so it seems you will need a local storage for the generated PDF files anyway.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
marshall
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Jan 30th, 2014
Re: Export to PDF not working in Windows Azure hosting environment
Reply #6 - Feb 20th, 2014 at 10:37pm
Print Post  
I have the same problem running the PDF exporter on a Azure web site. No matter where I load the font metric xml file or how I set the FontCachePath I always get the same error. I've tried all possible approaches and nothing seems to work.

"Cannot find PDF font metrics cache file. Make sure pdflib-fontrecords.xml is in the application's folder, ot assign its location to the FontCachePath property."

This happens on my local machine AND on Azure so it's not an Azure only issue. Can you provide some sample code that is known to work?

Thanks for your help.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to PDF not working in Windows Azure hosting environment
Reply #7 - Feb 21st, 2014 at 7:17am
Print Post  
This is thrown in response to a simple !File.Exists(FontCachePath) check, so either the file has not been deployed at all or the property value does not point to the deployed file. Try writing the path value to the page html to verify if it corresponds to the correct location of deployed cache file. I can't see any problems using it locally, we'll try it on Azure next week.
  
Back to top
 
IP Logged
 
marshall
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Jan 30th, 2014
Re: Export to PDF not working in Windows Azure hosting environment
Reply #8 - Feb 21st, 2014 at 4:54pm
Print Post  
Good to know what is throwing the exception.  I'll try again.  Thanks for looking into this.
  
Back to top
 
IP Logged
 
marshall
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Jan 30th, 2014
Re: Export to PDF not working in Windows Azure hosting environment
Reply #9 - Feb 21st, 2014 at 5:36pm
Print Post  
It seems something else is going on.  I have put some test code in to check for the existence of the file.   Is there something else expected in the FontCachePath parameter?

Here is my code.

        ' generate the PDF file
        exporter.SuppressUnmanagedCode = True           ' required to run under Azure!
        exporter.FontCachePath = Server.MapPath("~/pdflib-fontrecords.xml") ' point to font data

        'Test for valid path
        If (Not File.Exists(exporter.FontCachePath)) Then
            Throw New System.Exception("Diagram Export PDF failed to locate font cache file!")
        End If

        exporter.Export(diagram, tempPath)  '<--- throws file not found exception.


Please see attached screen shot running on my local IIS (not Azure).

  

MindFusionPdfException.gif (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to PDF not working in Windows Azure hosting environment
Reply #10 - Feb 24th, 2014 at 8:05am
Print Post  
It seems we are not initializing our PdfLib library in correct order since introducing thread-local storage in version 5.0.2, and it will first try to load the font cache from its default location in assembly folder. For the time being, use this as a work-around:

Code
Select All
'Imports MindFusion.Pdf
dim exporter as New PdfExporter()
PdfGraphics.SuppressUnmanagedCode = False
PdfGraphics.FontCachePath = Server.MapPath("~/pdflib-fontrecords.xml")
exporter.SuppressUnmanagedCode = True
exporter.Export(diagram, tempPath) 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
marshall
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Jan 30th, 2014
Re: Export to PDF not working in Windows Azure hosting environment
Reply #11 - Feb 25th, 2014 at 5:13am
Print Post  
Unfortunately this workaround does not fix the problem.  The Export method still throws an exception.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to PDF not working in Windows Azure hosting environment
Reply #12 - Feb 25th, 2014 at 10:27am
Print Post  
We have just tried this on Azure, deploying the Tutorial sample project without any modifications:
http://mindfusion.cloudapp.net/

It seems to work with all deployment options left at default values. We are not sure why you'd need SuppressUnmanagedCode enabled in the first place, have you guys changed anything in the ServiceConfiguration files? One problem we can see is that Azure sometimes serves older versions of the PDF files - that might be related to the Azure local storage thing, we'll try exporting through it, and will also check if using the font cache works.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to PDF not working in Windows Azure hosting environment
Reply #13 - Feb 25th, 2014 at 12:35pm
Print Post  
It worked for us with SuppressNativeCode enabled too:
http://mindfusion2.cloudapp.net/

The only changes in the Tutorial project were adding pdflib-fontrecords.xml to it as content, and using this export code:

Code
Select All
protected void btnExportPdf_Click(object sender, EventArgs e)
{
	MindFusion.Diagramming.Export.PdfExporter pdf =
		new MindFusion.Diagramming.Export.PdfExporter();

	PdfGraphics.SuppressUnmanagedCode = false;
	PdfGraphics.FontCachePath = Server.MapPath(@"~\pdflib-fontrecords.xml");
	pdf.SuppressUnmanagedCode = true;
	string fileName = Session.SessionID + "_" + rnd.Next() + ".pdf"; ;
	string path = Server.MapPath(@"~\PDF\") + fileName;
	pdf.Export(diagView.Diagram, path);

	pdfURL.Value = "PDF/" + fileName;
}

Random rnd = new Random();
 



There wasn't a problem with older PDF files being served; what we saw was coming from the browser's local cache. Adding a random value to the file name fixed that.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
marshall
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Jan 30th, 2014
Re: Export to PDF not working in Windows Azure hosting environment
Reply #14 - Mar 6th, 2014 at 9:35pm
Print Post  
There is clearly a problem generating PDF's from a Azure web site due to Azure's security restrictions.  Apparently if this functionality DOES work for the Azure Web Role model or if you use an Azure VM (more $$$). 

There are a number of postings that describe this problem (and the failure of MS to address it):

http://social.msdn.microsoft.com/Forums/windowsazure/en-US/b4a6eb43-0013-435f-9d...

http://stackoverflow.com/questions/16183529/reportviewer-rdlc-azure-websites-err...

In addition I have still not gotten the FontCachePath method to work.  Always throws a can't find file exception.

  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint