Aspose .Doc or .Docx convert to Single-Page Tiff - tiff

How can one use Aspose to convert .Doc or .Docx into a Single-Page Tiff? I know how to make a multi-page tiff but i'm wanting to have separate files for each page.

You can use the following 'Aspose.Words for .NET' code to save each page in your Word document to single page TIFF image:
Document doc = new Document(MyDir + "in.docx");
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
options.PageCount = 1;
for (int i = 0; i < doc.PageCount; i++)
{
options.PageIndex = i;
doc.Save(MyDir + "Out" + i + ".tiff", options);
}
I work with Aspose as Developer Evangelist.

Related

Flying Saucer - Open an attachment from pdf link

I would like to know if there is a way to create a link (Using HTML) to open an attachment embedded in the pdf document.
Something like this...
Open the attachment file or Open the attachment file
Any suggestion or recommendation?
Thanks
I have been able to implement this scenario after reading the next useful post
https://groups.google.com/forum/#!topic/flying-saucer-users/KuwPoTjaQYU
Steps:
Check out the next repository https://github.com/osnard/flyingsaucer
Analyse the file ITextOutputDevice.java, method processLink(RenderingContext c, Box box)
Make changes based on your needs
Build the project and use the jar file generated
Here the code to create an embedded file based on base64 content.
Java
...String doEmbedFile = handler.getAttributeValue( elem, "data-fs-embed-file" );
if ("true".equals(doEmbedFile.toLowerCase())) {
String fileName = new File(uri).getName();
String content = handler.getAttributeValue( elem, "content" );
com.lowagie.text.Rectangle targetArea = checkLinkArea(c, box);
if (targetArea == null) {
return;
}
try {
if (!_attachments.contains(fileName)) {
byte[] fileBytes = Base64.getDecoder().decode(content.getBytes("UTF-8"));
PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(_writer, null, fileName, fileBytes);
fs.addDescription(fileName, true);
_writer.addFileAttachment(fs);
_attachments.add(fileName);
}
targetArea.setBorder(0);
targetArea.setBorderWidth(0);
//This only works on Adobe Acrobat Reader
PdfAction action = PdfAction.javaScript(
"this.exportDataObject({cName:\"" + fileName + "\", nLaunch:2});",
_writer
);...
HTML
<body><div id='div1'><p><a href='test.png' data-fs-embed-file='true' content='iVBORw0KGgoAAAANSUhEU...'>open test.png file</a></p></div><div id='div2'><p><a href='test.pdf' data-fs-embed-file='true' content='JVBERi0xLjUNCiW1tbW1D...'>open test.pdf file</a></p></div><div id='div3'><p><a href='test.txt' data-fs-embed-file='true' content='VEVFRUVFRUVFRVNUIFRYVA=='>open test.txt file</a></p></div></body>
*base64 content truncated
Output
Greetings and I hope it can help others
just open it on new tab, add attribute target="_blank" in your anchor tag
Open attachment

How to reduce the size of pdf in jspdf document

I am using jspdf for converting html to pdf by following code.
html2canvas(document.getElementById("page4")).then(
function(canvas) {
document.body.appendChild(canvas);
var context = canvas.getContext("2d");
var imgData4 = canvas.toDataURL("image/jpeg");
var doc = new jsPDF(options, "", "", "");
doc.addPage();
doc.addImage(imgData4, 'jpeg', 0, 0);
doc.save(enrId + ".pdf");
});
First im converting html to jpeg. I have 4 pages so each page is separate jpeg
Then i have assigned every page into pdf page
like that, im converting html to pdf.
I dont facing any problem here, but memory is a problem here
Here my problem is,
pdf size is around 1.5MB to 2MB. How can i reduce the pdf size?
If it is not possible, Suggest some other plugin for convert html to pdf
I've got the same problem using PNG, now I'm usig JPEG format, and the file size went from 6000 ko to 300 ko.
Try this code :
canvas.toDataURL( 'image/jpeg', 1.0 );
to vary the quality :
var fullQuality = canvas.toDataURL('image/jpeg', 1.0);
var mediumQuality = canvas.toDataURL('image/jpeg', 0.5);
var lowQuality = canvas.toDataURL('image/jpeg', 0.1);
More information in this page :
https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL

How to append GET parameter for every URL request from a browser?

For testing, I need to append "?testing=true" for every URL reference in my webpage.
For example, say webpage has an image "localhost/image/logo.png" I need to this should be converted to "localhost/image/logo.png?testing=true" when loaded on a browser.
I tried several plugins on firefox, which allows appending/modifying URL on submit, but my requirement is to change URL on load.
You might have some success with the Firefox Greasemonkey extension. You can use a script like this:
var parameter = '?testing=true'
for (var x = 0; x < document.images.length; x++) {
image = docuent.images[x];
image.src = image.src + parameter;
console.log(image.src);
}
for (x = 0; x < document.getElementsByTagName("link").length; x++) {
document.getElementsByTagName("link")[x].href = document.getElementsByTagName("link")[x].href + parameter;
}
It replaces all embedded images and stylesheets with the same files with "?testing=true" appended. However there are still requests to the original image before that.
Another option would be to use a local proxy such as Charles for URL rewriting.

HTML from Database to PDF

I need to generate pdf from html dynamically using asp.net. HTML is stored in database. HTML has tables and css, upto 10 pages. I have tried iTextSharp by directly passing html, it produces pdf which is not opening. Destination pdf.codeplex.com has no documentation, it produces PDF with styles from parent page.
Any other solution will be helpful.
I've tried many HTML to PDF solutions including iTextSharp, wkhtmltopdf and ABCpdf (paid)
I'm currently settled on PhantomJS a headless, open-source, WebKit-based browser. It is scriptable with a javascript API which is reasonably well documented.
The only disadvantage I found was that attempting to use stdin to pass HTML into the process was unsuccessful because the REPL still has some bugs. I also found that using stdout seemed to be a lot slower than simply allowing the process to write to disk.
The code below avoids stdin and stdout by creating the javascript input as a temp file, executing PhantomJS, copying the output file to a MemoryStream and cleaning up the temporary files at the end.
using System.IO;
using System.Drawing;
using System.Diagnostics;
public Stream HTMLtoPDF (string html, Size pageSize) {
string path = "C:\\dev\\";
string inputFileName = "tmp.js";
string outputFileName = "tmp.pdf";
StringBuilder input = new StringBuilder();
input.Append("var page = require('webpage').create();");
input.Append(String.Format("page.viewportSize = {{ width: {0}, height: {1} }};", pageSize.Width, pageSize.Height));
input.Append("page.paperSize = { format: 'Letter', orientation: 'portrait', margin: '1cm' };");
input.Append("page.onLoadFinished = function() {");
input.Append(String.Format("page.render('{0}');", outputFileName));
input.Append("phantom.exit();");
input.Append("};");
// html is being passed into a string literal so make sure any double quotes are properly escaped
input.Append("page.content = \"" + html.Replace("\"", "\\\"") + "\";");
File.WriteAllText(path + inputFileName, input.ToString());
Process p;
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = path + "phantomjs.exe";
psi.Arguments = inputFileName;
psi.WorkingDirectory = Path.GetDirectoryName(psi.FileName);
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
p = Process.Start(psi);
p.WaitForExit(10000);
Stream strOut = new MemoryStream();
Stream fileStream = File.OpenRead(path + outputFileName);
fileStream.CopyTo(strOut);
fileStream.Close();
strOut.Position = 0;
File.Delete(path + inputFileName);
File.Delete(path + outputFileName);
return strOut;
}

How to create a WinRT Book reader application

I'd like to create an application that receives formatted text (RTF) or html, renders it an show it page by page..
Is there any control that aims to do that?
I tried to use the RichEditBox control to load a file but it stucks during the operation:
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(#"myFile.rtf");
using (var memstream = await file.OpenReadAsync())
{
MainText.Document.LoadFromStream(Windows.UI.Text.TextSetOptions.ApplyRtfDocumentDefaults, memstream);
}
I tried to load an HTML file this way:
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(#"myFile.htm");
var stream = await file.OpenAsync(FileAccessMode.Read);
string app;
using (StreamReader rStream = new StreamReader(stream.AsStream()))
{
app = rStream.ReadToEnd();
}
myWebView.NavigateToString(app);
But I cannot find a way to "count" the lenght of the parsed text to chunk it in pages..
There is any other way or library to do that? Any example online?
If you want to show your HTML contents in pages then you can use RichTextBlock with RichTextBlockOverflow. RTF is not supported to RichTextBlock.
how to inject RTF file to RichTextBlock in c#/xaml Windows store app
Showing Html in WinRT with RichTextBlock or other component
XAML text display sample