@@ -140,6 +140,15 @@ public static async Task AddPdfPagesAsync(PdfDocument document, string html, Pdf
140140 orgPageSize = new XSize ( orgPageSize . Height , orgPageSize . Width ) ;
141141 }
142142
143+ var pdfPageSize = orgPageSize ;
144+
145+ if ( config . ZoomLevel != 1 )
146+ {
147+ // let the layout engine render onto a smaller page, as we'll scale it up when we
148+ // render it to the PDF.
149+ orgPageSize = new XSize ( orgPageSize . Width / config . ZoomLevel , orgPageSize . Height / config . ZoomLevel ) ;
150+ }
151+
143152 var pageSize = new XSize ( orgPageSize . Width - config . MarginLeft - config . MarginRight , orgPageSize . Height - config . MarginTop - config . MarginBottom ) ;
144153
145154 if ( ! string . IsNullOrEmpty ( html ) )
@@ -171,22 +180,25 @@ public static async Task AddPdfPagesAsync(PdfDocument document, string html, Pdf
171180 while ( scrollOffset > - container . ActualSize . Height )
172181 {
173182 var page = document . AddPage ( ) ;
174- page . Height = orgPageSize . Height ;
175- page . Width = orgPageSize . Width ;
183+ page . Height = pdfPageSize . Height ;
184+ page . Width = pdfPageSize . Width ;
176185
177186 using ( var g = XGraphics . FromPdfPage ( page ) )
178187 {
179188 //g.IntersectClip(new XRect(config.MarginLeft, config.MarginTop, pageSize.Width, pageSize.Height));
180189 g . IntersectClip ( new XRect ( 0 , 0 , page . Width , page . Height ) ) ;
181190
191+ if ( config . ZoomLevel != 1 )
192+ g . ScaleTransform ( config . ZoomLevel ) ;
193+
182194 container . ScrollOffset = new XPoint ( 0 , scrollOffset ) ;
183195 await container . PerformPaintAsync ( g ) ;
184196 }
185197 scrollOffset -= pageSize . Height ;
186198 }
187199
188200 // add web links and anchors
189- HandleLinks ( document , container , orgPageSize , pageSize ) ;
201+ HandleLinks ( document , container , pdfPageSize , pageSize , config . ZoomLevel ) ;
190202 }
191203 }
192204 }
@@ -198,17 +210,25 @@ public static async Task AddPdfPagesAsync(PdfDocument document, string html, Pdf
198210 /// <summary>
199211 /// Handle HTML links by create PDF Documents link either to external URL or to another page in the document.
200212 /// </summary>
201- private static void HandleLinks ( PdfDocument document , HtmlContainer container , XSize orgPageSize , XSize pageSize )
213+ private static void HandleLinks ( PdfDocument document , HtmlContainer container , XSize pdfPageSize , XSize pageSize , double zoomLevel )
202214 {
203215 foreach ( var link in container . GetLinks ( ) )
204216 {
205217 int i = ( int ) ( link . Rectangle . Top / pageSize . Height ) ;
206218 for ( ; i < document . Pages . Count && pageSize . Height * i < link . Rectangle . Bottom ; i ++ )
207219 {
208- var offset = pageSize . Height * i ;
220+ //Zoom as required.
221+ var offset = pageSize . Height * i * zoomLevel ;
222+ var linkRect = new XRect
223+ {
224+ X = link . Rectangle . Left * zoomLevel ,
225+ Y = link . Rectangle . Top * zoomLevel ,
226+ Width = link . Rectangle . Width * zoomLevel ,
227+ Height = link . Rectangle . Height * zoomLevel
228+ } ;
209229
210230 // fucking position is from the bottom of the page
211- var xRect = new XRect ( link . Rectangle . Left , orgPageSize . Height - ( link . Rectangle . Height + link . Rectangle . Top - offset ) , link . Rectangle . Width , link . Rectangle . Height ) ;
231+ var xRect = new XRect ( linkRect . Left , pdfPageSize . Height - ( linkRect . Height + linkRect . Top - offset ) , linkRect . Width , linkRect . Height ) ;
212232
213233 if ( link . IsAnchor )
214234 {
0 commit comments