spire.doc can not convert data from doc/rtf file to pdf - spire.doc

I am using spire.office. It is converting data from excel to pdf successfully but not from the document or RTF file. It is showing the following error
Could not load type 'spr᝚' from assembly 'Spire.Doc, Version=, Culture=neutral, PublicKeyToken=663f351905198cb3' because it attempts to implement a class as an interface.
Please check it and gives some advice. Thanks in advance
File.WriteAllText(filepath + ".rtf", fileText);
Document doc = new Document(filepath + ".docx", Spire.Doc.FileFormat.Docx);
//doc.LoadFromFile(filepath + ".docx",Spire.Doc.FileFormat.Docx);
doc.SaveToFile(filepath + ".pdf");

When converting files to PDF, you also need to add Spire.Pdf.dll. If not, it might throw that kind of "spr" error. Additionally, you should specify the FileFormat as PDF: doc.SaveToFile(filepath + ".pdf", FileFormat.PDF);

Do you load license beforehand?


Apex Error (Image to PDF conversion) : BLOB is not a valid UTF-8 string

So i have this task where i have to convert the image uploaded in Notes and Attachment object to PDF. For that i created a trigger(before insert) on Attachment object and used the below mentioned code,
I used the standard EncodingUtil to convert the image Body in the proper format,
I tried this code
attachmentObj.Body = blob.toPdf(attachmentObj.Body.toString());
But i get the error message "BLOB is not a valid UTF-8 string",
So after some research i also used tried this,
String encodeStringBody = EncodingUtil.base64Encode(attachmentObj.Body);
attachmentObj.Body = blob.toPdf(encodeStringBody);
But the attachment created have ineligible body. I cannot see anything when i 'view file' in the attachment object.
I expect the file to be converted to PDF but both the code i used have problems.
Please help me with this if anyone find solution to the problem.

Transferring my dynamic value from response data to excel file in Jmeter

I want to actually transfer my dynamic value from the response data to Excel file in Jmeter... can anyone plz let me know the clear process for it ?
I used beanshell post processor but dint got the expected output...
Take a look at Apache POI - Java API To Access Microsoft Excel Format Files, this way you will be able to create, read and update Excel files from Beanshell code. The easiest way to add binary documents formats support to JMeter is using Apache Tika, given you have tika-app.jar in JMeter Classpath you will be able to view Excel files contents using View Results Tree listener and use Apache POI API to manipulate Excel files.
Minimal working code for creating an Excel file and adding to it JMeter variable value looks like:
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("Sheet1");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
FileOutputStream fileOut = new FileOutputStream("FileCreatedByJMeter.xlsx");
Busy Developers' Guide to HSSF and XSSF Features
How to Extract Data From Files With JMeter

ServletOutputStream byte array to pdf corrupt pdf

I use tomcat 7.0.53, Struts 1.2.7, Spring 3.1.1. This is my code:
File file = new File("C:\\pdf\\" + report.getFileName());
FileOutputStream fos = new FileOutputStream(file);
response.addHeader("Content-disposition", "application; filename="
+ report.getFileName());
ServletOutputStream outputStream = response.getOutputStream();
The file I get is right no problem there. But the file I get from response is corrupted. I tried to set encoding to response, tried to turn on spring CharacterEncodingFilter, tomcats SetCharacterEncodingFilter. Nothing helps. Where should I look at?
p.s. this code is in Struts Action execute method
you might want to save the result that you get from your webserver and compare it with the correct pdf. This way you'll see if there are some extra bytes at beginning or end, differences in encoding or whatever else is different.
Remove response.setContentLength(report.getData().length); and try if it works, by doing this you also enable chunked data transmission.
I needed to return a null instead of an ActionForward so Struts knows the response was handled within the action.
I had the similar issue - corrupted binary pic. upon the download.
Then while downloading TXT/XML files, I have noticed few blank lines at the beginning the text body.
Using the suggestion above on JSP, I removed all line breaks in my JSP page which manages the download.
So all jsp and server tags follow in one single line:
<jsp:useBean.. ><%..response. ;response.setStatus(HttpServletResponse.SC_RESET_CONTENT);return; %>
This removed extra blank lines in TXT/XML and solved binary corruption issue as well.
Olaf, thank you for the clue

Issues in Updating Metadata while Generating PDF

I am working on a Extend Script which saves FrameMaker Book as a PDF. The script is able to save to the PDF but when I tried to add the PDF Metadata (Author/CreationDate/Keywords/Subject/Title) etc, the same does not reflect in the generated PDF.
On Closure inspection I found that Metadata elements were not added to PDFDocInfo property of the Book.
Here is the code which I wrote to update the Author Details in PDFDocInfo
$.writeln("Length before" + doc.PDFDocInfo.length);
doc.PDFDocInfo.push("Mr Bond");
$.writeln("Length after" + doc.PDFDocInfo.length);
where doc is an Object of type Book
The output is
Length before0
Length after0
Should the PDFDocInfo not have 2 elements in it now. Am I missing any thing here ?
The following code did the trick...
var pdfDocInfo = new Strings();
pdfDocInfo.push("Mr Bond");
book.PDFDocInfo = pdfDocInfo;

axlsx serialize spreadsheet to string

For testing purposes, I'd like to serialize an axlsx spreadsheet to a string. The axlsx documentation indicates it is possible to "Output to file or StringIO". But I haven't found documentation or a code sample that explains how to output to a StringIO. How is it done?
From the code:
# Serialize to a stream
s = package.to_stream()
File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
In the end, an [xlsx] file is zip archive containing multiple xml files and other assets. You can use Package#to_stream to generate an IO stream for streaming purposes, but viewing that archive as a string is probably not what you are looking to do.
If you are just looking to investigate the xml for a specific Worksheet, you can use Worksheet#to_xml_string which will return a String object with all the goodies in there. (That is how worksheet validation works, we parse that XML and validate it against the schema for the object)
Hope this help!