将itextsharp PDF从纵向转换为横向模式

时间:2023-01-19 20:58:02

I have a PDF generation code which was previously downloaded in Portait mode and the code behind is shown below.

我有一个PDF生成代码,以前是以Portait模式下载的,后面的代码如下所示。

Document doc = new Document(PageSize.A4, 88f, 88f, 10f, 10f);

which was working properly.

哪个工作正常。

Now I need the same PDF to be converted to Landscape mode, I googled it and found this code.

现在我需要将相同的PDF转换为横向模式,我用Google搜索并找到此代码。

Document doc = new Document(new Rectangle(288f, 144f), 10, 10, 10, 10);
doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());

But still its displaying in Portrait mode.Any help appreciated.

但仍然以纵向模式显示。任何帮助赞赏。

3 个解决方案

#1


12  

You use

你用

Document doc = new Document(PageSize.A4, 88f, 88f, 10f, 10f);

for portrait PDF. The PageSize.A4 is defined as

用于肖像PDF。 PageSize.A4定义为

Rectangle A4 = new RectangleReadOnly(595,842);

Thus, one way to create a landscape PDF would be to use a RectangleReadOnly with switched width and height values:

因此,创建横向PDF的一种方法是使用具有切换宽度和高度值的RectangleReadOnly:

Document doc = new Document(new RectangleReadOnly(842,595), 88f, 88f, 10f, 10f);

Alternatively a rotated version of the original rectangle should work, too:

或者,原始矩形的旋转版本也应该起作用:

Document doc = new Document(new RectangleReadOnly(595,842,90), 88f, 88f, 10f, 10f);

#2


7  

Change

更改

Doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());

#3


0  

maybe the problem is when you are giving it 10,10,10,10. how can you see it as landscape?? change it to as per you margins and try this link

也许问题是当你给它10,10,10,10时。你怎么能把它看作风景?将其更改为您的边距并尝试此链接

#1


12  

You use

你用

Document doc = new Document(PageSize.A4, 88f, 88f, 10f, 10f);

for portrait PDF. The PageSize.A4 is defined as

用于肖像PDF。 PageSize.A4定义为

Rectangle A4 = new RectangleReadOnly(595,842);

Thus, one way to create a landscape PDF would be to use a RectangleReadOnly with switched width and height values:

因此,创建横向PDF的一种方法是使用具有切换宽度和高度值的RectangleReadOnly:

Document doc = new Document(new RectangleReadOnly(842,595), 88f, 88f, 10f, 10f);

Alternatively a rotated version of the original rectangle should work, too:

或者,原始矩形的旋转版本也应该起作用:

Document doc = new Document(new RectangleReadOnly(595,842,90), 88f, 88f, 10f, 10f);

#2


7  

Change

更改

Doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());

#3


0  

maybe the problem is when you are giving it 10,10,10,10. how can you see it as landscape?? change it to as per you margins and try this link

也许问题是当你给它10,10,10,10时。你怎么能把它看作风景?将其更改为您的边距并尝试此链接