PDF isn't generating (urgent)


#1

I downloaded a demo version of aspose.pdf a while ago (about 4 months) and used it to generate some PDF’s. I got it working just fine and just purchased a licensed version. I uninstalled the previous version and installed the latest version, now my pdf’s won’t generate most of the time. It appears as though the first time or two after a reboot they’ll generate, after that it just goes to a blank browser. What am I doing wrong? I believe I’m using the latest hot fix. The code is roughly as follows:

Pdf pdf = new Pdf();

string sFileName;

License license = new License();

license.SetLicense(“Aspose.Pdf.lic”);

// Setup general info

pdf.Author = “InLine”;

pdf.Creator = “InLine”;

Aspose.Pdf.Section sec1 = pdf.Sections.Add();

sec1.IsLandscape = false;

sec1.PageInfo = new PageSetup();

sec1.PageInfo.PageWidth = 710;

sec1.PageInfo.Margin.Left = 15;

sec1.PageInfo.Margin.Right = 15;

sec1.PageInfo.PageHeight = 910;

sec1.PageInfo.Margin.Top = 15;

sec1.PageInfo.Margin.Bottom = 15;

sFileName = “Report - " + DateTime.Now.ToString(“d”);

pdf.Title = sFileName;

sFileName = sFileName + “.pdf”;

// Add the header

Text textHeader = new Text(sec1);

textHeader.TextInfo = new TextInfo();

textHeader.TextInfo.FontSize = 14;

textHeader.TextInfo.FontName = “Arial”;

textHeader.TextInfo.Alignment = AlignmentType.Center;

sec1.Paragraphs.Add(textHeader);

Aspose.Pdf.Segment segHeader = new Segment(textHeader);

textHeader.Segments.Add(segHeader);

sName += " (test)”;

segHeader.Content = sName;

Response.ClearHeaders();

Response.ContentType=“application/pdf”;

pdf.Save(“Report.pdf”, SaveType.OpenInBrowser, Response);

Response.End();


#2

Dear Schnazz,

Thank you for considering Aspose.

I have tested your code but can’t reproduce this error. Please change the SaveType and try again. Let me know if it can work with other savetypes.


#3

Thank you for your quick response!

With a save type of OpenInAcrobat it does work. This is a reasonable short term work around, but OpenInBrowser is much preferred.


#4

Dear Schnazz,

Thank you for considering Aspose.

Here is the code in the Save method:

response.Expires = 0;
response.Buffer = true;
response.ClearContent();
if(saveType == SaveType.OpenInAcrobat)
response.AddHeader(“content-disposition”,“attachment; filename=” + fileName);
else
response.AddHeader(“content-disposition”,“inline; filename=” + fileName);
response.ContentType = “application/pdf”;
response.BinaryWrite(buf);

Please check if there is conflict with your code which cause the problem when open in the document in browser.


#5

Thanks for the help! It currently appears to be working, it seems as though this the problem was the DateTime.Now.ToString(“d”); (though it seems odd).

sFileName = "Report - " + DateTime.Now.ToString(“d”);

pdf.Title = sFileName;

If I got rid of the DateTime portion, (so FileName is just Report), it seems to work. For my purposes, this will work just fine. Thanks!