更改页面方向

时间:2018-01-04 15:26:40

标签: c# asp.net itext

我在C#ASP.NET应用程序中使用iTextSharp.dll。我所追求的是,​​如果计数int selectedCount = checkboxlistfirst.Items.Cast<System.Web.UI.WebControls.ListItem>() .Count(li => li.Selected); Document pdfDoc = new Document(PageSize.A4.Rotate(), 0, 0, 5, 0); if (selectedCount <= 2) { pdfDoc.SetPageSize(new Rectangle(850f, 1100f)); } 值为const MyApp = TabNavigator({ Data1: { screen: Data1 }, Data2: { screen: Data2 } }); class Data1 extends React.Component { static navigationOptions = { tabBarLabel: 'Data 1' }; render() { return ( <Text>Data inside Data 1</Text> ); } } class Data2 extends React.Component { static navigationOptions = { tabBarLabel: 'Data 2' }; render() { return ( <View> <Text>Data inside Data 2</Text> </View> ); } },那么我想以纵向打印。如果计数是其他任何东西,那么我想在横向打印。我在下面的语法将始终以纵向打印。

如何根据我的标准进行打印?

class Data extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      selected: null
    }
  }
  
  data1 = () => {
    return (
      <View>
        <Text>This is data 1</Text>
        <Text>I Have something in data 1</Text>
      </View>
    )
  }
  
  data2 = () => {
    return (
      <View>
        <Text>This is data 2</Text>
        <Text>I Have something in data 2</Text>
      </View>
    )
  }
  
  changeData = (data) => {
    this.setState({ selected: data });
  }

  render() {
    return (
      <View>
        <View style={{ flexDirection: 'row' }}>
          <TouchableHighlight onPress={()=>this.changeData('1')}>
            <Text>Data 1</Text>
          </TouchableHighlight>
          <TouchableHighlight onPress={()=>this.changeData('2')}>
            <Text>Data 2</Text>
          </TouchableHighlight>
        </View>
        
        {this.state.selected === '1' ? data1 : data2}
        
      </View>
    );
  }
}

1 个答案:

答案 0 :(得分:2)

您基本上需要旋转文档的页面。

查看https://developers.itextpdf.com/examples/stamping-content-existing-pdfs/clone-scaling-and-rotating-pages

(java代码,但应该很容易移植到C#)

PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST));
int n = pdfDoc.getNumberOfPages();
PdfPage page;
PdfNumber rotate;
for (int p = 1; p <= n; p++) {
    page = pdfDoc.getPage(p);
    rotate = page.getPdfObject().getAsNumber(PdfName.Rotate);
    if (rotate == null) {
        page.setRotation(90);
    }
    else {
        page.setRotation((rotate.intValue() + 90) % 360);
    }
}
pdfDoc.close();