How to create pdf file of the webview content in titanium - pdf

I am new to Titanium. I have a webview. The content of the webview can be a pdf file, or a url. I want to save the webview content as a pdf file. I have created webview using the below code:
var webViews = Ti.UI.createWebView({
left : 0,
top : 0,
right : 0,
bottom : 0,
url : 'http://www.appcelerator.com'
});
Please anyone help me out...

You cant directly convert the webview data in pdf but you have to first parse html and then use the js pdf to create the pdf.Here is the code with example
https://github.com/Mindelusions/TiJSPDF
Thanks

Related

how can I show the pdf file content inside from razor file

I created a document file from word and has exported as pdf . i want to show the pdf content inside the Div element in razor page. How can I show the pdf content from razor page. Please can you provide an example code how to show in blazor server side
If you stored your pdf file directly in your documents for example in the folder wwwroot/pdf.
wwwroot/pdf/test.pdf
You can display this PDF with this line of html bellow :
< embed src="pdf/test.pdf" style="width=100%; height=2100px;" />
It will provide you a pdf displayer with printing options !
If you want to go further, upload your file and then display it, I will recommend you to go check this explanation :
https://www.learmoreseekmore.com/2020/10/blazor-webassembly-fileupload.html
The upload for PDF files works the same as Img file, you need to go check IBrowserFile documentation.
You will see that it has a Size obj and a OpenReadStream() function that will help you get the display Url for your file (image or pdf)
If the site abow closes, this is the upload code that is shown on it :
#code{
List<string> imgUrls = new List<string>();
private async Task OnFileSelection(InputFileChangeEventArgs e)
{
foreach (IBrowserFile imgFile in e.GetMultipleFiles(5))
{
var buffers = new byte[imgFile.Size];
await imgFile.OpenReadStream().ReadAsync(buffers);
string imageType = imgFile.ContentType;
string imgUrl = $"data:{imageType};base64,{Convert.ToBase64String(buffers)}";
imgUrls.Add(imgUrl);
}
}
}
This code was written by Naveen Bommidi, author of the blog where I found this usefull code
If you want, as I said, upload a PDF and then display it.
You can use the same html line :
< embed src="#imgUrl" style="width=100%; height=2100px;" />
And your uploaded files will be displaying.
Example

Generating and Downloading a PDF

I am developing an Android app for flight reservation and i am using firebase Database for storing and retriving data. I need to generate a PDF of Ticket and contents should be changed as per passenger details and stored in local directory. I have a template of Ticket. What should i do?
Thank you in advance.
Since Android 5 you can use PdfDocument and its friend classes to generate a PDF document on Android device. The official documentation is here. There is no library to use a template with PdfDocument. You have to use some drawing primitive to accomplish your task.
Here is a sample to generate a PDF with a single page A4:
// create a new document
PdfDocument document = new PdfDocument();
// crate a page description
PageInfo pageInfo = new PageInfo.Builder(595, 842, 1).create();
// start a page
Page page = document.startPage(pageInfo);
Canvas canvas=page.getCanvas());
// draw something on the page
Paint paint = new Paint();
paint.setColor(Color.RED);
canvas.drawCircle(50, 50, 30, paint);
// finish the page
document.finishPage(page);
// write the document content
document.writeTo(getOutputStream());
// close the document
document.close();
The page content is defined with Canvas object. Just another example. I hope this helps you.

How to convert Xamarin.Forms XAML UI page to PDF file?

In Xamarin.Forms, I want to convert my xaml page UI (sometimes my page is scrollable when having more content) into the PDF. I have tried the PDFSharp (https://github.com/akgulebubekir/PDFSharp.Xamarin.Forms) open source. But it works only on UWP and having some issues in iOS and Android.
So is there any free open source plugin available to convert XAML UI into PDF in all three platforms? If open source not available, is there any other way or work around to achieve it in android, ios & UWP?
Thanks in advance.
I had a bit of trouble with this and managed to do it using UIkit and PdfKit tools.
Here is an exemple:
using UIKit;
using PdfKit;
//Calculate scroll View height
double xamlHeight = XamlFullPage.Height;
int numberOfPages = (int)Math.Ceiling(xamlHeight / Application.Current.MainPage.Height);
// Create a new PDF document
PdfDocument document = new PdfDocument();
for (int i = 0; i<numberOfPages; i++) //while the all the page have not been taken into account
{
await SummaryScrollView.ScrollToAsync(0, i*Application.Current.MainPage.Height, false).ConfigureAwait(false); //find the beginnig of the current page
//Captures the XAML page as image and returns the image in memory stream
var image = UIScreen.MainScreen.Capture();
// Create a page with the printscreen
PdfPage page = new PdfPage(image);
//insert page in the i position
document.InsertPage(page, i);
page.Dispose();
}
//Write file in temp foleder
document.Write(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "TuitionFees" + fileName + ".pdf"));`

Printing a pdf as an image inside of a pdf

I'm creating a web app and using a php FPDF script to creates and print out a pdf. This also prints out on the pdf images that are uploaded to the app, which is no problem. However, it needs to do the same thing for an uploaded pdf and that is where my problem lies. How can I print a pdf as an image inside of a pdf using fpdf?
I have heard of imageMagick but I don't think that is an option because it is a software and I don't know where I would run it.
You can use FPDI to import a page of an existing PDF document and place it with FPDF onto a newly created page:
<?php
require_once('fpdf.php');
require_once('fpdi.php');
$pdf = new FPDI();
// load the document and get the total page count
$pageCount = $pdf->setSourceFile("the/document/you/want/to/import/a/page/from.pdf");
// import the first page
$tplIdx = $pdf->importPage(1);
// add a page
$pdf->AddPage();
// use the imported page on x=10, y=10 and a width of 90
$pdf->useTemplate($tplIdx, 10, 10, 90);
// output the PDF document
$pdf->Output();

Attach footer at very bottom to every page in tcpdf

I need to attach footer at the very bottom of every page. I am using tcpdf for generating pdf's. i tried many solution on google but did not found any luck. My current framework is yii and i am using tcpdf extension.
you need to write Footer method in your class for example
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
Well, if you're subclassing the tcpdf class, just add a public function Footer() in which you do your stuff. It might help to set the bottom page margin to a sensible value before doing the content work, so that the Footer function has "space" to put in the footer.
why don't you try mpdf extension i am not sure if you can get its library for yii but it has one for codeigniter and it is awesome converts css + Html to pdf accurately.