diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 0608c9efff..1b087aa7af 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -735,7 +735,31 @@ void CPdfFile::GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, do { if (!m_pInternal->pReader) return; - m_pInternal->pReader->GetPageInfo(nPageIndex, pdWidth, pdHeight, pdDpiX, pdDpiY); +#ifndef BUILDING_WASM_MODULE + if (m_pInternal->bEdit && m_pInternal->pWriter && m_pInternal->pWriter->m_pDocument) + { + PdfWriter::CPage* pPage = m_pInternal->pWriter->m_pDocument->GetPage(nPageIndex); + if (!pPage) + return; + + int nRotate = pPage->GetRotate(); + if (nRotate % 180 == 0) + { + *pdWidth = pPage->GetWidth(); + *pdHeight = pPage->GetHeight(); + } + else + { + *pdWidth = pPage->GetHeight(); + *pdHeight = pPage->GetWidth(); + } + + *pdDpiX = 72.0; + *pdDpiY = 72.0; + } + else +#endif + m_pInternal->pReader->GetPageInfo(nPageIndex, pdWidth, pdHeight, pdDpiX, pdDpiY); } void CPdfFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak) { diff --git a/PdfFile/SrcWriter/Pages.cpp b/PdfFile/SrcWriter/Pages.cpp index 823407c975..fd7dfca9ea 100644 --- a/PdfFile/SrcWriter/Pages.cpp +++ b/PdfFile/SrcWriter/Pages.cpp @@ -482,7 +482,8 @@ namespace PdfWriter } double CPage::GetWidth() { - return GetMediaBox().fRight; + TBox oBox = GetMediaBox(); + return oBox.fRight - oBox.fLeft; } void CPage::SetHeight(double dValue) { @@ -491,7 +492,8 @@ namespace PdfWriter } double CPage::GetHeight() { - return GetMediaBox().fTop; + TBox oBox = GetMediaBox(); + return oBox.fTop - oBox.fBottom; } TBox CPage::GetMediaBox() { @@ -1560,7 +1562,12 @@ namespace PdfWriter Add("Rotate", nRotate % 360); } } - //---------------------------------------------------------------------------------------- + int CPage::GetRotate() + { + CNumberObject* pRotate = (CNumberObject*)GetRotateItem(); + return pRotate ? pRotate->Get() : 0; + } + //---------------------------------------------------------------------------------------- // CTextWord //---------------------------------------------------------------------------------------- CTextWord::CTextWord() diff --git a/PdfFile/SrcWriter/Pages.h b/PdfFile/SrcWriter/Pages.h index a550fd996f..5cee58903a 100644 --- a/PdfFile/SrcWriter/Pages.h +++ b/PdfFile/SrcWriter/Pages.h @@ -159,7 +159,8 @@ namespace PdfWriter void AddGroup(CDictObject* pDict); void AddContents(CXref* pXref); - void SetRotate(int nRotate); + void SetRotate(int nRotate); + int GetRotate(); private: @@ -168,7 +169,7 @@ namespace PdfWriter CArrayObject* GetMediaBoxItem(); CDictObject* GetResourcesItem(); CObjectBase* GetCropBoxItem(); - CObjectBase* GetRotateItem(); + CObjectBase* GetRotateItem(); TBox GetMediaBox(); void SetMediaBoxValue(unsigned int unIndex, double dValue); void AddResource();