Useful Form Printing - vb.net

im searching the best way for Printing a whole form / Several Datagridviews and some Specific controll contents in my WindowsForm application.
I know the internet is full with bad and good examples.
Its hard to separate the Good examples from the Bad examples.
So what can you reccomend me?
Whats your way to do this? Wich Examples in the Web are useful?
Thanks in advance

Try this code. This will print all the contents of the current form.
using (Bitmap bmp = new Bitmap(this.Width, this.Height))
{
this.DrawToBitmap(bmp, this.ClientRectangle);
using (PrintDocument p = new PrintDocument())
{
p.PrintPage += (o, pe) =>
{
pe.Graphics.DrawImage(bmp, this.ClientRectangle);
};
p.Print();
}
}
Sorry I didn't tested it.

you could create a snapshot from the form you want to print and then print the image.
For creating snapshots you could have a look here

Related

PDFBox: Fill out a PDF with adding repeatively a one-page template containing a form

Following SO question Java pdfBox: Fill out pdf form, append it to pddocument, and repeat I had trouble appending a cloned page to a new PDF.
Code from this page seemed really interesting, but didn't work for me.
Actually, the answer doesn't work because this is the same PDField you always modify and add to the list. So the next time you call 'getField' with initial name, it won't find it and you get an NPE. I tried with the same pdfbox version used (1.8.12) in the nice github project, but can't understand how he gets this working.
I had the same issue today trying to append a form on pages with different values in it. I was wondering if the solution was not to duplicate field, but can't succeed to do it properly. I always end with a PDF containing same values for each form.
(I provided a link to the template document for Mkl, but now I removed it because it doesn't belong to me)
Edit: Following Mkl's advices, I figured it out what I was missing, but performances are really bad with duplicating every pages. File size isn't satisfying. Maybe there's a way to optimize this, reusing similar parts in the PDF.
Finally I got it working without reloading the template each time. So the resulting file is as I wanted: not too big (4Mb for 164 pages).
I think I did 2 mistakes before: one on page creation, and probably one on field duplication.
So here is the working code, if someone happens to be stuck on the same problem.
Form creation:
PDAcroForm finalForm = new PDAcroForm(finalDoc, new COSDictionary());
finalForm.setDefaultResources(originForm.getDefaultResources())
Page creation:
PDPage clonedPage = templateDocument.getPage(0);
COSDictionary clonedDict = new COSDictionary(clonedPage.getCOSObject());
clonedDict.removeItem(COSName.ANNOTS);
clonedPage = new PDPage(clonedDict);
finalDoc.addPage(clonedPage);
Field duplication: (rename field to become unique and set value)
PDTextField field = (PDTextField) originForm.getField(fieldName);
PDPage page = finalDoc.getPages().get(nPage);
PDTextField clonedField = new PDTextField(finalForm);
List<PDAnnotationWidget> widgetList = new ArrayList<>();
for (PDAnnotationWidget paw : field.getWidgets()) {
PDAnnotationWidget newWidget = new PDAnnotationWidget();
newWidget.getCOSObject().setString(COSName.DA, paw.getCOSObject().getString(COSName.DA));
newWidget.setRectangle(paw.getRectangle());
widgetList.add(newWidget);
}
clonedField.setQ(field.getQ()); // To get text centered
clonedField.setWidgets(widgetList);
clonedField.setValue(value);
clonedField.setPartialName(fieldName + cnt++);
fields.add(clonedField);
page.getAnnotations().addAll(clonedField.getWidgets());
And at the end of the process:
finalDoc.getDocumentCatalog().setAcroForm(finalForm);
finalForm.setFields(fields);
finalForm.flatten();

Rendering salesforce lightning component into pdf (Generate PDF)

I am working on a lightning component and within the components layout I have to provide a button which can generate pdf of that lightning component . I found some blogs but still not sure about the actual solution for this . Please let me know if you guys have some sample implementation example for doing this .
Thanks !
If you want to save the entire window, you can just open the print window then save as PDF (if the business requirement allows):
print : function (component, event, helper) {
window.print();
}
If you want to print a portion of your lightning component, you might need to reconstruct the page to the pdf. Follow this:
var myWindow = window.open('','_blank', 'width=' + screen.availWidth + ',height=' + screen.avaliHeight);
myWindow.document.write('<html>HTML CODE HERE</html>');
myWindow.document.close();
myWindow.focus();
myWindow.print();

Is there a way to quickly generate a foreach for an existing variable using live templates?

I have the following code snippet:
Set<Company> companiesByUserName = companyUserService.getCompaniesByUserName(username);
Using IntelliJ live templates, I know I can type "itco" and it will generate the following for me:
for (Iterator<Company> iterator = companiesByUserName.iterator(); iterator.hasNext(); ) {
Company next = iterator.next();
}
However, how can I automatically create a foreach with the 'companiesByUserName' variable instead? So I want it to generate this automatically:
for (Company company: companiesByUserName) {
}
Because the foreach is a lot cleaner that iterating through the collection in a for loop, I generally use those instead, so would like to auto generate them if possible.
There is also a new feature introduced with IJ 13, called postfix completion. With that, you can type companiesByUserName.for and hit TAB (and obviously much more as per your defined templates):
Nevermind, found out how to do it. Just type "iter" and press enter.
Type "iter" then press tab. Idea is smart enough to pick collection to iterate through.

Make Text Field item as Read Only in APEX 5.0

I have some text field page items on my APEX 5.0 page and I want to make the textboxes as read only/non-editable. During the page load I want to use these text boxes for only the data display on the page and should be non-editable.
Can somebody advice on how to do that? What attributes need to set for this?
This answer is a bit late to the party, but I found myself confronted to this problem and I wanted to share the solution I came up with.
In fact you just need to create your item as a text area, let say P1_Text_Area and you give it a readonly attribute using JavaScript. Write thoses 2 lines in the "Function and Global Variable Declaration" of your page:
var disItem = document.getElementById('P1_Text_Area');
disItem.readOnly = true;
Hope this helps someone in need.
in item properties find the
Read Only group
and set Read Only Condition Type as Always
or the option that suits to you
You can use disabled + save session state ==> read only

How to use Silverlight 4 Beta Print Preview?

One of the Silverlight 4 features listed in a lot of the PDC documents is Print Preview.
I've searched for examples on how to use this and found nothing so far. Has anyone got this working yet? Can you give me some pointers on how to implement a simple web app with print preview in.
I have not seen print preview as any of them but actual Printing support in which you can control which controls are printed and events based on the printing process.
After looking for a while I found a way to do this by combining some features I found in other projects, but they used it for image manipulation. I tried with printing and it seems to work fine.
Here how it works:
Get the base container for the print contents converted to a bitmap by using WriteableBitmap, here I´ll use a Canvas:
WriteableBitmap wb = new WriteableBitmap(this.canvas1, null);
Use this bitmap as a source for a Image control (can be inside a ScrollViewer, what is even better).
this.imagePreview.Height = wb.PixelHeight;
this.imagePreview.Width = wb.PixelWidth;
this.imagePreview.Source = wb;
Set scaling base units (used 1 percent in this case):
Point scale = new Point();
scale.X = imagePreview.Width/100d;
scale.Y = imagePreview.Height/100d;
Then adjust the scaling using a Slider (optional)
private void vSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
imagePreview.Height = scale.Y * vSlider.Value;
imagePreview.Width = scale.X * vSlider.Value;
}
I think from the lack of responses and the fact that as Hurricanepkt pointed out in his reply Tim Heuer and others talk about a virtual print which if displying the same thing on the screen could be built quite easily into your own bespoke Print Preview functionality that the Print Preview listed in some lists is actually people misinterpretting what the Virtual Print documents actually are.