C# ABCPdf更改特定页面的方向
下面的代码创建了一个横向的新PDF。它使用ABCPdf组件C# ABCPdf更改特定页面的方向,c#,abcpdf,C#,Abcpdf,下面的代码创建了一个横向的新PDF。它使用ABCPdf组件 static void Main(string[] args) { var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "da.pdf"); var theDoc = new Doc(); //theDoc.Read(filePath); // apply a rotation transform theDoc.
static void Main(string[] args)
{
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "da.pdf");
var theDoc = new Doc();
//theDoc.Read(filePath);
// apply a rotation transform
theDoc.MediaBox.String = "Legal";
double w = theDoc.MediaBox.Width;
double h = theDoc.MediaBox.Height;
double l = theDoc.MediaBox.Left;
double b = theDoc.MediaBox.Bottom;
theDoc.Transform.Rotate(90, l, b);
theDoc.Transform.Translate(w, 0);
// rotate our rectangle
theDoc.Rect.Width = h;
theDoc.Rect.Height = w;
// add some text
theDoc.Rect.Inset(50, 50);
theDoc.FontSize = 96;
theDoc.AddText("Landscape Orientation");
theDoc.AddPage();
theDoc.PageNumber = theDoc.PageCount;
theDoc.AddText("Page 2");
// adjust the default rotation and save
int theID = theDoc.GetInfoInt(theDoc.Root, "Pages");
theDoc.SetInfo(theID, "/Rotate", "90");
theDoc.Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "out.pdf"));
theDoc.Clear();
}
我不想创建新的pdf,而是想打开现有的pdf,并使用ABCPdf将特定页面的方向更改为横向。比如,第一页是纵向的,第二页是横向的
谢谢您可以这样做,或者使用“AddImageDoc”方法插入修改过的页面
但是
Abcpdf不允许覆盖源文件。从“保存方法文档”中:
ABCpdf操作智能实时对象加载方案
这样可以确保仅加载所需的对象
进入记忆。这意味着,如果要修改大型文档,则
服务器负载将保持在最低限度。必须提供原始PDF文档
只要使用文档对象,就可以使用
因此,您无法在读取PDF文件时修改或覆盖该文件
导入文档对象。您需要将PDF保存到其他位置
然后在Doc对象使用
PDF结束(通过调用清除、处置或使用另一个PDF读取)
文件)
所以你总是需要一份“新pdf”。没关系。一旦更改完成,我不介意将文件保存为新的pdf格式。我会试试AddImageDoc,很快就会回来。