Q: How would a I place rotated image on a page? I tired to tweak the
above code byt my image is skewed.
Thanks for looking in to this for me.
--------------------
A: You can use the following helper function:
The logic as follows:
- The unit image is first scaled using the scale factor (relative to
the original pixel dimensions).
- The image is then rotated
- The final (leftmost) matrix translates the image to the desired
location:
static private void PlaceImage(Page page, Image img, double x, double
y, double scale, int rotationDegrees)
{
using (ElementBuilder builder = new ElementBuilder())
{
using(ElementWriter writer = new ElementWriter())
{
writer.Begin(page);
Element element = builder.CreateImage(img, new Matrix2D(1, 0, 0, 1,
x, y)
* Matrix2D.RotationMatrix(rotationDegrees * 0.017453292519)
* new Matrix2D(img.GetImageWidth()*scale, 0, 0,
img.GetImageHeight()*scale, 0, 0));
writer.WritePlacedElement(element);
writer.End();
}
}
}
For example:
PDFNet.Initialize();
using (PDFDoc doc = new PDFDoc("in.pdf")) {
doc.InitSecurityHandler();
pdftron.PDF.Image img = pdftron.PDF.Image.Create(doc, "peppers.jpg");
PlaceImage(doc.GetPage(1), img, 100, 100, 0.5, 45);
doc.Save("out.pdf", 0);
}
For example of how to add a rotated text please see:
How can I stamp all PDF pages with a rotated and centered text
stamp? Options
http://groups.google.com/group/pdfnet-sdk/browse_thread/thread/d017db32b85c78e9/8f66636628202344