i'm trying to manipulate pdf and i tried some of opensource libraries (e.g pdfSharp, pdfjet) and i cannot achive what i must do. Because pdfsharp add it with a new page to pdf, or pdfjet put an advert into pdf. So, i cannot use those libraries.
What i must achive is:
i must put a string at the end of the last page of pdf. If last page have enough space to put the string, then there is no need to add a new page, otherwise, string can be splitted or add a new page to pdf.
Here is a code sample i tried;
HtmlToPdf renderer = new IronPdf.HtmlToPdf();
IronPdf.PdfDocument doc = IronPdf.PdfDocument.FromFile(existingPdfPath);
doc.AppendPdf(renderer.RenderHtmlAsPdf(stringAddToPdf));
doc.SaveAs(newPdfPath);
Thanks for helps,
From what I can understand, AppendPdf is actually designed to always insert a new page..
https://ironpdf.com/c%23-pdf-documentation/html/M_IronPdf_PdfDocument_AppendPdf.htm
My suggestion would be to add the string as a footer as this should be possible either with AddHeaders/AddFooters/AddHTMLHeaders/AddHTMLFooters
https://ironpdf.com/c%23-pdf-documentation/html/Methods_T_IronPdf_PdfDocument.htm
Related
(More specific Giorgio Bozio)
I have been using Rotativa for the last year to print simple html to pdf and its been working fantastic. Very happy with product, but now recently i have been trying to do something a little more advance and i keep having the same issue.
Normally i would send Rotativa a simple invoice view (Predefined HTML) with model data populated via Razor and this worked well, but now i am trying to implement template's for my invoices. Customers can create their own template layouts with a custom 3rd party form designer and then upload its template file into my site. I take this file and parse it and generate the elements of the invoice with stringbuilder and div tags. I then send the generated HTML to the view that uses a #HTML.Raw() to populate the invoice html. Rotativa then takes this View and generates a pdf, but when it generates the pdf its quality of the text is horrible and blurry. Thus it generates the template correctly, but does some sort of shrinking or something to make the text not look crisp.
I have tried everything, from playing with custom switches to playing with the dimensions of the html.
When i copy the generated html to a view and just generate the pdf plainly then it prints fine, but as soon as i push the html to the view with HTML.Raw i seem to land up with fussy text.
Giorgio Bozio, does Rotativa have a issue with Html.Raw? or can you perhaps open a dialog with me to try and resolve this issue? Really hope you can help me...or someone can help me. Desperate and dont really want to change Rotativa for something else.
Please help.
Resolved Text printing issue by removing background-color definitions on Div containers.
Resolved extra blank page printing issue by reducing PageHeight on Rotativa Customswitches
:-)
I have code that takes a bunch of PDFs and combines them into one file...
PdfWriter writer = PdfWriter.getInstance(document, baos)
....
PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(writer, null, af.fileName, af.documentData.data)
fs.addCollectionItem(item)
writer.addFileAttachment(fs)
This works great and I see all of the pages as I would expect. Now I am looking to split it up and copy to multiple sub files based on size. However, when I consume the generated byte[] iText only seems to see the first page...
PdfCopy copy = null
PdfReader reader = new PdfReader(before) // Add the byte array here
int pages = reader.getNumberOfPages() //It is only 1 I would expect more pages.
It seems to only be recognizing the cover page which was added before the other documents. Is there a way I can get the count of ALL pages? If I take before and just send it as an attachment it shows up with all 1xx pages.
You are combining the files by attaching them to a new PDF which only has a cover page, and making this file a Portfolio as Adobe calls it:
PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(writer, null, af.fileName, af.documentData.data);
fs.addCollectionItem(item);
writer.addFileAttachment(fs);
Thus, your code is not one of the typical merge functions (using PdfCopy or PdfWriter with getImportedPage; correct ones use PdfCopy, fishy ones use PdfWriter) which generate a single PDF containing all source pages as genuine document pages. Instead your code creates a single page document with other PDFs as attachments and some extra information making PDF viewers display the attached PDFs inline.
If you want to access the pages of these attached PDFs, you have to extract them again and open them in separate PdfReader instances.
You can find more information on extracting PDF attachments in this answer.
Im using play framework and rendering PDF usin rednerPDF() method.
I would like to display some part of content always be in new page.
For Example I have two tables, One table should be in first page and another table should in next page instead of continue from first page. The first table contents are dynamic and we can't sure the height of the table.
Is it possible?
Is it possible?Yes.
You said one table(first one) should be in first page,and again you said its content is dynamic.Now my question is it span over pages and in the next page you want to write second table?This is a generic scenario and what you mentioned is specific one.
You can start trying using two properties of PdfPTable setSplitLate() and setSplitRows()(just google it out for details read Itext In Action).Just keep Two table as two Rows of outer table.set those two property for inner as well as outer in some way as you want(i.e generic case/Specific case).
Another alternative way is use writeSelectedRows() method over PdfContentByte(I don't konw which Object you gonna use for manipulating pdf but you can get it from PdfWriter,*PdfStamper* by using getDirectContent/*UnderContent*/OverContent) after generating table.To use this method you have to set total width of the table so the height can be calculated by method getTotalHeight of PdfPTable.If You use this height properly you absolutely know where your table ends.But all these specific part you have to read & understand first.
With yahp you can use a special html tag to force a page break
<yahp:pb />
we can achieve this by page-break-after:always
Please refer
Alternate to PDF for dynamically generated document with page breaks
I am a newbie coder. I have learned a lot in the few weeks. Now I am making my blog site.
What I want is , show the limited part of 6 or 8 articles in the content div and make a read more link to show the article.
Can you tell me a way to do it?
Load the string helper and use the word_limiter, character_limiter (google for docs)
Or, contain a paragraph called "Summary" (varchar(255)) different to your main "Content" field (TEXT).
Initially load string helper and do as follows
word_limiter("data",limit);
You can check it here
I'm having trouble figuring out how to add an external image (referenced by a URL) to a PDF using iText. Is this kind of thing possible?
The PDF spec in 7.1.5 says you should be able to reference a PDF via a URL by using a URL specification. This is what I've got so far:
PdfFileSpecification pdfSpec =
PdfFileSpecification.url(writer, "http://www.someurl.com/test.jpg");
StringBufferInputStream sbis = new StringBufferInputStream("");
PdfStream dict = new PdfStream(sbis, writer);
dict.put(PdfName.FILTER, PdfName.DCTDECODE)
dict.put(PdfName.TYPE, PdfName.XOBJECT);
dict.put(PdfName.SUBTYPE, PdfName.IMAGE);
dict.put(PdfName.WIDTH, new PdfNumber(100));
dict.put(PdfName.HEIGHT, new PdfNumber(100));
dict.put(PdfName.BITSPERCOMPONENT, new PdfNumber(8));
dict.put(PdfName.LENGTH, new PdfNumber(0));
dict.put(PdfName.F, pdfSpec);
PdfIndirectObject img = writer.addToBody(dict);
I know I still need to make sure the color space is added and stuff, but my main concern right now is actually getting this image into the body of the document. I can't figure out how to do this... it seems I can't get a reference to a PdfPage or the resources dictionary or anything. Is this possible using iText?
As a side note, this exercise is useless if I'm going to be presented with a security warning when the view tries to go load the image. Does anyone know if that is the case?
External content is described in the PDF spec, but almost no PDF processor does actually support them. By now Acrobat 9 has support for it, but I would be very cautious with that feature: Your clients or users may not be able to see the referenced content.