First of all, this is my first question on the site and I just want to thank all of you for helping out newbs like me. I have found so much invaluable information on this site! It has helped me with so much along my programming journey.
So here is my question. I have used OpenTBS (PHP class) to fill a .docx template with dynamic data and to insert an image in the document.
The image is inserted by entering the following command into the alternate text of the image:
[onshow.logo_location;ope=changepic;tagpos=inside;adjust=100%;]
I have a variable that I have set as $logo_location that points to the image that is to be inserted.
This step works perfectly. A docx file is created with the appropriate image in the right location.
When I try to convert this docx file to a PDF using phpdocx I get an error. The code to generate the pdf is the following:
require_once '../bbms/classes/phpdocx/classes/TransformDoc.inc';
require_once '../bbms/classes/phpdocx/classes/CreateDocx.inc';
$docx = new CreateDocx();
$document = new TransformDoc();
$document->setStrFile('199.docx');
$document->generatePDF();
The error I get is the following:
Unable to generate PDF file. exception 'DOMPDF_Exception' with message 'Unknown image type: ?image=opentbs1.' in C:\wamp\www\bbms\classes\phpdocx\pdf\include\image_cache.cls.php:188 Stack trace: #0 C:\wamp\www\bbms\classes\phpdocx\pdf\include\image_frame_decorator.cls.php(88): Image_Cache::resolve_url('?image=opentbs1', NULL, '', '') #1 C:\wamp\www\bbms\classes\phpdocx\pdf\include\frame_factory.cls.php(199): Image_Frame_Decorator->__construct(Object(Frame), Object(DOMPDF)) #2 C:\wamp\www\bbms\classes\phpdocx\pdf\include\dompdf.cls.php(606): Frame_Factory::decorate_frame(Object(Frame), Object(DOMPDF)) #3 C:\wamp\www\bbms\classes\phpdocx\classes\TransformDoc.inc(328): DOMPDF->render() #4 C:\wamp\www\discount_database\test.php(23): TransformDoc->generatePDF() #5 {main}
For some reason, the location for the new image in the docx file is being passed as "?image=opentbs1." to the static function resolve_url() in image_cache.cls.php.
When I tried to convert a normal docx file that wasn't created using OpenTBS, I didn't get this error. I checked what a valid url being sent to resolve_url() would look like and it looks like this:
"files/files_invoice_template.docx/media/word/media/image1.png"
Is there a way to configure openTBS to correctly set an inserted image's url / location?
Thank you!!
I don't use PHPDOCX or make PDFs from my OpenTBS stuff, but it looks like PHPDOCX has hardcoded the relationship name into their image recognition. Just looking at the code on github, it looks like if you change line 239 in
phpDocx/classes/TransformDoc.inc.php
:to something like
Since all images switched in by OpenTBS use
opentbs
as a prefix to avoid conflicts with existing elements.I'm no regular expression expert, so lets call this pseudo code. Hope it points you in the right direction at least.