c# - Rotating An Image using AddTemplate -
using vs 2010, c#, itextsharp
i creating pdf document opening various existing pdf documents, extracting images them , inserting them new pdf document. problem trying rotate images in new pdf document (depending on width , height of source images) make efficient use of space in new pdf document (ultimately used print set of stickers). looking @ output file stickers appear rotating however, right hand end of sticker dissapears out of top of document resulting in image appearing large forward slash / bottom left top of document.
the original code not rotate image (and works perfectly)
the x,y (sourcexstart, sourceystart) co-ordinates of image dynamically calculated
the existing code - no rotation - , works perfectly
if ((sourcexstart + pdfinreader.getpagesizewithrotation(1).width + 10) >= (thepagewidth - 5)) { sourcexstart = 5; sourceystart = sourceystart + lastheight + 30; lastheight = 0; } cb.addtemplate(page, sourcexstart, sourceystart); // add image sourcexstart = sourcexstart + pdfinreader.getpagesizewithrotation(1).width + 10; if (pdfinreader.getpagesizewithrotation(1).width > lastheight) { // note maximum height of sticker in row lastheight = pdfinreader.getpagesizewithrotation(1).width; }
the new code - attempting rotation 90 degreed depending on width & height
if (pdfinreader.getpagesizewithrotation(1).width < pdfinreader.getpagesizewithrotation(1).height) // tall stickers { // first need check if image fit in width of page if ((sourcexstart + pdfinreader.getpagesizewithrotation(1).height + 10) >= (thepagewidth - 5)) { sourcexstart = 5; sourceystart = sourceystart + pdfinreader.getpagesizewithrotation(1).width + 30; lastheight = 0; } cb.addtemplate(page, 0, -1f, 1f, sourcexstart, sourceystart, pdfinreader.getpagesizewithrotation(1).width); sourcexstart = sourcexstart + pdfinreader.getpagesizewithrotation(1).width + 5; if (pdfinreader.getpagesizewithrotation(1).width > lastheight) { lastheight = pdfinreader.getpagesizewithrotation(1).width; } }
Comments
Post a Comment