旋转页面时不应转换为删除pdf文档中搜索的图像。
using WebSupergoo.ABCpdf9;
Doc doc = new Doc();
byte[] source = // some source of pdf byte array
doc.Read(source);
for (int i = 1; i <= doc.PageCount; i++)
{
doc.PageNumber = i;
double w = doc.MediaBox.Width;
double h = doc.MediaBox.Height;
double l = doc.MediaBox.Left;
double b = doc.MediaBox.Bottom;
doc.Transform.Rotate(90, l, b);
doc.Transform.Translate(w, 0);
// rotate our rectangle
doc.Rect.Width = h;
doc.Rect.Height = w;
}
MemoryStream stream = new MemoryStream();
doc.Save(stream);
上面的代码似乎没有用。请适当建议。
答案 0 :(得分:3)
我尝试使用itextsharp库实现这一点。
byte[] source = // some source of pdf byte array
MemoryStream outStream = new MemoryStream();
PdfReader reader = new PdfReader(scannedInvoice.imgImage);
PdfStamper stamper = new PdfStamper(reader, outStream);
for (int i = 1; i <= reader.NumberOfPages; i++)
{
PdfDictionary pageDict = reader.GetPageN(i);
int desiredRot = 90; // 90 degrees clockwise
PdfNumber rotation = pageDict.GetAsNumber(PdfName.ROTATE);
if (rotation != null)
{
desiredRot += rotation.IntValue;
desiredRot %= 360; // 0, 90, 180, 270
}
pageDict.Put(PdfName.ROTATE, new PdfNumber(desiredRot));
}
stamper.Close();
var rotatedpdfArray = outStream.ToArray(); // The rotated output
希望这有助于.......