I'm writing a web application to generate labels. The label printer that I'm targeting utilizes 12mm tape and the customer specified that they want to limit the labels to 3.25". I know that with iTextSharp I can specify the size of the document I want to create, however it appears that I have to specify both a width and height.
Document document = new Document(new iTextSharp.text.Rectangle(234f, 33.84f));
234 is 3.25" converted to points, and 33.84 is 12mm converted to points, so this sets the document to the maximum size allowed. Is there any way to set just the height and let the document auto-expand to the amount of content? With that, is there a way to determine if the expanded width of the document exceeds to maximum allowed by the customer? Thanks in advance for any help you can offer.
No, that is not possible in iText. It's not a particularly good idea anywhere else either. As Redman said, PDF is a print-based format. It's not HTML.
There are some tricks you can do to get around this to some extent:
Create your page with the maximum legal height. 200" * 72dpi = 14400 points.
Add a "generic tag" to your paragraphs.
create a tag event handler that tracks where the bottom of your last paragraph was drawn.
Save the PDF.
Open it again with a PDFStamper
Set the bottom of the page to match the location of that last paragraph. Remember that the bottom left starts off at 0,0, and the top right will be
Save the final PDF
This trick will only work if your total output is less that 200" high. If you go over that, you'll still get a second page, and your "where the bottom is" code had better be prepared for it.
PS: I don't see what's wrong with having a number of 12mm x 3.25" pages... won't that perfectly fit the labels they want printed?
As far as I know, because PDF is a print format, the document width and height must be set.
This is why reporting tools generally default page sizes to the default printer page size.
You best bet to try and calculate the size of the content and create the PDF accordingly.
Depending on the volume and nature of the workflow, you could provide a preview for the customer to check before printing.
Related
Is there any way I can convert the contents of a rich text box to a bitmap in WPF?
I tried the solution mentioned in the following post: Saving RichTextBox FlowDocument to image
But my dilemma is I am unable to figure out how to calculate the required size of the bitmap before hand that would cover the entire flow document.
Please help. Thanks in advance.
FlowDocuments don't have a rigid size, that's the point:
Flow Document Overview:
Flow documents are designed to optimize viewing and readability. Rather than being set to one predefined layout, flow documents dynamically adjust and reflow their content based on run-time variables such as window size, device resolution, and optional user preferences.
You need to set either a height or a width restraint, or both. If you set only one, width for example, the FlowDocument will update to stretch vertically until all the content has been displayed. After you set the constraint(s), you can check the actual size of the document and that will give you the required size of your image.
I have a RadRichTextBox that have a RadDocument loaded. This is then used to print mentioned document using richTextBox.Print().
The main problem is that the resolution of the printed page is tied to the zoom of the document in the viewer (RadRichTextBox), i.e. if I have the document zoomed way out (small pages on screen) the resolution on the printed paper is terrible. On the other hand, if I zoom in, the resolution becomes really good.
Obviously, I want to always print at the best possible resolution, is there a way to achieve this?
In the end I went with a work around that works by saving the scaling, setting it to a high number, then restoring it after printing the document.
Size sf = richTextBox.ScaleFactor;
richTextBox.ScaleFactor = new Size(10,10);
richTextBox.Print(/*... settings ...*/);
richTextBox.ScaleFactor = sf;
This looks weird, as the documents zooms in while the document is printing, but the printed document have a proper resolution.
I have working iTextsharp code for printing labels. Now the problem is, I have a requirement to print the labels in Continuous paper which i am not able to select in iTextsharp configuration (iTextSharp.text.PageSize.A4). Please advice how can i select the page size according to my current scenario.
Thanks
Your problem is related to PDF as a document format. In PDF, the content is distributed over different pages. You can define the size of such a page yourself. You mention iTextSharp.text.PageSize.A4, but you can define the page size as a Rectangle object yourself. See iTextsharp landscape document
If you want a long, narrow page, you could define the page size like this:
Document Doc = new Document(new Rectangle(595f, 14400f));
There are some implementation limits though. The maximum height or width of a page is 14,400 user units. See the blog post Help, I only see blank pages in my PDF!
However, I am pretty sure that you don't want to create a long narrow page. If you want to print labels on "continuous paper", you want to create a PDF document in which every page has the size of exactly one label. Your PDF will have as many pages as there are labels.
Suppose that the size of one label is 5 by 2 inch (width: 12.7cm; height: 5.08cm), then you should create a document like this:
Document Doc = new Document(new Rectangle(360, 144));
And you should make sure that all the content of a label fits on a single page. Your label printer should know that each page in the PDF should be printed on a separate label.
(Thank you #amedeeVanGasse for correcting my initial answer.)
My C# application generates a Crystal Report that contains many images with varying size, orientation, and aspect ratio. To make them appear correctly in the report, I use a white Square Canvas and center the image inside. This makes lot of wasted space:
Is it possible to resize each picture in the report to the appropriate size from C#? I have found a way to resize the images here, but I don't know if I can perform these steps from c#, especially when it comes to "Calculating and setting Width and Height to the proper number of twips."
I know the size of my image in C#, but can it be passed to and implemented in the report? Images are inside an xml file in base64 format.
Designer View:
Okay, i don't have a working solution but an idea that might help you ( and i hope it will )
I searched a programmatically way to do what you want, and i don't find anything. Unless the fact that you can manipulate your FieldObject with C#, it can't be used in your report.
So, i'll try to guide you with some screenshoots, but i am French and my screens will be in french, so sorry for the bad translations !
You can write a formula to change the display of your BinaryImage in your subreport. I just found a way to change the width of you data, not the height.
So, assuming my image is stored in "ARTICLE" table, and the name of the column is "ART_IMAGE". I put my data in the detail section and create a new formula, ignore the created formula, you need to access to the "formatting formulas" :
Here in my screen it is called "Formules de mise en forme". In the left you can see my simple report and on the right the formula panel, i clicked on my details section and i can see my only field.
Now right click on this field and create a new formatting formula :
A pop up is displayed, you'll need to choose something like that in english "
Adjusting the width" :
Now, you have to return the new width of your current image, a way to know what is the current width is to store it in a field in your database.
So if in your database you have a field for your image, and a field like image_width. In my example i have a field name ART_DIMENSION and i store the width of the image.
The tricky part is that this formula accept twips not inch or cm. For you information 1 inch = 1440 twips.
So in my example here is the formula :
So for each image to display, the width of my image will be the width stored in "ART_DIMENSIONS" ( with the good convert : inch to twips )
In your report design, with a formula like this which set the width dynamically for your image, you can set the section and your image object with a very small width. In this case your images will be displayed one by another because the section width will be edited for each image to display.
I tried to be very clear, hope it will help you, ask me any questions if you don't understand something.
Regards,
We print pdf books generated through a html to pdf application.
There is a header and footer on each page, and we place content exactly using production, and translation restrictions (and layout variations) for different languages to ensure that the fixed content for each page fits.
So for example, although our content is dynamic, a paragraph is expected to take approximatley the same amount of space for the same place in the book. We sometimes change style and layout attributes for translations but the same rules about like sizes apply.
We have a header and footer on each page, and the entire book is rendered as one long html page using css line breaking to force each header onto to a new page. So to reflect we control fixed content height per page server side.
This works well, and we are very happy with the advantages that HTML affords us in presentation (designers rather than programmers can design pages etc), we are also heavily invested in this tech, we are in too deep to change direction now, so we are not able to change our technology, we are using html 2 pdf and we need to make this work as best as possible. That is not to say we could not mix tech. but...
The problem is thus, we now have some variable sized content, that we have no former control over, to us it is text, so we have control over its formatting, but not it's quantity. We also have headings which are different sizes.
We need a way to calculate page breaks, leaving as little white space as possible, and I would love to know how anyone else is dealing with this. I know this will not be an exact science, but I still need the best approach possible.
We have total control over the rendering/layout engine it is always ie8 compatible, so different browsers need not be considered.
These are my thoughts, would love to hear yours:
This is our current method, assign a number of lines per page (variable by font-size and font to allow for different locales) each block of content will be calculated into n lines cost and this figure used to calculate pages breaks.
Pro simple
Con inaccurate, none of our fonts are monospaced, needs configuring for every locale.
Render each consecutive page of free flow content into a webpage in a div of the exact page width (fixed div) let it flow to whatever vertical height it requires, using a html 2 bmp solution capture an image and use the height of the rendered image (edge detected and cropped if required) to calculate the required number of pages.
Pro Could be accurate, not too expensive if free flow content is kept contiguous.
Con Incomplete solution, once I know the required number of pages, how do I know where to break the html? Measuring each page using this method and edge detecting would be very expensive.
On a font by font basis, knowing in advance the font sizes, padding and margins of text and headings, calculate width and line breaks and height, chracter by character using width data extracted from the font file.
Pro Once all the data had been extracted, and margins had been added for differences in HTML rendering this could likely be fairly accurate.
Con Highly intricate and sensitive to style sheet changes.
Could we use a WebBrowserControl to somehow measure the content?
Love to hear your thoughts and suggestions.
EDIT....
Our pdf converter is Winnovative, which runs within a .net Windows service, our html feed however is generated in PHP.
Kindly refer the manual
http://www.winnovative-software.com/manual%5CHTML%20to%20PDF%20Converter%20for%20.NET%20-%20Developer%27s%20Manual.htm
point 5.1.
Hope this solution helps you.
Note: the internal links are not working, so kindly manually navigate to the desired point.
This question is old, but I am doing the same basic thing as you. What I've found is that line number counting is still important, but you can use the css style line height to standardize the size of each line. (height for tr's if html is table based). This should allow you to have a constant number of lines per page.
Did you come up with a solution that worked for you?