Issue converting aspx file to image - wkhtmltoimage

I've been using TuesPechkin to create images of some HTML code from my application.
I'e been using the following code successfully when using HTML, but if I try to load ASPX files instead, the code doesn't work.
var htmlDocument = File.ReadAllText(#"C:\Dev\Git\Groups\viz\slides\Slide menu\003#Survey\form.aspx");
var document = new HtmlToImageDocument
{
ScreenHeight = 350,
ScreenWidth = 500,
Format = "png",
LoadSettings = new LoadSettings { WindowStatus = settings.WindowStatus ?? "load-complete" },
In = htmlDocument
};
IConverter converter =
new StandardConverter(
new ImageToolset(
new Win32EmbeddedDeployment(
new TempFolderDeployment())));
var resultBytes = converter.Convert(document);
I have even tried to read the HTML to string and load that, but it is not working.
I am using TuesPechkin version 2.1.1.

Related

Make text a link/annotation to invoke goTo other page action in PDF

How do I make plain text in a PDF a link to another part of the pdf document?
Currently, I'm post processing a PDF. I've identified two pages that should link pack to each other base on if two numbers (text object) are found in the page.
Is there a way I can convert that text to a clickable local link?
We have checked the reported query "Make text a link/annotation to invoke goto other page action in PDF" and prepared a test sample to meet your requirement. In this sample we have used PdfDocumentLinkAnnotation to navigate the internal document by click on text. Please check the sample and it is available in the below link for your reference.
Please find the sample from the following link.
Also please find the below UG documentation link to more details about PdfDocumentLinkAnnotation.
Code in link:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Interactive;
namespace ConsoleApplication1
{
class Program
{
public static string DataPathOutput
{
get
{
if (!Directory.Exists(System.Environment.CurrentDirectory + #"\..\..\Output\"))
Directory.CreateDirectory(System.Environment.CurrentDirectory + #"\..\..\Output\");
return System.Environment.CurrentDirectory + #"\..\..\Output\";
}
}
static void Main(string[] args)
{
// Creates a new PDF document
PdfDocument document = new PdfDocument();
// Creates a first page
PdfPage firstPage = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
PdfBrush brush = PdfBrushes.Black;
PdfGraphics graphics1 = firstPage.Graphics;
string inputText1 = "Sample Text-1";
graphics1.DrawString(inputText1, font, brush, 10, 40);
// Measure string size to use same size for annotation
SizeF size1 = font.MeasureString(inputText1);
RectangleF rectangle1 = new RectangleF(10, 40, size1.Width, size1.Height);
// Creates a second page
PdfPage secondPage = document.Pages.Add();
PdfGraphics graphics2 = secondPage.Graphics;
string secondPageInput = "Sample Text-2";
graphics2.DrawString(secondPageInput, font, brush, 10, 40);
// Measure string size to use same size for annotation
SizeF size2 = font.MeasureString(inputText1);
RectangleF rectangle2 = new RectangleF(10, 40, size2.Width, size2.Height);
// Add annotation for firstpage to link second page of PdfDocumet
PdfDocumentLinkAnnotation firstAnnotation = new PdfDocumentLinkAnnotation(rectangle1);
firstAnnotation.Color = new PdfColor(Color.Transparent);
firstAnnotation.Destination = new PdfDestination(secondPage);
// Use below comment for link specific part of page
//firstAnnotation.Destination.Location = new Point(10, 40);
firstPage.Annotations.Add(firstAnnotation);
// Add annotation for second page to link first page of PdfDocumet
PdfDocumentLinkAnnotation secondAnnotation = new PdfDocumentLinkAnnotation(rectangle2);
secondAnnotation.Color = new PdfColor(Color.Transparent);
secondAnnotation.Destination = new PdfDestination(firstPage);
// Use below comment for link specific part of page
//secondAnnotation.Destination.Location = new Point(10, 40);
secondPage.Annotations.Add(secondAnnotation);
// Save document on mentioned location
document.Save(System.IO.Path.Combine(DataPathOutput, "Output.pdf"));
document.Close(true);
}
}
}

Loading image to canvas using querySelector

In the code below $('#initialModel') is a button which opens up a file loader and $('#initialModelImage') is my canvas and am trying to load the image dynamically on to the canvas from the file uploader ,but am not able to see the uploaded image on the canvas.Could someone help me correct my code.Thanks.
$('#initialModel').on('change',function(e){
var modelFile=document.querySelector('#initialModel').files[0];
var reader=new FileReader();
if (modelFile)
reader.readAsDataURL(modelFile);
else
$('#initialModelImage').src = "";
reader.onloadend = function (_file)
{
var canv=document.getElementById("initialModelImage");
var ctx = canv.getContext('2d');
ctx.drawImage(reader.result,640,480);
}
});

Image lost from header when converting docX to PDF using Spire.doc library

I have created a docX using the docX library and have added an image in the header. However when I convert the docX to PDF using the Spire.doc library, the image is lost. Any idea why? Below is my code:
var doc = DocX.Create(fileName);
string url = #"C:\Users\Desktop\Capture.JPG";
Novacode.Image img = doc.AddImage(url);
Picture pic = img.CreatePicture();
doc.AddHeaders();
Header header_default = doc.Headers.odd;
Paragraph p1 = header_default.InsertParagraph();
p1.Append(headerText).Bold().Color(System.Drawing.Color.LightGray).FontSize(20);
p1.AppendPicture(pic);
doc.Save();
Document docS = new Document();
docS.LoadFromFile(fileName);
string pdfPath = #"C:\Users\Documents\toPDF.PDF";
docS.SaveToFile(pdfPath, FileFormat.PDF);
As you already use Spire.Doc in your code, why not use spire to create header in Word directly and then save the file to PDF file format. I tried following code and it works fine.
using Spire.Doc;
using System.Drawing;
using Spire.Doc.Documents;
namespace Doc2Pdf
{
class Program
{
static void Main(string[] args)
{
Document doc = new Document();
Section section = doc.AddSection();
HeaderFooter header = section.HeadersFooters.Header;
Paragraph p1 = header.AddParagraph();
Image image = Image.FromFile("pic.png");
p1.AppendPicture(image);
doc.SaveToFile("Header.pdf", FileFormat.PDF);
}
}
}

Arabic characters not showing while creating PDF in Windows Phone (WinRT)

I am creating a PDF using componentOne library to create a PDF in my universal application, this is creating a PDF fine for English, but when I create a PDF in Arabic it starts giving garbage characters instead of Arabic characters.
This looks like an encoding issue to me. Please let me know how do we solve such issues generally for creating PDF, even if you do not know about componentOne library. I might pick the clue.
EDIT:
Download Stripped down code:
http://1drv.ms/1ABAuqi
Code:
async void CreatePdfDocument()
{
try
{
var pdf = new C1PdfDocument(PaperKind.Letter);
pdf.Landscape = false;
// measure and show some text
var text = App.GetResource("DocumentHeading");
var font = new Font("Segoe UI Light", 36, PdfFontStyle.Bold);
var fmt = new StringFormat();
fmt.Alignment = HorizontalAlignment.Center;
// measure it
var sz = pdf.MeasureString(text, font, 72 * 3, fmt);
var rc = new Rect(0, 0, pdf.PageRectangle.Width, sz.Height);
rc = PdfUtils.Offset(rc, 0, 0);
// draw the text
pdf.DrawString(text, font, Colors.Orange, rc, fmt);
}
catch (Exception e)
{
}
}

cannot load image in isolated storage when creating IconicTile

I'm trying to create IconicTile using image saved on isolated storage.
At first, I saved image to isolated storage.
// bitmap is Stream of image source (e.g. from PhotoChooserTask)
var wbmp = new WriteableBitmap(bitmap);
var file = "Shared/ShellContent/IconicTile.png";
// when file exists, delete it
if (storage.FileExists(file))
{
storage.DeleteFile(file);
}
using (var isoFileStream = new IsolatedStorageFileStream(file, FileMode.Create, storage))
{
// use ToolStackPNGWriterExtensions
wbmp.WritePNG(isoFileStream);
}
And I have confirmed PNG file is successfully created using Isostorage Explorer Tools.
Then I try to create IconicTile.
var initialData = new IconicTileData
{
BackgroundColor = SelectedColor,
IconImage = new Uri("isostore:/Shared/ShellContent/IconicTile.png", UriKind.Absolute),
Title = tbTitle.Text,
WideContent1 = tbWideContent1.Text,
WideContent2 = tbWideContent2.Text,
WideContent3 = tbWideContent3.Text
};
var uri = string.Format("/SecondaryPage.xaml");
var TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(uri));
if (TileToFind == null)
ShellTile.Create(new Uri(uri, UriKind.Relative), initialData, true);
else
TileToFind.Update(initialData);
But image in the created tile are white.
(I'd like to attach image but my reputation is too low. Sorry.)
I tried not only PNG format but also JPG format, but neither doesn't work.
Is there anyway to create IconicTile using image on IsolatedStorage?
The iconic tile format expects a transparent background, based on your comment at the first line (PhotoChooserTask), I suspect you're using some type of image with no transparency.