Creating pdf from docx rendering library issue - pdf

If you know smth about this theme please leave a comment. I am trying to get pdf file from docx using phpoffice/word. But i cant make it real because for whole day testing i get only this error:
PHP Fatal error: Uncaught exception 'PhpOffice\PhpWord\Exception\Exception' with message 'PDF rendering library or library path has not been defined.
Please don't tell me to look this question in www, i tried - nothing helpful. My code:
require './vendor/autoload.php';
require './vendor/phpoffice/phpword/bootstrap.php';
$filename = 'example';
echo PHPWORD_BASE_DIR . '/TCPDF-master';
$wordPdf = \PhpOffice\PhpWord\IOFactory::load("./file_to_fill/ДКП квартира физики.docx");
$rendererName = \PhpOffice\PhpWord\Settings::PDF_RENDERER_TCPDF;
$rendererLibrary = 'TCPDF';
$rendererLibraryPath = dirname(__FILE__).'/'. $rendererLibrary;
\PhpOffice\PhpWord\Settings::setPdfRendererPath($rendererLibraryPath);
\PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF');
$pdfWriter = \PhpOffice\PhpWord\IOFactory::createWriter($wordPdf , 'PDF');
if (file_exists($filename.".pdf")) unlink($filename.".pdf");
$pdfWriter->save($filename.".pdf");
I know that my problem is library, but i really can't understand where the file of this library is. May be it happens because today for the first time i was trying to work with composer. I tried different library like dompdf and TCPDF and my be some others.
So if you have any ideas welcome.=)

So after many hours of searching and testing i got the working code. May be i am not only one need this.
For TCPDF library:
define('PHPWORD_BASE_DIR', realpath(__DIR__));
require './vendor/autoload.php';
require './TCPDF-master/tcpdf.php';
$PdfPath = realpath(PHPWORD_BASE_DIR . '/TCPDF-master');
\PhpOffice\PhpWord\Settings::setPdfRendererPath($PdfPath);
\PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF');
$phpWord = \PhpOffice\PhpWord\IOFactory::load('yourtemplate.docx');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF');
$xmlWriter->save('result.pdf');
For mpdf library:
define('PHPWORD_BASE_DIR', realpath(__DIR__));
require './vendor/autoload.php';
require './vendor/mpdf/mpdf/mpdf.php';
$PdfPath = realpath(PHPWORD_BASE_DIR . '/vendor/mpdf/mpdf');
\PhpOffice\PhpWord\Settings::setPdfRendererPath($PdfPath);
\PhpOffice\PhpWord\Settings::setPdfRendererName('MPDF');
$phpWord = \PhpOffice\PhpWord\IOFactory::load('temp.docx');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF');
$xmlWriter->save('result.pdf');
But the the domPDF doesn't work at all(
So this two libraries works but not good, one of it gives me "???" when i input the Russian text. And both of them gives a lot of different free space in document (may be margin). And i can't understand how edit it.

Related

syncfusion.pdf.pdfException"Could Not Find valid signature (%pds-).'

string docuAddr = #"C:\Users\psimmon\source\repos\PDFTESTAPP\PDFTESTAPP\TempForms\forms-www.courts.state.co.us-Forms-PDF-JDF1117.pdf";
byte[] bytes = Encoding.Unicode.GetBytes(docuAddr);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(bytes, true);---blows here
PdfLoadedForm myForm = loadedDocument.Form;
PdfLoadedFormFieldCollection fields = myForm.Fields;
not sure what I have done wrong here, but the PDF file is opening, either in a browser or a fileexployer window. so it has to be me, guessed at most of this, all you very smart folks, I could use your gray matter. forgive my stupidity.
The reported exception “could not find valid signature (%PDF-)” may occurs due to the file is not a PDF document. We suspect it seems the other format files are saved with the “.pdf” extension. We could not open and repair this type of document on our end, we have already added the details in our documentation,
Please find some of the following corrupted error messages that cannot be repaired:
UG: https://help.syncfusion.com/file-formats/pdf/open-and-save-pdf-file-in-c-sharp-vb-net#possible-error-messages-of-invalid-pdf-documents-while-loading
If you want to find this type of corrupted document, Syncfusion PDF Library provides support to check and report whether the existing PDF document is corrupted or not with corruption details and structure-level syntax errors.
UG: https://help.syncfusion.com/file-formats/pdf/working-with-document#find-corrupted-pdf-document
Blog: https://www.syncfusion.com/blogs/post/how-to-find-corrupted-pdf-files-in-c-sharp.aspx
KB: https://www.syncfusion.com/kb/9686/how-to-identify-the-corrupted-pdf-document-using-c-and-vb-net

Pear Quickform2 File Upload handling

I'm trying to build a proper file upload handling via Pear quickform 2.
My serverside approach would be:
$submitValues = $editForm->getValue();
$filename = submitValues['uploaded_image']['name'];
$move_file = move_uploaded_file(.....)
Is there still a function like in quickform1: isUploadedFile() to make sure its an uploaded file?
unfortunately searching the documentary didn't give me the hints I needed.
Any advice regarding this issue is very much appreciated.
You can use the php function directly :
is_uploaded_file($submitValues['uploaded_image']['tmp_name']);
See http://php.net/is_uploaded_file

an error 3013 thrown when writing a file Adobe AIR

I'm trying to write/create a JSON file from a AIR app, I'm trying not so show a 'Save as' dialogue box.
Here's the code I'm using:
var fileDetails:Object = CreativeMakerJSX.getFileDetails();
var fileName:String = String(fileDetails.data.filename);
var path:String = String(fileDetails.data.path);
var f:File = File.userDirectory.resolvePath( path );
var stream:FileStream = new FileStream();
stream.open(f, FileMode.WRITE );
stream.writeUTFBytes( jsonToExport );
stream.close();
The problem I'm having is that I get a 'Error 3013. File or directory in use'. The directory/path is gathered from a Creative Suite Extension I'm building, this path is the same as the FLA being developed in CS that the Extension is being used with.
So I'm not sure if the problem is that there are already files in the directory I'm writing the JSON file to?
Do I need to add a timer in order to close the stream after a slight delay, giving some time to writing the file?
Can you set up some trace() commands? I would need to know what the values of the String variables are, and the f.url.
Can you read from the file that you are trying to write to, or does nothing work?
Where is CreativeMakerJSX.getFileDetails() coming from? Is it giving you data about a file that is in use?
And from Googling around, this seems like it may be a bug. Try setting up a listener for when you are finished, if you have had the file open previously.
I re-wrote how the file was written, no longer running into this issue.

FileUploadDialogHandler()

I am trying to automate a web app which involves selecting an existing file using a fileuploaddialoghandler() method and entering the full path in the file name dropdown then Open click.
However, when I attempt this using this code
FileUploadDialogHandler fileupload = new FileUploadDialogHandler(#"C:\TIFFiles\Testtif.TIF");
//browser.WaitForComplete();
using (new UseDialogOnce(browser.DialogWatcher, fileupload))
{
newIee.Button(Find.ById("ctl00_WebPartManager1_FileUpload_FileBrowse")).ClickNoWait();
browser.AddDialogHandler(fileupload);
browser.WaitForComplete();
browser.RemoveDialogHandler(fileupload);
}
It does not work.
What else should I be doing?
Thanks much!
W
I just have one question about your code... What is newIee? I can't tell by looking at the code if newIee is attached to browser. Other than that, your FileUpdateDialogHandler should be fine.
If you can provide the code where you declare newIee, it might add me in determining if it's a factor causing your code not to work properly.

itext outofmemory error while attempting to count the number of pages in a pdf file

I'm trying to execute the following code:
PdfReader reader = new PdfReader("/path/to/file.pdf");
int pages = reader.getNumberOfPages();
It works on most files, but on one particular file, it crashes with error:
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:572)
at java.lang.StringBuffer.append(StringBuffer.java:320)
at com.itextpdf.text.pdf.PRTokeniser.readString(PRTokeniser.java:158)
at com.itextpdf.text.pdf.PRTokeniser.getStartxref(PRTokeniser.java:224)
at com.itextpdf.text.pdf.PRTokeniser.getStartxref(PRTokeniser.java:229)
...goes on for a while
at com.itextpdf.text.pdf.PRTokeniser.getStartxref(PRTokeniser.java:229)
I know that it's something wrong with the input file. I'm just wondering if there's a way of knowing before attempting to make the method call, that the file is going to cause a problem.
It turns out it was a bug with the version of itext I am using (5.0.1). I logged a query with the developers, and a fix was put in - that I tested - and which hopefully will find it's way into the next version (5.0.2)