[ 
https://issues.apache.org/jira/browse/PDFBOX-5676?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17762905#comment-17762905
 ] 

Benjamin edited comment on PDFBOX-5676 at 9/8/23 6:11 AM:
----------------------------------------------------------

No error is thrown but the pdf will not render the page.  Sample code:

    private int addCoverPage(PDDocument document, int pageNumber, 
ArrayList<PDDocument> mergedDocs) throws IOException, SQLException{
        try(Connection connection = connectionSource.getConnection()){
            Statement st = connection.createStatement();
            JSONObject coverPagePathJO = DDASQLData.getContentValue(st, new 
JSONObject("\{\"templateid\":\"3\", \"contentid\":\"70\", \"prefix\":\"" + 
p.getJSONReadyPrefix() + "\"}"));
            String pdfPath = "default pdf path";
            if(coverPagePathJO!=null){
                pdfPath = coverPagePathJO.getString("text");      
            }        
            File file = new File(pdfPath);   
            PDDocument doc = Loader.loadPDF(file);           
            PDPage thisPage = doc.getPage(0);
            PDPageContentStream contentStream = new PDPageContentStream(
                document, thisPage, PDPageContentStream.AppendMode.APPEND, 
true, true
            );          
            document.addPage(thisPage); 

            String coverEntity = DDASQLData.getContentValue(st, new 
JSONObject("\{\"templateid\":\"3\", \"contentid\":\"2\", \"prefix\":\"" + 
p.getJSONReadyPrefix() + "\"}")).getString("text");
            String[] ceParts = coverEntity.split("\n",-1);

            float center = A4LandscapeHeight / 2 + 50;

            float heightOfText = (ceParts.length + 1 ) * 40;

            contentStream.beginText();
            contentStream.setFont( calibribold, 34 );
            contentStream.setNonStrokingColor(NexiaColors.NEXIATEAL);           
 
            //Setting the position for the line 
            contentStream.newLineAtOffset(82, center + heightOfText / 2);       
 
            float fontSize = 34;
            for(String part: ceParts){
                while((((calibribold.getStringWidth(part) / 1000.0f) * 
fontSize) + (2 * 82) + 265) > A4LandscapeWidth){
                    fontSize = fontSize - 1;            
                }
                contentStream.setFont( calibribold, fontSize);            
                contentStream.showText(part);
                contentStream.newLineAtOffset(0, -40);            
            }        

            contentStream.setNonStrokingColor(NexiaColors.NEXIAGREY);    
            contentStream.setFont(calibribold, 14);            
            contentStream.showText(DDASQLData.getContentValue(st, new 
JSONObject("\{\"templateid\":\"3\", \"contentid\":\"1\", \"prefix\":\"" + 
p.getJSONReadyPrefix() + "\"}")).getString("text"));                 
            contentStream.endText();
            contentStream.close();         
            st.close();
            mergedDocs.add(doc);
        }
        pageNumber++;
        return pageNumber;
    }


was (Author: JIRAUSER286761):
No error is thrown but the pdf will not render the page.  Sample code:

            File file = new File(pdfPath);   
            PDDocument doc = Loader.loadPDF(file);           
            PDPage thisPage = doc.getPage(0);
            PDPageContentStream contentStream = new PDPageContentStream(
                document, thisPage, PDPageContentStream.AppendMode.APPEND, 
true, true
            );          
            document.addPage(thisPage); 

> Upgrading from 3.0.0-RC1 to 3.0.0 impacted merging pdf documents
> ----------------------------------------------------------------
>
>                 Key: PDFBOX-5676
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5676
>             Project: PDFBox
>          Issue Type: Bug
>            Reporter: Benjamin
>            Priority: Major
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to