You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Tim Mann <ha...@gmail.com> on 2022/01/29 00:49:45 UTC

Help with line needed

Greetings,

I have written an application in Java version 8.281 that uses PDFBOX
2.0.22.  The program reads in some user input and creates a form in PDF
format.  Part of the code is to draw a solid line across the top of
the page footer.   I use the following code to do this.

public static void writeFooter(PDPageContentStream content,PDPage page,
PDFont font,int fontSize)throws IOException {
            float fullPageWidth = page.getMediaBox().getWidth();
            // draw a line across the page above the footer
            content.setLineWidth(1);
            content.setLineDashPattern (new float[]{1}, 0); // reset lines
to solid // added 01262022
            content.moveTo(pageLeftMargin, marginBottom + ( 2 *
LINE_SPACING_12) );// x,y
            content.lineTo(fullPageWidth - rightMargin, marginBottom +
((float) 2 * LINE_SPACING_12));
            content.closeAndStroke();

There is more code in this method that writes text in the page footer, but
that is not germane to the issue.    Again there has been no change to this
section of code other than I added the setLineDashPattern in an attempt to
fix the issue, but it didn't work.

The page size is selectable in the program.  The following is a snippet of
how pages are created based on the user's selection of desired paper size;

public static PDPage createPage() {

    switch (JavaManifestFormatter.pageSize){
        case "Letter":
            if(pageOrientationIsLandscape == true){
                return new PDPage(new
PDRectangle(PDRectangle.LETTER.getHeight(),
PDRectangle.LETTER.getWidth())); // PDRectangle expects width, height
            }
            else {
                return new PDPage(PDRectangle.LETTER); // set page size to
8.5 x 11.0" = US letter
            }
        case "A4":
            if(pageOrientationIsLandscape == true){
                return new PDPage(new
PDRectangle(PDRectangle.A4.getHeight(), PDRectangle.A4.getWidth())); //
PDRectangle expects width, height
            }
            else {
                return new PDPage(PDRectangle.A4);
            }
Additional code creates other page sizes.

As would be expected from the above code, a solid line is drawn on the page
a couple of lines up from the bottom of the page.  The program works fine
with page sizes of letter, legal, & A3.  However if I choose a page size of
A4, 5, or 6, the line in the footer becomes a dashed line.  If I go back to
letter, legal, or A3 paper size, the line is again a solid line.  I have
looked and looked and I can't find any information to help with this.   Is
there a known issue with drawing lines on certain page sizes?  Can anyone
point out  a code fix for this issue?  Would upgrading PDFBOX to version
2.0.25 help with this issue?

Thanks for the assistance

-- 
Regards,

Tim Mann

Re: Help with line needed

Posted by Tim Mann <ha...@gmail.com>.
Thanks. That resolved my issue. 

Tim Mann
Sent from my iPhone

> On Jan 29, 2022, at 1:07 AM, Tilman Hausherr <TH...@t-online.de> wrote:
> 
> 
> Am 29.01.2022 um 01:49 schrieb Tim Mann:
>>             content.setLineDashPattern (new float[]{1}, 0); // reset lines
>> to solid // added 01262022
> No that's a dash pattern of length 1. use "(new float[0], 0)".
> 
> <2NaW6tAWeapOLnFt.png>

Re: Help with line needed

Posted by Tammy Savage <ta...@icloud.com.INVALID>.
Bbcbmb

> On 29 Jan 2022, at 12:01, Tilman Hausherr <TH...@t-online.de> wrote:
> 
> Am 29.01.2022 um 01:49 schrieb Tim Mann:
>>             content.setLineDashPattern (new float[]{1}, 0); // reset lines
>> to solid // added 01262022
> No that's a dash pattern of length 1. use "(new float[0], 0)".
> 
> <2NaW6tAWeapOLnFt.png>
> 


Re: Help with line needed

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 29.01.2022 um 01:49 schrieb Tim Mann:
>              content.setLineDashPattern (new float[]{1}, 0); // reset lines
> to solid // added 01262022

No that's a dash pattern of length 1. use "(new float[0], 0)".