2017-09-07 1 views
0

저는 PDFBox 및 Boxable을 처음 접했고 다른 사람들이 저를 도울 수 있다면 좋겠어요! 이 질문은 여기에서 질문 한 내용을 참조합니다 (Ref : https://github.com/dhorions/boxable/issues/89) flurinBoonea는 텍스트, 이미지 및 표를 모두 같은 페이지에 넣기위한 작은 샘플 코드를 제공했습니다. 내 질문은, 내부의 내용을 기반으로하는 동적 인 높이를 가진 표를 만들고 표 뒤에 몇 개의 텍스트를 넣어야하는 경우입니다. 나는 그것을 어떻게 할 수 있는가?!? 어딘가에 나는 테이블을 그리는 동안 내가 다음 코드 조각 전에 table.draw를 사용할 때마다 나는 다음 요소에 대한 YPosition을 얻을 비슷한,전에 그릴 때 테이블이 사라집니다 contentable - PDFBox with Boxable

float yPosition = table.draw() 

을 사용하고 다음 요소에 대해이 위치를 사용하지만 읽어 보시기 바랍니다 ,

PDPageContentStream contentStream = new PDPageContentStream(doc, page); 
contentStream.beginText(); 
contentStream.setFont(font, 18); 
contentStream.moveTextPositionByAmount(0, yPosition - 20); 
contentStream.drawString("This is a test message"); 
contentStream.endText(); 
contentStream.close(); 

테이블이 사라지고 텍스트 만 표시됩니다. 이 문제를 해결하는 방법을 모릅니다. 누군가 나를 도와주세요. 나는 꽤 오랫동안이 문제에 매달렸다. 따라서,

/** 
* Create a new PDPage content stream. This constructor overwrites all existing content streams 
* of this page. 
* 
* @param document The document the page is part of. 
* @param sourcePage The page to write the contents to. 
* @throws IOException If there is an error writing to the page contents. 
*/ 
public PDPageContentStream(PDDocument document, PDPage sourcePage) throws IOException 

이 콘텐츠 스트림을 만들 때를 : 는

답변

1

당신은으로이 생성자가 설명되어 있습니다

PDPageContentStream contentStream = new PDPageContentStream(doc, page); 

사용하여 해당 페이지에 대한 추가 콘텐츠 스트림을 생성 사전에 감사합니다 당신이 그 페이지에 있던 모든 내용을 버리십시오.

기존 콘텐츠에 추가하고 싶을 때마다 다른 생성자 (예 : 제쳐두고

/** 
* Create a new PDPage content stream. 
* 
* @param document The document the page is part of. 
* @param sourcePage The page to write the contents to. 
* @param appendContent Indicates whether content will be overwritten, appended or prepended. 
* @param compress Tell if the content stream should compress the page contents. 
* @param resetContext Tell if the graphic context should be reset. This is only relevant when 
* the appendContent parameter is set to {@link AppendMode#APPEND}. You should use this when 
* appending to an existing stream, because the existing stream may have changed graphic 
* properties (e.g. scaling, rotation). 
* @throws IOException If there is an error writing to the page contents. 
*/ 
public PDPageContentStream(PDDocument document, PDPage sourcePage, AppendMode appendContent, 
          boolean compress, boolean resetContext) throws IOException 

으로 설명되어 있습니다

PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.APPEND, true, true); 

: 당신은 당신이 언급 그래서 난 당신이 특정 A의 전류 버전을 사용하는 가정, PDFBox 및 Boxable 새로운 PDFBox 2.0.x. 어떤 이유로 든 이전 버전 (예 : 1.8.x)을 사용하기로 한 경우 대신

PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true, true); 

이 필요합니다.

관련 문제