We are trying to send an image as a stream to a method in Grails 2.4.3.
def imgStream
imgStream = servletContext.classLoader.getResourceAsStream("/assets/Logo.jpg")
We call in another service to render the PDF
ByteArrayOutputStream output = licensePlanReportsService.renderLicensingPlanPDF(licensingPlanInstance, internal, imgStream)
We are using com.lowagie.text.Image from iText 2.1.7 and poi 3.9-20121203
if(imgStream) {
Image logo = Image.getInstance(imgStream.getBytes())
logo.scaleAbsolute(128.64, 88.32)
logo.setAbsolutePosition(25, 485)
document.add(logo)
}
The image is not rendering for us on our output the PDF report. Does this seem to be the correct way to render the image to the PDF?
This issue was resolved by changing the initial call by using the following code:
imgStream = grailsAttributes.getApplicationContext().getResource("Logo.jpg").getInputStream()
Instead of the initial way
imgStream = servletContext.classLoader.getResourceAsStream("/assets/Logo.jpg")
Thanks,
Tom
Related
I am creating a web application and I am using groupdocs for view pdf and other docs,
in one of the scenario I want to change particular page orientation of pdf document, I found groupdocs merger with a set of code from here and I modified that code with my expectations which is below,
string filePath = #"c:\sample.pdf";
OrientationOptions orientationOptions = new OrientationOptions(OrientationMode.Landscape, new int[] { 3, 4 });
using (Merger merger = new Merger(filePath))
{
merger.ChangeOrientation(orientationOptions);
merger.Save(filePath);
}
but I am getting the below error
Requested ChangeOrientation operation for ‘Pdf’ document type is not
supported
I tried this in groupdocs 21.8 version
I found groupdocs merger with a set of code from here
We cannot reproduce this issue using GroupDocs.Viewer for .NET rotate pages. Have a look at the blow screenshot and the code:
using (Viewer viewer = new Viewer(#"D:/test.pdf"))
{
PdfViewOptions viewOptions = new PdfViewOptions(#"D:/output.pdf");
viewOptions.RotatePage(1, Rotation.On90Degree);
viewer.View(viewOptions);
}
As you are using GroupDocs Viewer API to render/view documents. Please use the above mentioned code. However, this issue exists in GroupDocs.Merger for .NET and we are working on the fix.
I am currently triying to use an Inventor Automation to modify a drawing and then export it to the SVF Format for the Viewer. Therefore I used this sample project from an Autodesk developer:
https://github.com/akenson/da-extract-params
I tried the code for exporting a 3D Drawing as SVF and that works fine. But when I tried to export a 2D drawing (like a DWG) to SVF, the SVF Addin doesn't create a file.
The Problem appears in the Method CreateForgeViewable() in the SampleAutomation Class in the ExtractParamsPlugin Projekt. I think the problem could be the configuration of the options for the Addin... But I couldn't find a Documentation for the SVF Addin.
// Setup SVF options
if (oAddin.get_HasSaveCopyAsOptions(doc, oContext, oOptions))
{
oOptions.set_Value("GeometryType", 1);
oOptions.set_Value("EnableExpressTranslation", true);
oOptions.set_Value("SVFFileOutputDir", sessionDir);
oOptions.set_Value("ExportFileProperties", false);
oOptions.set_Value("ObfuscateLabels", true);
}
Is there any parameter, that I should set for exporting a DWG to a SVF? Or is there somewhere a documentation for this Plugin?
I would be really thankfull for a reply.
Best regards
Sebastian
Currently, we only support SVF for 3D from Design Automation of Inventor (DA4I). If you want SVF for 2D DWG you can either go through Model Derivatives, or output to PDF by DA4I and use it in Forge Viewer (by pdf.js), or output DWG from DA4I and then go to Design Automation of AutoCAD (DA4A) to export.
Here is sample how you can use your Bundle to export IDW to PDF
TranslatorAddIn PDFAddIn = (TranslatorAddIn)_inventorApplication.ApplicationAddIns.ItemById["{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}"];
if (PDFAddIn != null)
{
TranslationContext context = _inventorApplication.TransientObjects.CreateTranslationContext();
NameValueMap options = _inventorApplication.TransientObjects.CreateNameValueMap();
if (PDFAddIn.HasSaveCopyAsOptions[doc, context, options])
{
context.Type = IOMechanismEnum.kFileBrowseIOMechanism;
DataMedium dataMedium = _inventorApplication.TransientObjects.CreateDataMedium();
options.Value["Sheet_Range"] = PrintRangeEnum.kPrintAllSheets;
options.Value["Vector_Resolution"] = 300;
options.Value["All_Color_AS_Black"] = false;
options.Value["Sheets"] = GetSheetOptions(doc);
dataMedium.FileName = exportFileName;
PDFAddIn.SaveCopyAs(doc, context, options, dataMedium);
}
}
and then use PDF with Forge Viewer
viewer.loadExtension('Autodesk.PDF');
viewer.loadModel( [pdfUrl], { page: 1 }); // load page 1 by default
I really hope you will be able to help me out on this one.
I am new to pdf.js so for the moment, I am playing around with the pre-built version to see if I can integrate this into my web app.
My problem:
I am using tcpdf to generate a pdf file which I would like to visualize using pdf.js without having to save it to a file on the server.
I have a php file (generate_document.php) that I use to generate the pdf. The file ends with the following:
$pdf->Output('test.pdf', 'I');
according to the tcpdf documentation, the second parameter can be used to generate the following formats:
I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
D: send to the browser and force a file download with the name given by name.
F: save to a local server file with the name given by name.
S: return the document as a string (name is ignored).
FI: equivalent to F + I option
FD: equivalent to F + D option
E: return the document as base64 mime multi-part email attachment (RFC 2045)
Then, I would like to view the pdf using pdf.js without creating a file on the server (= not using 'F' as a second parameter and passing the file name to pdf.js).
So, I thought I could simply create an iframe and call the pdf.js viewer pointing to the php file:
<iframe width="100%" height="100%" src="/pdf.js_folder/web/viewer.html?file=get_document.php"></iframe>
However, this is not working at all....do you have any idea what I am overlooking? Or is this option not available in pdf.js?
I have done some research and I have seen some posts here on converting a base64 stream to a typed array but I do not see how this would be a solution to this problem.
Many thanks for your help!!!
EDIT
#async, thanks for your anwer.
I got it figured out in the meantime, so I thought I'd share my solution with you guys.
1) In my get_document.php, I changed the output statement to convert it directly to base64 using
$pdf_output = base64_encode($pdf->Output('test_file.pdf', 'S'));
2) In viewer.js, I use an XHR to call the get_document.php and put the return in a variable (pdf_from_XHR)
3) Next, I convert what came in from the XHR request using the solution that was already mentioned in a few other posts (e.g. Pdf.js and viewer.js. Pass a stream or blob to the viewer)
pdf_converted = convertDataURIToBinary(pdf_from_XHR)
function convertDataURIToBinary(dataURI) {
var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
var base64 = dataURI.substring(base64Index);
var raw = window.atob(base64);
var rawLength = raw.length;
var array = new Uint8Array(new ArrayBuffer(rawLength));
for (i = 0; i < rawLength; i++) {
array[i] = raw.charCodeAt(i);
}
return array;
}
et voilà ;-)
Now i can inject what is coming from that function into the getDocument statement:
PDFJS.getDocument(pdf_converted).then(function (pdf) {
pdfDocument = pdf;
var url = URL.createObjectURL(blob);
PDFView.load(pdfDocument, 1.5)
})
I created a custom extension for TYPO3 CMS.
It basically does some database queries to get text from database.
As I have seen, TYPO3 editor, transforms data before storing it in database so for example a link <a href="....." >Link</a> is stored as <link href>My Link Text</link> and so on for many tags like this.
when I query data from DB, I get it as it is stored in DB (<link href>My Link Text</link>)
so links are not displayed as they shoud. They display as normal text..
As far as I know there are two ways to go:
disable RTE transformations (how to do that?)
use lib.parseFunc_RTE (which i have no Idea how to configure it properly)
any idea?
thanks.
I guess you're not using Extbase and Fluid? Just as a reference, if you are using Extbase and Fluid for your extension you can render text from the RTE using Fluid:
<f:format.html>{bodytext}</f:format.html>
This uses lib.parseFunc_RTE to render the RTE text as HTML. You can also tell it to use a different TypoScript object for the rendering:
<f:format.html parseFuncTSPath="lib.my_parseFunc">{bodytext}</f:format.html>
Useful documentation:
parseFunc
Fluid format.html
I came across the same problem, but using EXTBASE the function "pi_RTEcssText" ist not available anymore. Well maybe it is, but I didn't know how to include it.
Anyway, here's my solution using EXTBASE:
$this->cObj = $this->configurationManager->getContentObject();
$bodytext = $this->cObj->parseFunc($bodyTextFromDb, $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.']);
This way I get the RTE formatted text.
I have managed to do it by configuring the included typoscript:
# Creates persistent ParseFunc setup for non-HTML content. This is recommended to use (as a reference!)
lib.parseFunc {
makelinks = 1
makelinks.http.keep = {$styles.content.links.keep}
makelinks.http.extTarget < lib.parseTarget
makelinks.http.extTarget =
makelinks.http.extTarget.override = {$styles.content.links.extTarget}
makelinks.mailto.keep = path
tags {
link = TEXT
link {
current = 1
typolink.parameter.data = parameters : allParams
typolink.extTarget < lib.parseTarget
typolink.extTarget =
typolink.extTarget.override = {$styles.content.links.extTarget}
typolink.target < lib.parseTarget
typolink.target =
typolink.target.override = {$styles.content.links.target}
parseFunc.constants =1
}
}
allowTags = {$styles.content.links.allowTags}
And denied tag link:
denyTags = link
sword = <span class="csc-sword">|</span>
constants = 1
nonTypoTagStdWrap.HTMLparser = 1
nonTypoTagStdWrap.HTMLparser {
keepNonMatchedTags = 1
htmlSpecialChars = 2
}
}
Well, just so if anyone else runs into this problem,
I found one way to resolve it by using pi_RTEcssText() function inside my extension file:
$outputText=$this->pi_RTEcssText( $value['bodytext'] );
where $value['bodytext'] is the string I get from the database-query in my extension.
This function seems to process data and return the full HTML (links, paragraphs and other tags inculded).
Note:
If you haven't already, it requires to include this file:
require_once(PATH_tslib.'class.tslib_pibase.php');
on the top of your extension file.
That's it basically.
I need to show four charts on a grails page in a grid layout with positions 11, 12, 21 and 22. Each chart is build with a code similar to:
<img src="${createLink(controller:'paretoChart', action:'buildParetoChart11')}"/>
The code for the chart building action is:
def buildParetoChart11 = {
def PlotService p11 = PlotService.getInstance()
def poList = paretoChartService.getParetoidPO()
def listCounter = 0
def idPO = poList[listCounter]
idPO.toString()
def String idPOvalue = idPO
def out = response.outputStream
out = p11.paretoPlot(out, idPOvalue)
response.setContentType("image/jpg")
session["idPOList11"] = poList
}
The Java p11.paretoPlot(out, idPOvalue) returns a BufferedImage of the chart inside the OutputStream, but it only works for one chart. The other three charts vary on the the order on each all pour actions are called.
PlotService was written by me, yes. In this implementation, I'm passing the OutputStream out I got from response.outputStream and the String idPOvalue to the Java method. plotPareto's implementation is as follows:
public OutputStream paretoPlot(OutputStream out, String po) throws IOException {
chart = buildParetoChart(po);// here the chart is actually built
bufferedImage = chart.createBufferedImage(350, 275);
ChartUtilities.writeBufferedImageAsJPEG(out, bufferedImage);
}
So, is there a way to make sure one action is completed before firing up the next one?
Thanks in advance!
each request to get an image is handled asynchronously by the browser. Each request runs in its own thread on the server. With img tags, the browser controls the GET requests to get the images, so I don't think you can easily guarantee the order, and nor should you have to.
Are you seeing any errors?
I would look at the firebug or equivalent output to see if the browser is getting an error. for any of the image requests.
I would also try attaching a debugger to your server.
Did you write the PlotService? You need to make sure it is thread safe.
Also, I dont see you reading any params, is there a separate action for each image?