Hello,
Sorry for another topic about Rotation, but I couldn't find anything which works for me.
Business case:
We are using Microsoft Reporting 2005. A PDF document is created using ReportViewer.
Code:
string[] streamIds;
string mimeType;
string encoding;
string extension;
byte[] bytes;
ReportViewer viewer = new ReportViewer();
... //Report server URL, path to report, credentials etc.
bytes = viewer.ServerReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
It works, but Page.Orientation property is set to Portrait for all pages. Doesn't matter the page dimensions in Report. Page is displayed correctly (landscape) in Acrobat reader and Foxit reader, but when I loop through document's pages, this property is 'Portrait'. Page.Width and Page.Height properties are correct.
Now I have to create a single PDF document from 2 reports (one is Portrait, one is Landscape) and send it to a partner. The partner uses their own software which requires all pages to be Portrait. I have to Rotate Lanscape pages by 90 degrees clockwise. When printing Landscape pages printer turns them oposite direction and that's not OK.
I have made the page rotation this way. Acrobat reader and Foxit reader shows and prints the document correctly, but when I send the PDF to our partner, their system treates rotated pages as they are Landscape.
The partner sent me this -> MediaBox:
1 ( 23 0 R): [ 0 0 595.276 841.89 ] //Portrait page from 1st report
2 ( 28 0 R): [ 0 0 841 595.276 ] // Rotated page from 2nd report
Code:
// This will be the resulting PDF file.
PdfDocument document = PdfReader.Open(filepath, PdfDocumentOpenMode.Import);
//Loop through pages
foreach (PdfPage page in reportDoc.Pages)
{
//Rotate Landscape pages
if (page.Width > page.Height)
{
double width = page.Width;
double height = page.Height;
//This only rotates text, paper remains Landscape
page.Rotate = 90;
//Let's change the paper size
page.Width = Math.Min(height, width);
page.Height = Math.Max(height, width);
document.AddPage(page);
}
else
{
document.AddPage(page);
}
}
This is how the Page properties look when I add the page:
Attachment:
File comment: page properties aftes I have set Page.Rotate = 90
pdfPage.png [ 31.16 KiB | Viewed 11871 times ]
This code didn't do anything...
Code:
PdfDocument reportModDoc = PdfReader.Open(reportStream, PdfDocumentOpenMode.Modify);
foreach (PdfPage page in reportModDoc.Pages)
{
if (page.Width > page.Height)
{
XGraphics xGraph = XGraphics.FromPdfPage(page);
//Tried both of theese - nothing. Both page and text remains landscape
//xGraph.RotateAtTransform(90, new XPoint(400, 400));
//xGraph.RotateTransform(90);
xGraph.Save();
xGraph.Dispose();
}
}
reportModDoc.Save(filepath);
reportModDoc.Dispose();
It looks like only representation is changed while page remains the same under the bonnet