I am using the method below to render SSRS reports to PDF. Its always using the same deviceInfo (see below). After rendering some reports i use PDFSharp to combine them into one PDF file. This works fine for some factonIDs but sometimes PDFSharp
is throwing an exception "Unexpected token 'ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ[...]'". When i open those PDF files with PDF-XChange Editor, i get a warning telling me there were problems with the document which could be solved by saving a copy (see picture below
if you speak german). I tried to combine those copied PDF files with PDFSharp and it worked fine.
The report and device information stays the same. It is only the text and numbers in the report which changes. Why does the renderer create corrupted files sometimes?
I dont want to manually open each PDF and save a copy to make sure they are not corrupted.
EDIT: I added AccessiblePDF and HumanReadablePDF to deviceInfo because i was getting a similiar error (Unexpected token 'FactonID') for all rendered pdf files.
![]()
<DeviceInfo> <AccessiblePDF>true</AccessiblePDF><HumanReadablePDF>true</HumanReadablePDF><PageHeight>8.3in</PageHeight><PageWidth>11.7in</PageWidth> <MarginLeft>0.2in</MarginLeft> <MarginRight>0.2in</MarginRight><MarginTop>0.2in</MarginTop><MarginBottom>0.2in</MarginBottom></DeviceInfo>
private static void RenderReportToFile(int factonID, string reportName, string fileName, string format, string deviceInfo)
{
// Create Web service proxies.
EPO_Export.reportexecution.ReportExecutionService rs = new EPO_Export.reportexecution.ReportExecutionService();
rs.Url = "http://blg-factrepd01/ReportServer/reportexecution2005.asmx";
rs.Credentials = CredentialCache.DefaultCredentials;
try
{
string encoding;
string mimeType;
string extension;
Warning[] warnings;
string[] streamIDs;
// Load the report.
ExecutionInfo info = rs.LoadReport(reportName, null);
ParameterValue[] values = new ParameterValue[2];
values[0] = new ParameterValue
{
Label = "Facton ID",
Name = "paraProjectFactonID",
Value = factonID.ToString()
};
values[1] = new ParameterValue
{
Label = "Version",
Name = "paraVersionFactonID",
Value = factonID.ToString()
};
rs.SetExecutionParameters(values, "en-us");
// Render the report.
byte[] reportBytes = rs.Render(
format,
deviceInfo,
out extension,
out mimeType,
out encoding,
out warnings,
out streamIDs);
// Write report bytes to a file.
using (FileStream stream = File.OpenWrite(fileName))
stream.Write(reportBytes, 0, reportBytes.Length);
Console.WriteLine("Report '" + reportName + "' has been rendered successfully for Facton ID: " + factonID.ToString() + ".");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}