Home > other >  Unity WebGL platform use Itext component generating PDF saved to the local computer
Unity WebGL platform use Itext component generating PDF saved to the local computer

Time:09-26

Problem basically is, create file stream on the PC platform, generate PDF files, written to a local computer no problem, but in webGL platform file stream, on the memory stream with the also not line, the browser will pop-up error, consult the zha do?




Void SavePdf_PC ()
{
Try
{
//create a PDF document
Document doc=new Document (PageSize. A4, 60, 60, 72, 72);
//create instances, write PDF document is saved location
PdfWriter PdfWriter=PdfWriter. GetInstance (doc, new FileStream (fileName, FileMode. Create));
//open the document
Doc. The Open ();
//create the
Doc. AddTitle (" nikolatta ");
Doc. AddAuthor (" Addis Chen ");
PDF doc. AddSubject (" Test ");
PDF doc. AddCreator (" Test ");
//practical the vera.ttf font
BaseFont heiBaseFont=BaseFont. CreateFont (Application. StreamingAssetsPath + "/Fonts/DENG. The vera.ttf," BaseFont. IDENTITY_H, BaseFont. NOT_EMBEDDED);
//create a font
ITextSharp. Text. The Font testFont=new iTextSharp. Text. The Font (heiBaseFont, 18);
//create a paragraph
Com.lowagie.text.paragraph pdf_title=new com.lowagie.text.paragraph (" I love nicole!" , testFont);
Pdf_title. Alignment=iTextSharp. Text. Element. ALIGN_CENTER;
Doc. Add (pdf_title);
//close the document
Doc. The Close ();
PdfWriter. Close ();
//open the PDF file
//System. Diagnostics. Process. The Start (fileName);

}
The catch (Exception e)
{
Print (e.M essage);
ErrorText. Text=e.M essage.
}

}









Void SavePdf_Web ()
{
//StartCoroutine (" DownLoad ");
Try
{
//create a PDF document
Document doc=new Document (PageSize. A4, 60, 60, 72, 72);
//create a memory stream
MemoryStream fileStream=new MemoryStream ();
FileStream. Position=0;
//create instances, write PDF document location is the code mischief
PdfWriter PdfWriter=PdfWriter. GetInstance (doc, fileStream);
//open the document
Doc. The Open ();
//create a paragraph
Com.lowagie.text.paragraph pdf_title=new com.lowagie.text.paragraph (" I love nicole!" );
Pdf_title. Alignment=iTextSharp. Text. Element. ALIGN_CENTER;
Doc. Add (pdf_title);
//close the document
Doc. The Close ();
PdfWriter. Close ();
Byte [] pdfByte=new byte [fileStream Length].
FileStream. Position=0;
FileStream. Read (pdfByte, 0, pdfByte. Length);
WebDownLoadPDF (pdfByte, "WebDownLoadPDF. PDF");
}
The catch (Exception e)
{
Print (e.M essage);
ErrorText. Text=e.M essage.
}
}

[DllImport (" __Internal ")]
Private static extern void PDFDownLoader (string STR, string fn);
Public void WebDownLoadPDF (byte [] pdfData, string pdfFileName="newpdf")
{
If (pdfData!=null)
{
PDFDownLoader (Convert ToBase64String (pdfData), pdfFileName);
}
}

CodePudding user response:

Please who is a great god, save the children, or I don't have my way, so long as can meet my needs, can be in webGL platform, according to the pre-written PDF layout format, PDF files dynamically generated content is different, and saved to the local computer,

CodePudding user response:

No one ever do this thing? Let me call summoning a great god,

CodePudding user response:

Which brother to the point, to help, thank you very much,

CodePudding user response:

Brother this problem solved, I also need to webgl export PDF

CodePudding user response:

I also can't ah, this feature is consistent with the
  • Related