I have a basic UWP app that supports printing a document (text, no images). Internally I split the document into multiple pages. Each page is loaded as static HTML page into a WebView that I then use to print.
My problem is that printed text looks blurry/fuzzy. When I printed to a PDF and zoom into the page, I noticed that the text does not scale and cannot be selected. It looks as if my document was printed (i.e. exported) as image and not as text.
Here is an example at the actual size:
Note how even at the actual size, the text is blurry.
Now zoomed in:
Here is is clearly visible that the text is not scaled as vector, but as image.
My question: how can I print the contents of a WebView in a UWP app and have the text scale correctly? Is there a way to configure the WebView or PrintTask to specify the quality?
For reference, the code to produce a single page:
private WebView makePage(int pageNumber, Size pageSize, double scaleFactor) {
var webView = new WebView();
webView.Width = pageSize.Width;
webView.Height = pageSize.Height;
webView.ScriptNotify += WebView_ScriptNotify;
// Generate HTML and load into WebView, wait
// for scriptNotify...
return webView;
}
Related
How can we add header and footer same for all pages through out pdf using jsPDF. And apart from this please let me know that what are all ways to create pdf using jspdf like using HTML content or a string or some HTML template so please help me out on both query
Although jsPDF does not have a dedicated header or footer functions, you may use
var doc = new jsPDF();
doc.text("Header or footer text", x, y);
Where x is margin from left of the page and y is from the top.
You may have to position it as per your page dimensions require.
And about your second query, jsPDF has addHTML and addImage (Older versions of jsPDF) functions to help you generate PDF.
addHTML take in raw HTML code as input while addImage takes image as input which can be positioned on the PDF page.
addImage requires additional libraries such as html2canvas for image generation.
I've been trying to embed a youtube video within a codename one application. When I run the simulator for both Android and iOS it looks fine, but when I actually run the application on my Galaxy S7, nothing shows. I've tried using both BrowserComponent and WebBrowser and neither work. My code is below:
Form hi = new Form("Hi World", BoxLayout.y());
Display display = Display.getInstance();
BrowserComponent browser = new BrowserComponent();
//WebBrowser browser = new WebBrowser();
String videoUrl = "https://www.youtube.com/embed/r6VO3zaBJGY";
int videoWidth = (int) ((double) display.getDisplayWidth());
int videoHeight = (int) ((double) videoWidth*0.5625);
String integrationCode= "<iframe src=\"" +videoUrl+"\" frameborder=\"0\" width=\"" + videoWidth + "\" height=\"" + videoHeight + "\" allow=\"autoplay; encrypted-media\" allowfullscreen></iframe>";
browser.setPage(integrationCode, null);
browser.getAllStyles().setPadding(0, 0, 0, 0);
browser.getAllStyles().setMargin(0, 0, 0, 0);
Container browserContainer = new Container(new BorderLayout(CENTER_BEHAVIOR_CENTER));
browserContainer.add(CENTER, browser);
hi.add(browserContainer);
hi.show();
There are two mistakes in the code: BoxLayout and CENTER_BEHAVIOR_CENTER.
The reason this won't work has to do with the way layouts work. Layout managers use the preferred size to give components the right size. BrowserComponent doesn't have a proper preferred size as the rendering of HTML is asynchronous and it's pretty flexible to begin with. In this case you used two layout managers that respect preferred size. They get a size that amounts to zero and place the browser component appropriately...
BoxLayout.Y_AXIS needs the preferred height and CENTER_BEHAVIOR_CENTER needs the preferred size to position the component in the center.
The typical workaround is to use a regular BorderLayout which defaults to the scaled behavior. This stretches the center component to take up available space. Notice you need to set it on the Form itself as it has a hardcoded size of the entire screen. The center location ignores the preferred size and gives the component the full size.
It also solves another problem. Form is scrollable by default on the Y axis. Scrollability for Codename One components and native widgets (e.g. web) can collide so by using the border layout you implicitly disable scrolling which in this case might provide superior UX.
Note that you can get the code above to work by overriding calcPreferredSize() in BrowserComponent and returning the size you want for the component. I don't think this will result in a good UX because of scrollability issues.
I want to display some Hebrew text using Text and TextPath. In plain HTML5 it seems the best way is to set the dir attribute on the canvas to rtl (HTML5 Canvas fillText with Right-to-Left string). How do I do that in Konva?
const canvas = layer.getCanvas()._canvas;
canvas.setAttribute('dir', 'rtl');
http://jsbin.com/wezusafebi/edit?js,output
I am using PdfStamper getOverContent() so I can add an image to the output PDF file using an AffineTransform of Identity type.
PdfContentByte content = stamper.getOverContent(1);
data.image.setAbsolutePosition(desc.X,desc.Y);
content.addImage(data.image,desc.transform);
//content.addImage(data.image);
if I use the commented line without the transform it works perfectly adding the image to the PDF generated but with the AffineTransform (setToIdentity()) it does not show up.
could someone help me out with that ? I intend to use more sophisticated transform but the Identity should work first...
EDIT (copied from the invalid answer)
I removed the call to setAbsolutePosition and used a setToIdentity() as the only transformation and the image is not show... Then added the setToTranslation(X,Y) where X and Y are the same values used in the successful case where I do NOT give the transformation as the second parameter and still it does NOT show the image. Is there an example with the AffineTransform as a parameter to PdfContentByte addImage() call using an AffineTransform as a parameter ? I have bought your book but could not fins any.
I have examined your problem and I am pretty sure that your image gets added. However: you can't see it because the dimension of the image is 1 user unit by 1 user unit.
I've made an example to show you how to fix this problem: AddImageAffineTransform
public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
Image image = Image.getInstance(IMG);
AffineTransform at = AffineTransform.getTranslateInstance(36, 300);
at.concatenate(AffineTransform.getScaleInstance(image.getScaledWidth(), image.getScaledHeight()));
PdfContentByte canvas = stamper.getOverContent(1);
canvas.addImage(image, at);
stamper.close();
reader.close();
}
In this example, I start with a translation: 36 user units from the left border and 300 user units from the bottom. If I would add the image using this transformation, I'd add the image at those coordinates, but it would be too small to see with the naked eye.
To make sure the image is visible, I concatenate a scale transformation scaling the image to its width in X direction and to its height in Y direction.
In my MVC application when it comes to printing of reports i have few options
RazorPDF - advanatage of handling design from cshtml itself & can pass values from controller as model
iTextSharp - advanatage of handling design from cshtml itself & can pass values from controller as model
pdfSharp - No advantage of handling design from cshtml page. Have to do all coding from .cs file & modifications is very difficult. BUt have a great control over the layout of generated report
So Can any one suggest a method with both options
Can do the PDF design from cshtml itself.
Can specify width and height of the PDF page
Since the report is not always to print on laser printers. Need to giv support for dotmatrix print as well and in that case i have to mention width & height of page .Also there is a possibility toprint on letter heads so i have to mention widtha nd height of empty area again
Or any one can suggest a way to mention to width and height of PDF page with RazorPDF and iTextSharp approach
Your question is about many different tools, but this is the answer in case you are using iTextSharp.
When you create a PDF from scratch using iTextSharp, you always need a Document and a PdfWriter class. The Document class is to be used for the high-level functionality; the PdfWriter class for the low-level operations.
The page size is defined at the Document level. You can create a new Document object like this:
Document document = new Document();
As we didn't pass any parameters to the constructor, iTextSharp will create a PDF using the default page size (A4) and margins of half an inch.
This is the equivalent of:
Document document = new Document(PageSize.A4, 36, 36, 36, 36);
As you can see: I use 36 as value for half an inch, because 1 inch = 72 user units in PDF.
If you want to define another page size, you can do so by using one of the other values available in the PageSize class, for instance:
Document document = new Document(PageSize.LETTER);
PageSize.A4 and PageSize.LETTER are instances of the Rectangle class, so if you need a page size that isn't defined in PageSize, then you can create your own rectangle. For instance:
Rectangle envelope = new Rectangle(432, 252);
Document document = new Document(envelope, 0, 0, 0, 0);
Where do these values come from? Let's do the Math:
6 inch x 72 points = 432 points (the width)
3.5 inch x 252 points = 252 points (the height)
This is how you define pages with a custom size.