Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A full page of text generates a blank page break. #475

Open
Bricobit opened this issue Jan 28, 2015 · 8 comments
Open

A full page of text generates a blank page break. #475

Bricobit opened this issue Jan 28, 2015 · 8 comments

Comments

@Bricobit
Copy link

Bricobit commented Jan 28, 2015

Suppose that a sheet Word have a 10 lines of text max, if we insert the 10 lines of text using a TextRun "dynamically" should have a single sheet but as phpword inserts a line break after any element such as a TextRun then generates a second blank page.

At the end of an element TextRun sends the cursor to the next line when the cursor should be behind the last letter.

Sample code:
.......
//the text recovered from database filled an entire sheet and causes a blank second page
$tr = $section->addTextRun('pStyle');
$tr->addText(h("Tittle: "),'AB11');
$tr->addText($databaseText,null,array('spaceAfter' => 0));

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save("doc.docx");
?>

Take a look at the picture for a better understanding
linebreakproblems

You can not create a property that allows enable or disable the line break after an element TextRun?

I have to fix it because it looks ugly, ¿how i can locate the code responsible for inserting page breaks so I can make a botch?


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@nafwa03
Copy link

nafwa03 commented Jan 29, 2015

I am not one of the developers but I bet it is a paragraph node w:p automatically. Maybe? A separate function should be created to find EOL and determine if w:tr,w:t, etc...? Determine page size first and put fixes in accordingly? I haven't studied the code enough and just trying to help...

@Bricobit
Copy link
Author

You're right it would be necessary to determine the size to see if the blade is complete and thus allow or disallow automatic line break, but I have no idea how to fix it, there must be some function in the library that already perform this calculation because there paragraph elements which are to be forced to not cut or the property cantSplit of the tables elements.

@nafwa03
Copy link

nafwa03 commented Jan 29, 2015

I know not ideal but did you try creating a single row/col invisible table and putting the content in that to see if it still causes the break? Like an additional wrapper?

@Bricobit
Copy link
Author

yes, it was the first thing I tried and fails, after the table a new line is also generated.

At the end I leave as impossible I can not waste any more time, there are few cases in which the sheet is completed to the last line, so when a blank sheet that erased manually is generated.

Thanks for the help, go looking now and then this problem if somebody finds a solution.

good luck

@nafwa03
Copy link

nafwa03 commented Feb 1, 2015

Yeah I hear your frustration. The only other solution I can think of would be to create a separate page with a bookmark on said pages that could be blank. Insert these macros below and then call php com to run it after document is rendered...?

Sub GotoBadPage()
Selection.GoTo What:=wdGoToBookmark, Name:="BadPage"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub

Sub DeleteBadPage()
Application.Run MacroName:="GotoBadPage"
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub

Then in your php after render do this:
$word=new COM("Word.Application") or die("Cannot start MS Word");
$word->visible = 1;
$word->Documents->Open($file_with_path);
$word->Application->Run("DeleteBadPage");
$word->Quit();

You could also find another macro that searches for blank pages and deletes accordingly. I have seen them out there. You will have to save the doc as a docm which I am not sure is possible with phpword.

@Bricobit
Copy link
Author

Bricobit commented Feb 5, 2015

thx its a posible solution

@cyberformed
Copy link

Not working. Needs to remove the blank page generated in last. Pls share your thoughts.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@github-actions github-actions bot added the Stale label Nov 18, 2022
@Progi1984 Progi1984 removed the Stale label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants