HTML to PDF result in landscape - pdfsharp

I am using PDFSharp to generate PDF from html source.
PdfGenerator.GeneratePdf(html, PageSize.A4);
Generate to pdf works well, but I dont know how I can change page orientation to landscape?

the following code could be usefull for you:
var config = new PdfGenerateConfig();
config.PageOrientation= PageOrientation.Landscape;
config.PageSize = PageSize.A4;
PdfDocument pdf = PdfGenerator.GeneratePdf(documentHtmlContent, config);
pdf.Save(FILE_OUT_PATH);
Process.Start(FILE_OUT_PATH);

Related

How to convert bytes into image

I am generating a report using Telerik and displaying it as PDF in UI. Can anyone tell me, how to display that report as an image in UI using jquery and asp.net mvc3
You can try somethig like this:-
public Image byteArrayToImage(byte[] byteArray1)
{
MemoryStream m1= new MemoryStream(byteArray1);
Image i1= Image.FromStream(m1);
return i1;
}
Check out this link:- ByteToImage

Object Tags and Asp

I have a master page that gets all its images from a table on a database, and I am trying to incorporate flash, for banners, but I can't quite seem to figure it out.
Right now there is a:
<asp:image id="headerimg" runat="server">
and that generates the appropriate img tag needed to show an image in html. Now I would like to know if there is any way where I can generate an object tag if a .swf file is present and populate the tag with width height and data and also not show the img tag.
Update__
I now have made a usercontrol that will create the object tag, but can someone please tell me if it is looking like I am doing it right..
IDataReader dr = DB.GetRS("SELECT HeaderGraphic,HeaderAlign, fWidth, fHeight, Flash FROM Store where CustomerID='" + Session["Customer"].ToString() + "'");
if(dr["Flash"] == 1)
{
HtmlGenericControl obj = new HtmlGenericControl("object");
obj.Attributes["width"] = dr["fWidth"];
obj.Attributes["height"] = dr["fHeight"];
obj.Attributes["data"] = dr["HeaderGraphic"];
this.Controls.Add(obj);
}
else
{
HtmlGenericControl image = new HtmlGenericControl("img");
img.Attributes["src"] = dr["HeaderGraphic"];
img.Attributes["align"] = dr["HeaderAlign"];
this.Controls.Add(image);
}
is this continuing to look right? and is there anything I am missing?
Thanks.
Why not create a user control that generates the required <OBJECT /> html to display the swf file and then you can dynamically load these if there are swf file present?
is this looking right? and how do I get this into the html?
Yes it looks right. You can add it into your page this way:
this.Controls.Add(obj);
Hope it helps!
Hanlet
EDIT: I could recommend you to look into Generic Handlers and see if you can somehow use it. Good luck!

flex air show pdf preview

I am using urlloader to load a tiff file from the server.
Then i get it as ByteArray and show the image in a popup window.
var bytes:ByteArray = urlloader.data as ByteArray;
i use the TIFFbaselineDecoder to decode the bytes and open a popup to show the bitmap.
Works nicely.
Now, i want to do the same thing for a pdf file.
How can i show the pdf file in a window from the bytearray.
Please let me know.
Thanks
Vish
First, you can check if the user's machine is suitable for PDF display
if(HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK){
trace("PDF content can be displayed");
}
else {
trace("PDF cannot be displayed. Error code:", HTMLLoader.pdfCapability);
}
If so, then
var request:URLRequest = new URLRequest("http://www.example.com/test.pdf");
pdf = new HTMLLoader();
pdf.height = 800;
pdf.width = 600;
pdf.load(request);
container.addChild(pdf);
Mind you, this works too :
<mx:HTML width="100%" height="100%" location="understanding_the_flex_3_lifecycle_v1.0.pdf"/>

Can I print an HTMLLoader (pdf) in Adobe Air?

I'm using AlivePDF to create a PDF file, then save it to the desktop. I can then use an HTMLLoader to display my lovely PDF file.
Now, the print button in Adobe Reader works fine. However, there will be young children using the app, so I'd like to have a big "Print" button right above it.
I figured I could just start up a print job and feed it my HTMLLoader. This won't work because the HTML loader rasterizes the content.
Any suggestions?
One answer I have found in order to solve this problem is called Cross-scripting PDF content. The idea is that a PDF can have embedded JavaScript, which can be called from the JavaScript within the HTML page "housing" said PDF (object tag only, no embed).
This site was of particular help. I had to simplify the JavaScript from that page down quite a bit. I kept getting syntax errors.
I also need my program to generate the PDF and the HTML content. I cannot ship a single PDF with embedded JS and an HTML file pointing to it. They need to be dynamically generated by the user. Here is a basic rundown:
private function printText(text:String):void
{
var p:PDF=new PDF(Orientation.PORTRAIT, Unit.MM, Size.LETTER);
p.addPage();
p.addText(text, 100, 100);
p.addJavaScript(this.getJavascript());
var f:FileStream=new FileStream();
var html:File=File.desktopDirectory.resolvePath("exported.html");
f.open(html, FileMode.WRITE);
f.writeUTF(this.getHtml());
f.close();
var file:File=File.desktopDirectory.resolvePath("exported.pdf");
f.open(file, FileMode.WRITE);
var bytes:ByteArray=p.save(Method.LOCAL);
f.writeBytes(bytes);
f.close();
Now that we have our two files, HTML and PDF, we can view the PDF, and create a giant purple print button for our younger / sight-impared users.
if (HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK)
{
var win:PrintTitleWindow; //the window w/giant button
var htmlLoader:HTMLLoader=new HTMLLoader();
var url:URLRequest=new URLRequest(html.url);
htmlLoader.width=880;
htmlLoader.height=(appHeight - 150); //i figure out the height elsewhere
htmlLoader.load(url);
var holder:UIComponent=new UIComponent();
holder.addChild(htmlLoader);
win=PrintTitleWindow(PopUpManager.createPopUp(mainWindow, PrintTitleWindow, true));
win.width=900;
win.height=(appHeight - 50);
win.addChild(holder);
win.addContent(htmlLoader);
PopUpManager.centerPopUp(win);
}
}
Here is the JS and HTML I used. I'm adding these in here for laughs. I'm sure there is a better way to do this, but I'm tired and it is late.
private function getJavascript():String
{
return 'function myOnMessage(aMessage) { print({ bUI: true, bSilent: false, bShrinkToFit: true }); } function myOnDisclose(cURL,cDocumentURL) { return true; } function myOnError(error, aMessage) { app.alert(error); } var msgHandlerObject = new Object(); msgHandlerObject.onMessage = myOnMessage; msgHandlerObject.onError = myOnError; msgHandlerObject.onDisclose = myOnDisclose; this.hostContainer.messageHandler = msgHandlerObject;';
}
private function getHtml():String
{
return '<html><head><script>function callPdfFunctionFromJavascript(arg) { pdfObject = document.getElementById("PDFObj");pdfObject.postMessage([arg]);}</script></head><body><object id="PDFObj" data="exported.pdf" type="application/pdf" width="100%" height="100%"></object></body></html>';
}
The PrintTitleWindow is a simple title window with the print button on it. The code to print is simple.
myHtmlLoader.window.callPdfFunctionFromJavascript('Print');
Eh Voila! I have a gigantor-print-button like so:
(source: cetola.net)
Hitting that big purple print button is the same as hitting the print icon in the PDF toolbar. The difference for me is that my users, who could be elementary or middle-school kids, won't have to look around for the stupid button.
So, it's a long way around the block. Still, if you need to print and can't rely on that adobe toolbar button, here's your answer :) .

Flex - get bitmap

Is it possible to get the bitmap data from a component using ActionScript?
I dynamically load an image.
onComplete I create a Flex Image component and add the loaded image to the source
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void
{
var image:Image = new Image();
image.x = 0;
image.y = 0;
image.source = e.currentTarget.content;
canvas.addChild(image); // canvas is already added as an MXML element.
}
Later I want to create a new Image component and get the bitmapData from the first Image.
I have tried this
canvas.getChildAt(0)
Which seems to give me the Image, but I can not figure out how to get the bitmap data.
canvas.getChildAt(0).bitmapData;
gives me a compile error "... undefined property"
Does anyone know how ot get the bitmap data so I can use it in my new Image component?
Thanks in advance,
Ran
Check out ImageSnapshot.captureBitmapData()
http://livedocs.adobe.com/flex/3/langref/mx/graphics/ImageSnapshot.html
Cliff's answer will give you a screenshot of the Image; to get the underlying BitmapData for the image without doing a screenshot, you can try
Bitmap(image.content).bitmapData
This should avoid any filters as well.
This should do it.
var bd:BitmapData = new BitmapData(myComponent.width, myComponent.height, true, 0);
bd.draw(myComponent);

Resources