PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jun 17, 2024 5:00 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Oct 03, 2012 4:40 pm 
Offline

Joined: Wed Oct 03, 2012 3:38 pm
Posts: 3
Hello,

I want to merge some pdfs generated with reporting services into a only one pdf with PDFsharp.

I use the following code to do it (simplified version):

Code:
PdfDocument pdfDoc = new PdfDocument();

string strDeviceInfo = "<DeviceInfo><HumanReadablePDF>True</HumanReadablePDF></DeviceInfo>";
string strMimeType = "";
string strEncoding = "";
string strFileNameExtension = "";
string[] streams;
Warning[] warnings;

// First local report generated with MS Reporting
LocalReport report1 = new LocalReport();
report1.DataSources.Add(new ReportDataSource("MyDS", myDataSource1));
report1.ReportEmbeddedResource = "myreport.rdlc";
byte[] pdfContent1 = report1.Render("PDF", strDeviceInfo, strMimeType, strEncoding, strFileNameExtension, streams, warnings);
MemoryStream ms1 = new MemoryStream(pdfContent1);
PdfDocument tmpPdfDoc1 = PdfReader.Open(ms1, PdfDocumentOpenMode.Import);
for (int ind = 0; ind < tmpPdfDoc1.PageCount; ind++) {
    pdfDoc.AddPage(tmpPdfDoc1.Pages(ind));
}

// Second local report generated with MS Reporting
LocalReport report2 = new LocalReport();
report2.DataSources.Add(new ReportDataSource("MyDS", myDataSource2));
report2.ReportEmbeddedResource = "myreport.rdlc";
byte[] pdfContent2 = report2.Render("PDF", strDeviceInfo, strMimeType, strEncoding, strFileNameExtension, streams, warnings);
MemoryStream ms2 = new MemoryStream(pdfContent2);
PdfDocument tmpPdfDoc2 = PdfReader.Open(ms2, PdfDocumentOpenMode.Import);
for (int ind = 0; ind < tmpPdfDoc2.PageCount; ind++) {
    pdfDoc.AddPage(tmpPdfDoc2.Pages(ind));
}

// Save the merged pdf
strFile = System.IO.Path.GetTempFileName.Replace(".tmp", ".pdf");
pdfDoc.Save(strFile);

// Open the merged pdf
System.Diagnostics.Process proceso = new System.Diagnostics.Process();
proceso.StartInfo.FileName = strFile;
proceso.Start();


All process works fine, the problem is that the file myreport.rdlc contains a textbox with a static text with the euro sign and in the merged pdf, that euro sign appears as question mark.
The textbox has the Arial font assigned.

If I save the pdfContent1 of first pdf directly to disk with a FileStream (without PDFSharp) the euro sign are showed ok.

I don't know where is the problem (in my source Reporting report, or in the conversion of PDFSharp).

Any help will be appreciated.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 04, 2012 9:54 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hi!

Maybe an encoding problem.
strEncoding appears to remain empty?

Please try saving the byte[] to a file and use PDFsharp to read from the file. If the Euro sign is correct when the file is viewed in Adobe Reader but still incorrect when read with PDFsharp, please provide us that file for further investigation.

It sounds as if you tried that already (or did you use a different method to save the PDF file?).

ISO-8859-1 is a superset of the ANSI codepage (1252 IIRC), but only the former includes the Euro sign and MS conversion routines tend to replace non-existing characters with question marks. So conversion to ISO-8859-1 may work while conversion to ANSI may not work.
If you didn't save your PDF file from a byte[] as shown in your sample, then maybe different code (or a different encoding) was used.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 05, 2012 8:49 am 
Offline

Joined: Wed Oct 03, 2012 3:38 pm
Posts: 3
Hi Thomas.

Thanks for your answer.

As you told me, I made the following test:

1.- Generate the byte[] array with Reporting LocalReport.Render() method.
2.- Save that byte[] array to a pdf file (named fileA.pdf).
3.- Import the fileA.pdf into a pdfSharp temp document with PdfReader.Open() method.
4.- Add all pages from temp pdfsharp document into a new pdfSharp document.
5.- Save the new pdfSharp document in another file (fileB.pdf).

You were right, both file fileA.pdf and fileB.pdf show the question mark instead of the euro symbol.

It seem to be an issue with the encoding and invoking the Render method of Reporting's LocalReport with the DeviceInfo "<DeviceInfo><HumanReadablePDF>True</HumanReadablePDF></DeviceInfo>".

Although it is clear that the problem is not in pdfSharp, how could fix it? (I have no idea how could fix it)

strEncoding is empty (null) after calling the Render method.

Perhaps playing with the Reporting source rdlc file encoding ?

Thanks again.


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 05, 2012 9:57 am 
Offline

Joined: Wed Oct 03, 2012 3:38 pm
Posts: 3
Googling, it seem a known problem:
http://social.msdn.microsoft.com/Forums ... 6c6f711417

Exists a hotfix for Reporting Services, but not for LocalReports.

Quote:
I think I will move the euro sign as a report parameter.
Perhaps it might work.


Not work to move euro sign as parameter :cry: :cry: :cry:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 151 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group