|
Hello
I have a requirement to write pdfdocument using html contents in an ASP.NET MVC Project. I am writing the HTML code inside a string variable and then I am giving that string for rendering it as pdf bytes using the below code. The returned bytes I am saving it as pdf on the server. However I am getting too many formatting issues in the pdf generated.
When I saved the html contents which I passed to the string, formattings are good but somehow when I am trying to create a pdf out of those contents I am getting issues. Any help will be greatly appreciated.
public byte[] Render(string htmlText)
{
byte[] renderedBuffer;
using (var outputMemoryStream = new MemoryStream())
{
using (var pdfDocument = new Document())
{
PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDocument, outputMemoryStream);
pdfWriter.CloseStream = false;
//pdfWriter.PageEvent = new PrintHeaderFooter { Title = pageTitle };
pdfDocument.Open();
using (var htmlViewReader = new StringReader(htmlText))
{
using (var htmlWorker = new HTMLWorker(pdfDocument))
{
htmlWorker.Parse(htmlViewReader);
}
}
}
renderedBuffer = new byte[outputMemoryStream.Position];
outputMemoryStream.Position = 0;
outputMemoryStream.Read(renderedBuffer, 0, renderedBuffer.Length);
}
return renderedBuffer;
}
|
|
|
|
|
krishnapnv wrote: when I am trying to create a pdf out of those contents I am getting issues. And do you plan on letting us into the secret of what those issues are?
Use the best guess
|
|
|
|
|
I am getting issues with formatting. The pdf is not getting formatted properly. A close observation revealted that, itextsharp is not able to include external css files, and so a lot many formatting problems. So I am stuck here and waiting for some response
Thanks
Krishna
|
|
|
|
|
on btn click event how to save windows form data in pdf format
|
|
|
|
|
One way is to use something like iTextSharp to create your PDF.
|
|
|
|
|
|
I have a tabbed form and I'm trying to switch it over to tiled. It looks like this:
TabPage newPage = new TabPage(string.Format("{0}:{1}", cb1.cbInfos[i].usbHandle, cb1.cbInfos[i].boxID));
InitializeControls(controls[i]);
tabCtrlMain.Size = (controls[i].Size);
tabCtrlMain.Width += 20;
tabCtrlMain.Height += 100;
this.Width = tabCtrlMain.Width + 20;
this.Height = tabCtrlMain.Height + 50;
newPage.Controls.Add(controls[i]);
tabCtrlMain.TabPages.Add(newPage);
I saw this example, http://sharpertutorials.com/multiple-document-interface-mdi/[^], but this looks different because they are changing where it refers to Run new Form to Run new Mdi
example:
Application.Run(new Form1());
to
Application.Run(new MDIParent1());
but I'm not seeing where I have that sort of thing to switch over. Does anyone have any ideas how to switch over to tiled from tabbed? I'm fine with the contents of my controls[i] containing the correct information. The tabbed forms look fine. We decided to change the look because we think it will work better with this application. Thanks!
|
|
|
|
|
There's nothing special here. It's really just:
Application.Run(new className);
Instead of calling their startup form the default name of Form1, they changed the name to MDIParent1. Whether of a not a form supports MDI is just a property setting on the form. Just look in the Properties box of your form for "IsMdiContainer".
By the way, everyone is moving AWAY from MDI, not towards it.
After that, I guess you'll have a bunch of code to rewrite as you apparently won't being TabControl anymore. The only person who can tell you what you have to do is yourself since you're the one who designed the app in its current form.
|
|
|
|
|
Cool. That helped. I'm doing this to add it to my existing form and add the existing control that I was previously showing in the tab:
Form newForm = new Form();
InitializeControls(controls[i]);
newForm.Size = (controls[i].Size);
newForm.Width += 20;
newForm.Height += 100;
this.Width = newForm.Width + 20;
this.Height = newForm.Height + 50;
newForm.Controls.Add(controls[i]);
newForm.ShowDialog();
But it's filling up my entire area. Do you know how to scale the control's contents down to 1/4 the size? I think once I do that, it won't be tough to figure out how to position it (tiled) in the right location in my form with the other 4 controls I'm adding. It didn't let me say newForm.size = controls[i].size/4. (operator / can't be applied to system.drawing.size and int)
|
|
|
|
|
Loko at what type the Size property takes, it's an instance of Size. Look at the properties of Size, Height and Width. Sooooo, you just make a new instance of a Size with the new values:
using System.Drawing;
.
.
.
Size newSize = new Size(controls[i].Size.Width / 4, controls[i].Size.Height / 4);
controls[i].Size = newSize;
|
|
|
|
|
Hi,
I want to know how can I force beep using C# and:
[DllImport("kernel32.dll")]
private static extern int Beep(int dwFreq, int dwDuration);
even if Microsoft Windows volume is switched to mute?
Technology News @ www.JassimRahma.com
|
|
|
|
|
Jassim Rahma wrote: even if Microsoft Windows volume is switched to mute? That is the user's choice. I would be very annoyed if some application started beeping after I had set my PC to silent.
Use the best guess
|
|
|
|
|
The only way you can override the sound setting is to change the volume yourself, do the beep, then put the volume back where you found it. There is no little magic "override" method you can call.
The big problem with the is that you're changing a setting the user has set for a reason. THe other one is that if you turn the volume up to some arbitrary level, you have no idea how loud the sound really is. It still might not be audible or you might blast the user right out of their chair!
|
|
|
|
|
Why not use Console.Beep ?
Along with what the others say, the user may have the speakers physically turned down or off.
Or headphones could be plugged in but the user not wearing them.
There is also the possibility that the user is remoted into a system halfway 'round the world.
Perhaps you could allow the user to set a configuration setting to specify the volume to use.
For one application I wrote for a former employer I allowed the user to specify what sound to make (if any) as an alert.
|
|
|
|
|
Jassim Rahma wrote: even if Microsoft Windows volume is switched to mute?
Make sure you weld the PC-case shut. I'd rip that speaker out before you have the correct P/Invoke.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
if Microsoft Windows volume is switched to mute?
first you can change volume to 100% for playing sound and then change it back to 0%.
-Amir Mohammad Nasrollahi
/* LIFE RUNS ON CODE */
|
|
|
|
|
Hi,
I have problem with adding asp.net usercontrol in Usercontrol.
The 1st user control is DataList where the Companies are listed.
Now i need another usercontrol inside this one where i will list the products from each Company.
hope some one will explain how to combine this 2 controls or tell me some easy way to do this.
thanks
|
|
|
|
|
You should not post your questions in multiple places. ASP.NET UserControl In UserControl[^]
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Hi,
I am creating a setup project for my solution in C#, and I created a merge module that include all obfuscated assembly files (.dll files, and the .exe file), then add it to the setup project
Before building the setup project, I replace assembly files (in the Bin/Debug) by obfuscated files. After building the project, .dll files still are obfuscated, however the .exe file isn't obfuscated.
Are there anyone know how to fix that ?
Thank you very much !
|
|
|
|
|
I suspect, from this question, that you are manually obfuscating the file. When your setup is built, though, it rebuilds the executable, so that the file is no longer obfuscated - (you'll see the same behaviour if you manually apply a certificate to your code). The trick is to run the obfuscation process as a PostBuild process - which means that the setup will get the obfuscated version.
|
|
|
|
|
Thanks Pete very much,
Could you please tell me more how to use PostBuild process ?
I'm using the Crypto Obfuscator software to obfuscate assembly files.
And I can see the properties of Setup project include the PostBuildEvent but I don't know how to use it (I am using Visual Studio 2010)
Thanks and regards,
Tai
|
|
|
|
|
|
Hi Pete, thank you
Could you tell me more detail about creating obfuscated setup project ?
My solution includes some project:
1. Start up project (create application file)
2. Library projects (create dll files)
3. Merge project (include obfuscated assembly files)
4. Setup project
Thanks and regards,
|
|
|
|
|
Hi, You can drag and drop the project file to Eazfuscator.Net and it will handle the Obfuscation of your binaries every time you compile with release, if you are using different Obfuscator check how to obfuscate the project file, I believe rebuilding your solution is recompiling the .exe and overwrite your Obfuscated .exe then the setup project will include the new non-Obfuscated file.
|
|
|
|
|
Thanks Samer,
I am trying to use Crypto Obfuscator and Dotfuscator. I only rebuild setup project (not the solution) but it make the .exe recompiling. I don't know why ?
|
|
|
|