2017-03-28 12 views
0

私はPDFを作成するためにPDFBoxを使用していますが、基本的に曲線ボーダーとソーシャルネットワーク情報である「背景」画像をPDFに挿入します。PDFBoxは各ブラウザで異なって表示されるPDFを作成します

私はPDFを生成するために使用したコードの下に見つけてください:

PDDocument document = new PDDocument(); 
    PDPage page = new PDPage(); 

    document.addPage(page); 
    PDPageContentStream contentStream = new PDPageContentStream(document, page); 

    PDImageXObject pdImage = PDImageXObject.createFromFile(basePath+"images/"+ticket.getId()+".png", document); 
    PDImageXObject backgroundImage = PDImageXObject.createFromFile(basePath+"images/ticket_template.jpg",document); 

    backgroundImage.setWidth(595); 
    backgroundImage.setHeight(800); 

    contentStream.drawImage(backgroundImage,10,0); 
    contentStream.drawImage(pdImage,(page.getMediaBox().getWidth() - pdImage.getWidth())/2,page.getMediaBox().getHeight()-400); 

    float margin = 50; 
    // starting y position is whole page height subtracted by top and bottom margin 
    float yStartNewPage = page.getMediaBox().getHeight() - (2 * margin); 
    // we want table across whole page width (subtracted by left and right margin ofcourse) 
    float tableWidth = page.getMediaBox().getWidth() - (2 * margin); 

    boolean drawContent = true; 
    float yStart = yStartNewPage; 
    float bottomMargin = 70; 
    // y position is your coordinate of top left corner of the table 
    float yPosition = 550; 
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm"); 

    BaseTable table = new BaseTable(400, yStartNewPage, bottomMargin, tableWidth, margin, document, page, true, drawContent); 
    generateTable(table,"Event",event.getName()); 
    generateTable(table,"Código",ticket.getId()); 
    generateTable(table,"Data Ínicio",dateFormat.format(event.getStartDate())); 
    generateTable(table,"Data Fim",dateFormat.format(event.getEndDate())); 
    generateTable(table,"Mesa",eventTable.getName()); 
    generateTable(table,"Número de Convidados",ticket.getNumberOfPeople()+""); 

    table.draw(); 

    contentStream.close(); 

    document.save(new File(basePath+"docs/"+ticket.getId()+".pdf")); 

    document.close(); 

画像が開かれると、紛失しているように見えるクロム:

Image on chrome

The second image is how it appears in google chrome

私はまた、PDFに色をつけた画像を挿入する際に問題があるようです。また、PDFを変換すると奇妙に見えますo画像

+1

分析のために問題のpdfを共有してください。 – mkl

答えて

1

ブラウザはほぼ一点までPDFをレンダリングしているため、ほとんどのブラウザでPDF仕様が徹底的に実装されています。

これはほぼすべてのPDFレンダリングエンジンに当てはまりますが、実際はAdobe PDFリーダーです。これは実質的にリファレンス実装です。

以前のブラウザでは、サードパーティ製のプラグインを使用してPDFを埋め込んでいましたが、セキュリティ上の問題が生じました。

あなたは完全にあなたのPDFが毎回正しく表示されるようにすることはできません。試行錯誤のプロセスです。PDF対応のプリンタのようなPDFレンダリングを実装する他のソフトウェアにも当てはまります。彼らは同じ結果を達成しようと従わない場合はブラウザでそれをチェックして、

  • (それは、少なくとも参照です)最初のAcrobat上にそれを試してみてください

    1. 唯一の賢明な解決策がにあります異なる技術。

    PDF非常に複雑な仕様であり、いくつかの結果を得るにはさまざまな方法がありますが、最も簡単な方法を試してみてください。

  • 関連する問題