I am using the SelectPDF library for my ASP.NET web application to convert a dynamically built HTML to PDF and then print it. The conversion simply looks like this:
HtmlToPdf converter = new HtmlToPdf();
converter.Options.PdfPageSize = PdfPageSize.A5;
converter.Options.PdfPageOrientation = PdfPageOrientation.Landscape;
PdfDocument doc = converter.ConvertHtmlString(FormattedLabelHTML);
doc.Save(Response, false, "Label_" + hfDispatchID.Value + ".pdf");
doc.Close();
The HTML itself is fine, as looking at the FormattedLabelHTML string in debug mode shows it's complete and looks at it should be (it's just HTML tables for each page, with page brakes between them).
But if the number of pages that should be printed is more than 12, then the rendered content stops at 12 pages, leaving the 12th page half-rendered, and the rest completely missing. If the page count is under 12, then they all render properly.
There are no errors thrown, everything executes properly. So does anyone have any tips as to why it can't print more than 12 pages?
Related
Tried to open a pdf result in blank pages. Retry with same pdf displayed all pages with content.
It happen only once & couldn't reproduce it.
My application work with 3 steps.
Open PDF
Add Barcode Image
Save PDF
Source pdf had 2 pages with text content, output pdf had only stamped pdf without content.
I believe something went wrong in following line because number of pages are correct but blank.
PdfDocument document = PdfReader.Open(filePath, PdfDocumentOpenMode.Modify);
I need find reason of failure but don't have any idea what went wrong at first time. I have already gone through following questions but they have different case.
https://stackoverflow.com/a/52453789/9102192
PDFSharp returning blank pages when adding password
Can anyone help me finding root cause for this incident or any guesses ?
I would try to do something like this:
using (PdfDocument pdfDoc = PdfReader.Open("source", PdfDocumentOpenMode.Modify)){
// Logic to insert image into pdf //
pdfDoc.Save("targetPath")
}
I want to convert an HTML form to a PDF form using HTML Renderer. I know how to convert an HTML page to PDF using HTML Renderer, but I'm not getting all the pages, it is displaying only first page.
When I open HTML in the browser it is displaying all the content and after transformation to PDF it is showing less content and it's up to only one page.
I have tried and searched for different solutions, but none of them are working for me. Please help me to display all the content in multiple pages.
I have used the following:
PdfDocument pdf2 = PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.Letter);
pdf2.Save(filename);
and tried this
PdfDocument pdf = PdfGenerator.GeneratePdf(htmlContent, PdfSharp.PageSize.A4);
I want to transform XML to PDF and HTML to PDF using either HTML Renderer or aspose libraries only.
To generate PDF from XML using Aspose.PDF API, you need to create XML based on XML Schema, which can be found in XML folder in Aspose.PDF installation directory or from this link. Now the XML file that follows the schema can be converted to PDF document with BindXML method, as in the code snippet below:
Document doc = new Document();
doc.BindXml(dataDir + "XML_DOM.xml");
doc.Save(dataDir + "XMLtoPDF_out.pdf");
About HTML to PDF conversion, you may use below code snippet to load a HTML file and save it as a PDF document.
HtmlLoadOptions options = new HtmlLoadOptions(dataDir);
Document pdfDocument = new Document(dataDir + "Test.html", options);
pdfDocument.Save(dataDir + "HTMLToPDF_out.pdf");
PS: I work with Aspose as Developer Evangelist.
I have problems with printed html pages with mshtml.dll. My pages contains links to bootstrap css. In browser (IE, FF, Chrome) all looks fine and prints also fine. When I trying to print page with MSHTML something goes wrong, and page looks like css does not work. I am loading html content from disk, and then print it:
var htmlContent = File.ReadAllText(filePath);
var htmlDocument = new HTMLDocument() as IHTMLDocument2;
htmlDocument.write(htmlContent);
htmlDocument.execCommand("Print", true, 0);
htmlDocument.styleSheets; // contains all linked css files
Does anyone experience such problem? Maybe there are other methods to print html page without browser?
I'm using Winnovative's Html to PDF converter to print my page to PDF.
// Get a PDF of the URL.
Document document = new Document();
//document.LicenseKey = PDFUtility.LicenseKey;
PdfPage page = document.Pages.AddNewPage(PdfPageSize.A4, new Margins(10, 10, 0, 0), PdfPageOrientation.Portrait);
HtmlToPdfElement pageToPrint = new HtmlToPdfElement(sURL);
page.AddElement(pageToPrint);
// Setup response
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename ={0}", sPage + ".pdf"));
document.Save(context.Response.OutputStream);
My header tags have a font face on them. This works fine locally and renders with the custom font. However on my dev and test servers it does not render the header tags at all. It does leave space where the header tags should be.
When we changed our headers to Arial the PDF renders with the headers in all environments.
We've checked permission on the font files (set permissions to full control for everyone). That didn't change anything.
Something to do with the font face is not working on our server and we can't figure out what.
You have to check if your font files are accessible in a browser from the server itself. Put your HTML code in a HTML file and open that file from the test server in a browser. If the HTML file is displayed well in browser it should be rendered well in PDF too.
You should also make sure that the IIS from the server has the ttf or woff (not sure what exactly you reference in #font-face) set in accepted MIME types, otherwise these files will not be served by web server.
I had a similar problem showing web fonts in my solution as well.
It turns out that woff2 fonts did not get rendered at all.
Once I switched to the woff file format, everything worked as expected.
From what I saw, there is no setting that I haven't enabled in the converter, so I guess woff2 is not supported.
Yes, you have to make sure the font files are enabled in your web server MIME types. Winnovative HTML to PDF converter works well with all types of we fonts. There is a complete example with C# and HTML code using #ont-face rules in Convert HTML with Web Fonts to PDF demo .
Right now I am using iTextSharp to create a PDF. We have a need to put a few text boxes on this PDF for the user to fill out. The PDF if being generated dynamically since it depends on user input as to what is shown, which can increase or decrease page count depending on what is selected. When we use iTextSharp, adobe sees the fields, but says "Currently there are no form fields in this PDF....". If I hit cancel on this dialog, I see the fields are on the PDF, but something is not right. I loaded up the PDF in a trial of Aspose.PDF and it can't see the fields either. I am adding the fields in the code sample below.
var txtName1 = writer.AcroForm.AddSingleLineTextField("Name1","",_avenirDefault,Font.NORMAL, 72, writer.GetVerticalPosition(false) - 12, 275,writer.GetVerticalPosition(false) + 5);
txtName1.SetFieldFlags(PdfFormField.FF_REQUIRED);
I have also tried,
var txtName1 = new TextField(writer,
new Rectangle(72, writer.GetVerticalPosition(false) - 12, 275,
writer.GetVerticalPosition(false) + 5), "Name1") { Options = BaseField.REQUIRED };
writer.AddAnnotation(txtName1 );
Neither of these prevented the error from showing in Adobe or finding the fields in the Aspose library. Any idea why these fields are shown but not detected as Form Fields for adobe?