2016-05-31 20 views
3

現在、私はpdfを生成するためにApacheのPDFBoxを使用しています。ポートレートモードでは正常に動作していますが、最初の2ページは横長モードにし、その後は他のすべてのページを縦向きにする必要があります。pdfを使用したPDFファイルの表示

だから誰も私の助けてください風景にPDFを作成し、この機能を達成する上で私を助けてください?

注:

1)(これはA4用)景観にmediaboxを割り当てます:私は

答えて

4

は、2つの戦略がある他のライブラリにPDFBoxから切り替えることはできません

float POINTS_PER_INCH = 72; 
float POINTS_PER_MM = 1/(10 * 2.54f) * POINTS_PER_INCH; 
new PDPage(new PDRectangle(297 * POINTS_PER_MM, 210 * POINTS_PER_MM)); 

2)を割り当てます肖像画のメディボックス、ページを回転させてCTMを回転させる、as shown in the official example

PDPage page = new PDPage(PDRectangle.A4); 
page.setRotation(90); 
doc.addPage(page); 
PDRectangle pageSize = page.getMediaBox(); 
float pageWidth = pageSize.getWidth(); 
PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.OVERWRITE, false); 
// add the rotation using the current transformation matrix 
// including a translation of pageWidth to use the lower left corner as 0,0 reference 
contentStream.transform(new Matrix(0, 1, -1, 0, pageWidth, 0)); 
(...) 
16

もう1つの解決策は、

PDPage page = new PDPage(new PDRectangle(PDRectangle.A4.getHeight(), PDRectangle.A4.getWidth())); 
+0

です。これは受け入れられる回答でなければなりません。よりシンプルでエレガントな –

関連する問題