Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-3890

The operator Tz is not available when creating new PDF using PDPageContentStream

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.7
    • 2.0.8, 3.0.0 PDFBox
    • PDModel
    • None

    Description

      When creating new PDF file using the PDPageContentStream there is no option to set horizontal text spacing. The horizontal text spacing operator (Tz) is implemented in org.apache.pdfbox.contentstream.operator.text.SetTextHorizontalScaling but that's not possible to use when creating new PDF.

      Minimal working example:

      PDDocument document = new PDDocument();
      PDPage page = new PDPage();
      document.addPage( page );
      
      PDFont font = PDType1Font.HELVETICA_BOLD;
      PDPageContentStream contentStream = new PDPageContentStream(document, page);
      
      contentStream.beginText();
      contentStream.setFont( font, 12 );
      contentStream.moveTextPositionByAmount( 100, 700 );
      contentStream.drawString( "Hello World" );
      contentStream.endText();
      contentStream.close();
      
      document.save( "Hello World.pdf");
      document.close();
      

      The workaround at this moment is to use PDPageContentStream.appendRawCommands("50 Tz");
      But this method is deprecated.

      Attachments

        Activity

          People

            tilman Tilman Hausherr
            jnovacho Jose Novacho
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: