Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ent · Nov 10, 2010 at 03:58 PM · webplayerimagepdfopenurl

How to convert to XImage without using System.Drawing.Image with the webplayer

Hi, I am having problems creating a PDF Screenshot with text data. What I am planing on doing is creating a screenshot and printing it into a PDF File, which is opened in a new window. My Problems are: Changing the image file from Bytes[] -> Stream -> XImage. Calling the new PDF in a new Tab / Window.

Ive got all this working fine on the Stand alone Server, but not on the Web Player version. Is there any way that I can use parts of system.drawing.image? or to save the files in temp_internet_files or something like that.

I can convert the Screenshot to a PNG or Stream, but not to an Image file, which I need for the PDF. I am using PDFSmart to create the PDF (are there any other PDF Creators with which I can easily add Image files without converting them?). Then I need to open the PDF in a new browser tab. I have seen some examples with ASP pages which I dont have and I can't get RESPONSE to work either, I guess System.Web is somehow not working either or different.

Here is my code:

    using UnityEngine;
using System;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Configuration;
using System.Web;

// using System.Web.UI; // using System.Web.UI.WebControls; // using System.Web.UI.WebControls.WebParts; // using System.Web.UI.HtmlControls;

using System.Net; using PdfSharp; using PdfSharp.Drawing; using PdfSharp.Pdf; using PdfSharp.Pdf.IO; using PdfSharp.Drawing.Layout; using PdfSharp.Pdf.Advanced;

public class ScreenshotToPdf : MonoBehaviour {

 void pdfDrawHeader(Texture2D pngTexture){
     MemoryStream ms = new MemoryStream(pngTexture.EncodeToPNG());
     Bitmap bmp = (Bitmap)Image.FromStream(ms, true, true);
     XImage image = XImage.FromGdiPlusImage(bmp);

     PdfDocument document = new PdfDocument();
     // Create an empty page
     PdfPage page = document.AddPage();
     // Get an XGraphics object for drawing
     XGraphics gfx = XGraphics.FromPdfPage(page);

     //..Some PDF Creation

     double factor = 1.0f;

     double width = image.PixelWidth;
     double height = image.PixelHeight;

     if(width > 480.0f){
         factor = width / 480.0f;
     }

     if(height > 360.0f && (height / 360.0f)>factor){
         factor = height / 360.0f;
     }

         if(factor==0.0f)
             factor=1.0f;
     width /= factor;
     height /= factor;


     gfx.DrawImage(image, (pdfwidth-hspace*2)*0.5-(width*0.5),vspace,width,height);
     imageHeight = vspace+height;

     MemoryStream stream = new MemoryStream();
     document.Save(stream, false);

     Response.Clear();
     Response.ContentType = "application/pdf";
     Response.AddHeader("content-length", stream.Length.ToString());
     Response.BinaryWrite(stream.ToArray());
     Response.Flush();

     stream.Close();
     Response.End();
 }

}

I could load the image file to the server and read it againg from there, but I would have the problem that 'XImage image = XImage.FromFile' only opens local files.

Does anyone have an idea how I could solve this problem?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Alternative to 'Application.OpenURL()' for newest Android API 1 Answer

How to save runtime generated texture in Webplayer to hard drive? 1 Answer

Can't replace loading image in web player 1 Answer

Custom background image in Unity WebPlayer Loading Screen 0 Answers

WbPlayer Loading From File 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges