when i copy content from generated word document and paste in google docs then i am facing formating issues like heading h1,h2 ect. not working in google docs. heading display like normal text.
when i copy content from generated word document and paste in google docs then i am facing formating issues like heading h1,h2 ect. not working in google docs. heading display like normal text.
hi any one can help me to resolve this issue. i am using basic version of phpdocx
Hello,
phpdocx includes and applies default styles when adding content. In the case of headings, phpdocx applies the following styles: Heading1PHPDOCX, Heading2PHPDOCX, Heading3PHPDOCX... that are included in the default base template of phpdocx.
Google Docs, and other DOCX editors, have limitations when working with DOCX documents and doesn't support some styles and contents from the OOXML standard used in DOCX documents.
In this case, Google Docs doesn't allow applying custom default style names when contents are copied and pasted, specific custom style names must be used. Instead of mystyle, myheading1, Heading1PHPDOCX or other custom style names, you need to include and use specific style names: Heading1, Heading2...
This requirement comes from Google Docs, not from phpdocx. Google Docs doesn't read heading information correctly from custom paragraph styles, it only allows speficic custom style names. With phpdocx you can use the required custom style names.
On Working with headings you can read all information about working with headings when generating DOCX documents.
In your script you can apply specific custom style names, importing them:
$docx = new CreateDocx();
$docx->importStyles('document_styles_headings.docx', 'merge');
$wordStyles = array('<h1>' => 'Heading1' , '<h2>' => 'Heading2');
$html = '
<h1>Heading 1</h1>
<h2>Heading 2</h2>
';
$docx->embedHTML($html, array('wordStyles' => $wordStyles));
or loading the DOCX as a template:
$docx = new CreateDocxFromTemplate('document_styles_headings.docx');
$wordStyles = array('<h1>' => 'Heading1' , '<h2>' => 'Heading2');
$html = '
<h1>Heading 1</h1>
<h2>Heading 2</h2>
';
$docx->embedHTML($html, array('wordStyles' => $wordStyles));
or you can also create and the custom paragraph styles using createParagraphStyle.
Following this information, you can use Google Docs preset style names. On https://www.phpdocx.com/en/forum/default/topic/2039 you can read this same question replied in the forum to another user.
Regards.
hi
i tried below code but it not working
$wordStyles = array('<h1>' => 'Heading1' , '<h2>' => 'Heading2'); $html = ' <h1>Heading 1</h1> <h2>Heading 2</h2> '; $docx->embedHTML($html, array('wordStyles' => $wordStyles));
i am generating docx from html and html is dynamic there is no spacific format for docx. how can i create template and define style for heading
Hello,
All sample codes are fully tested and working.
As explained in our previous reply, phpdocx doesn't include Heading1, Heading2, Heading3 as custom paragraph style names in the default base template. If you need to use these custom paragraph style names you must import them from an external DOCX that includes them (generated with MS Word or any other DOCX editor) or use a custom template that includes them or create them.
Please read our previous reply that details everything about this question.
Also, please note that phpdocx includes default CSS styles applied when transforming HTML. These default CSS styles can be changed applying new CSS styles when importing HTML.
Regards.
hi
i created word file custom_template.docx in microsoft word and upload that in server and performed bellow code
$docx = new CreateDocxFromTemplate('custom_template.docx');
$wordStyles = array('<h1>' => 'Heading1' , '<h2>' => 'Heading2');
$html = '
<h1>Heading 1</h1>
<h2>Heading 2</h2>
';
$docx->embedHTML($html, array('wordStyles' => $wordStyles));
still it's not working i also tried below code
$docx = new CreateDocx();
$docx->importStyles('custom_template.docx', 'merge');
$wordStyles = array('<h1>' => 'Heading1' , '<h2>' => 'Heading2');
$html = '
<h1>Heading 1</h1>
<h2>Heading 2</h2>
';
$docx->embedHTML($html, array('wordStyles' => $wordStyles));
Hello,
Does your DOCX contain the custom styles you want to use? To include custom styles in a DOCX with MS Word is not enough to generate an empty DOCX. Contents with the needed styles must be added, otherwise MS Word won't include them in the DOCX.
For futher support, please send the custom_template.docx file you are using to contact[at]phpdocx.com and we'll check it.
Regards.