iText7 - Unable to add nested SVG using convertToImage - pdf

I am unable to add nested svg(svg having another svg inside them) using convertToImage(InputStream stream, PdfDocument document) of iText.
Error log shows something like this -
c.i.s.r.r.ResourceResolver : Unable to retrieve image with data URI data:image/svg+xml;base64,PHN2ZyiusaPijhd78KJGKGKuuis79sgdf.........long string
Kindly let me know how can we solve this. TIA.

Related

After content stream recreation (using PDFbox) getting error in axesPDF (insert spaces)?

when I am recreating a pdf after some changes , if I use the output pdf in axesPDF to fix spaces issue I am getting "ERROR". The only difference I observed my input pdf have Array of tokens but my recreated pdf has Dictionary of elements. As shown in below. Does that cause the problem? How can I recreate similar structure? (Left one is input pdf right one output pdf after editing)
Input pdf
output pdf with changes
The code I am using to save the pdf is
PDStream newContents = new PDStream(document);
OutputStream out = newContents.createOutputStream(COSName.FLATE_DECODE);
ContentStreamWriter writer = new ContentStreamWriter(out);
writer.writeTokens(tokens);
out.close();
document.getPage(pg_ind).setContents(newContents);
newPDF.addPage(document.getPage(pg_ind));
newPDF.save()
Please help me on this. Thanks in advance.
Updating question along with error.
Another Input file
The error is
The button I used.
I am wondering this time even the content stream is in COSDictionary format it's giving error. Something else causing this.

Is it possible to save a base64 string as an image in a image file using only PhantomJS?

I'm trying to capture a particular element on a web page using PhantomJS. Using getBoundingClientRect(), I'm able to clip Off the unnecessary elements(for which the entire page gets rendered and then clipped). Now I'm to trying to focus and capture a particular canvas component and store it in an image file. Once base64 string is obtained, how do I save base64 string as an image in an image file without the aid of any utility like casperjs? The below code doesn't work for me.
img = chart1.canvas.toDataURL();
ext = img.split(';')[0].match(/jpeg|png|gif/)[0];
data = img.replace(/^data:image\/\w+;base64,/, "");
fs.write('myChart.png', data, 'w');

Docx4J: Vertical text frame not exported to PDF

I'm using Docx4J to make an invoice model.
In the left-side of the page, it's usual to show a legal sentence as: Registered company in ... Book ... Page ...
I have inserted this in my template with a Word text frame.
Well, my issue is: when exporting to .docx, this legal text is shown perfect, but when exporting to .pdf, it's shown as an horizontal table under the other data.
The code to export to PDF is:
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setFoDumpFile(foDumpFile);
foSettings.setWmlPackage(template);
fos = new FileOutputStream(new File("/C:/mypath/prueba_OUT.pdf"));
Docx4J.toFO(foSettings, fos, Docx4J.FLAG_EXPORT_PREFER_XSL);
Any help would be very appreciated.
Thanks.
You'd need to extend the PDF via FO code; see further How to correctly position a header image with docx4j?
Float left may or may not be easy; similarly the rotated text.
In general, the way to work on this is to take the FO generated by docx4j, then hand edit it to something which FOP can convert to a PDF you are happy with. If you can do that, then its a matter of modifying docx4j to generate that FO.

Images in Html to PDF using wkhtmltopdf in mvc 4

I am using wkhtmltopdf to convert html to pdf. I am using mvc 4. I was able to convert html to pdf. The only problem I have is that images do not render. There is small rectangle where image should appear. I have my images in database so when I get html string in my controller this is how image is shown right before I pass this string to converter:
<img src="/Images/Image/GetImageThumbnail?idImage=300" alt=""/>
So I am thinking that this approach is not working becuase I pass string to converter so image cannot be rendered. Any ideas how to solve this problem if images are in db?
I solve a similar issue by replacing src from src="/img/derp.png" to src="http://localhost/img/derp.png". I get the host part from the request that my Controller receives.
// Here I'm actually processing with HtmlAgilityPack but you get the idea
string host = request.Headers["host"];
string src = node.Attributes["src"].Value;
node.Attributes["src"].Value = "http://" + host + src;
This means that the server must be also be able to vomit images directly from URLs like that.
I guess it could be done with string.Replace as well if your HTML is in a string
string host = request.Headers["host"];
html = html.Replace("src=\"/", "src=\"http://"+host+"/"); // not tested

How to generate PDF using sfTCPDFPlugin in symfony 1.4?

I want to get a pdf of post details , so I installed sfTCPDFPlugin. I'm a new to it so can any one help me with this?
How to generate PDF using sfTCPDFPilugin in symfony 1.4?
The main problem you seems to have is to get the HTML output from your template to put it into the generated PDF. For that, you can use getPartial or getPresentationFor.
getPartial will render a partial
getPresentationFor will render a module/action
I recommend you to use the getPartial. Create a partial with the content you want to extract (and by the way, you will be able to use the same partial elsewhere if you need the same information to be viewable as html).
Assuming you create a partial called _my_partial.php, you can do that:
public function executePdf()
{
$config = sfTCPDFPluginConfigHandler::loadConfig();
/* put all your PDF configuration */
$html = $this->getPartial(
'my_partial',
// put in this array all variables you want to give to the partial
array('posts' => $posts)
);
$pdf->writeHTMLCell(
$w=0,
$h=0,
$x='',
$y='',
$html,
$border=0,
$ln=1,
$fill=0,
$reseth=true,
$align='',
$autopadding=true
);
$pdf->Output('example_001.pdf', 'I');
throw new sfStopException();
}
Refer link for step by step to generate PDF using sfTCPDFPlugin.
http://www.symfony-project.org/plugins/sfTCPDFPlugin/1_6_3?tab=plugin_readme